Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (780)
Games in Android Showcase (233)
games submitted by our members
Games in WIP (857)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Can MouseMotionDetector code feed data to SourceDataLine?  (Read 2756 times)
0 Members and 1 Guest are viewing this topic.
Offline philfrei
« Posted 2011-05-05 06:48:00 »

I've been playing around with 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.

music and music apps:
Offline philfrei
« Reply #1 - Posted 2011-05-08 04:41:43 »

I came up with this:

there is a separate playback thread that consults state variables such as the X-location of the mouse and whether to play or not

the MouseMotionListener updates the state variables but is otherwise entirely decoupled from the playback thread

It seems to work. I can load a sound (wav file) into a float array, then, start it playing. The lazy gui has an orange "playhead" cursor on a rectangle. By placing the mouse in front or behind the "playhead" cursor, the cursor changes direction in an attempt to follow the mouse. There is a sort of rubber band effect--the closer the mouse to the playback head, the slower the playback head moves (pitch drops), the further away, the faster the playback (pitch rises).

Clear as mud, I'm sure. But kind of cool to actually do some crude audio functions, finally.

music and music apps:
Pages: [1]
  ignore  |  Print  

hadezbladez (748 views)
2018-11-16 13:46:03

hadezbladez (387 views)
2018-11-16 13:41:33

hadezbladez (740 views)
2018-11-16 13:35:35

hadezbladez (195 views)
2018-11-16 13:32:03

EgonOlsen (2398 views)
2018-06-10 19:43:48

EgonOlsen (2561 views)
2018-06-10 19:43:44

EgonOlsen (1483 views)
2018-06-10 19:43:20

DesertCoockie (2146 views)
2018-05-13 18:23:11

nelsongames (1950 views)
2018-04-24 18:15:36

nelsongames (2630 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!