Hi !
Featured games (88)
games approved by the League of Dukes
Games in Showcase (679)
Games in Android Showcase (195)
games submitted by our members
Games in WIP (735)
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 2030 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  
You cannot reply to this message, because it is very, very old.

DarkCart (30 views)
2016-05-29 02:30:33

Hydroque (44 views)
2016-05-26 14:45:46

Mac70 (55 views)
2016-05-24 21:16:33

theagentd (58 views)
2016-05-14 18:38:35

theagentd (92 views)
2016-05-10 22:37:41

theagentd (99 views)
2016-05-10 22:33:46

IanParcs (121 views)
2016-04-18 14:18:53

KaiHH (117 views)
2016-04-18 08:35:41

KaiHH (139 views)
2016-04-15 12:43:58

theagentd (145 views)
2016-04-14 02:16:17
FPS Camera Tutorial
by Hydroque
2016-05-22 05:40:58

Website offering 3D Models specifically for games for free
by vusman
2016-05-18 17:23:09

Website offering 3D Models specifically for games for free
by vusman
2016-05-09 08:50:56

Website offering 3D Models specifically for games for free
by vusman
2016-05-06 11:10:21

Website offering 3D Models specifically for games for free
by vusman
2016-04-29 12:56:17

List of Learning Resources
by SilverTiger
2016-02-05 09:39:47

List of Learning Resources
by SilverTiger
2016-02-05 09:38:38

List of Learning Resources
by SilverTiger
2016-02-05 09:35:50 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!