I’ve been playing around with javax.audio.sampled coding, and managed to do a couple things like load wav data into a float array and play it back, either forwards or backwards (triggered by button presses). Also managed to give each playback instance its own thread which allows the various sounds to overlap. The fidelity seems pretty nice.
What I’m now wondering about is whether one can use the MouseMotionDetector calls to feed data to a SourceDataLine for playback. I was thinking of doing this: move the mouse over a rectangle, and use the x coordinates of successive MouseMotionDetection calls to grab corresponding sections of my floats array and ship it off for playback. (This would include the needed linear interpolations as the mouse moves at different speeds.)
It seems like the number of potential problems is rather large & I’m having some trouble conceptualizing this. I would assume I’d open a line before I start moving the mouse around, and send data to that same line with each MouseMotionDetection call. But if each of these is a separate thread, it seems that concurrency problems are inevitable. Should I try to make some sort of FIFO buffer? Haven’t gone about that before. Any recommendations as to the data structure to accomplish this?
So, there would be a “blocking” while loop draining the FIFO in its own thread while the MouseMotionDetector threads are loading up the FIFO? What’s to keep these from themselves causing concurrency problems at the loading end? Hmmm. Maybe need to back up a couple steps, send the x coords & times to the fifo instead of the float data…hmmm.
Current code with the mouse sounds pretty chaotic. I’m pretty sure that there is concurrency confusion/chaos going on. It’s an interesting playback but not what I’m going for.