Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
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 1746 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 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.

"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
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.

"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (17 views)
2014-08-28 18:26:30

CopyableCougar4 (26 views)
2014-08-22 19:31:30

atombrot (39 views)
2014-08-19 09:29:53

Tekkerue (36 views)
2014-08-16 06:45:27

Tekkerue (33 views)
2014-08-16 06:22:17

Tekkerue (22 views)
2014-08-16 06:20:21

Tekkerue (33 views)
2014-08-16 06:12:11

Rayexar (67 views)
2014-08-11 02:49:23

BurntPizza (45 views)
2014-08-09 21:09:32

BurntPizza (36 views)
2014-08-08 02:01:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org 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‑gaming.org
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!