We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProcessing DevelopmentLibraries,  Tool Development › Sound library conundrum
Page Index Toggle Pages: 1
Sound library conundrum (Read 1185 times)
Sound library conundrum
Nov 19th, 2009, 5:16am
 
Hi all,

I'm trying to get my audio player working as a library and I'm running into a fairly weird problem. I'll be as concise as I can to begin with, then elaborate if necessary...

My player is a Processing sketch in Eclipse which uses a bunch of pure Java classes to play the audio. Player.java uses javax.sound.sampled and has a while loop which does output_line.write(output_buffer,etc) to the output line for the duration of the piece of music. This works fine.

Having libraryised my code, so that I can successfully instantiate it and run it as a Processing applet (in both Eclipse and the Proc IDE), the weirdest thing happens: everything seems fine, the music files load properly, my debugging printlns are all cool...but the music doesn't play. More specifically, the aforementioned while loop only calls the buffer preparation function once, then fails to fill the buffer or advance the sample frame count.

This is all done in a 'public class Driver implements Runnable', so I felt that I wouldn't have to run my own timing mechanism through communication between my library and the end-user's sketch, since this should be running happily in its own thread (as it does normally, when not as a library!).

Can anyone think of anything glaringly obvious that I've forgotten, or simply not considered (as I'm not very experienced - still an enthusiastic beginner!)?

My buffer is being initialised properly, and there are NO errors at any point. Printing the buffer gives 0s, no null exceptions, but only once and then this Runnable thread seems to stop dead. I've done try/catches in various places, and I'm fairly sure there isn't anything I'm failing to catch. A friend mentioned mutex/sleeping/etc, but couldn't imagine why my code would work in a regular applet but not as a lib.

Any help would be gratefully appreciated, including help on how better to express my problem - I'm sure I've mangled some terminology already Wink

Cheers,
/brendan
Re: Sound library conundrum
Reply #1 - Nov 20th, 2009, 5:02am
 
Er, okay...it wasn't a threading issue Smiley But believing that it was forced me to go and learn a LOT about Java threading, thus eliminating that possibility from my enquiries Wink

My problem appears to have been caused by a slightly ambiguous SourceDataLine instantiation in my player thread which caused the thread to stop but didn't display any errors. Still don't understand why it doesn't fail in my non-library code, but I can figure that out at my leisure since my library now WORKS and I'm happy Cheesy
Page Index Toggle Pages: 1