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 › openStream() in audio library
Page Index Toggle Pages: 1
openStream() in audio library (Read 2388 times)
openStream() in audio library
Dec 9th, 2005, 1:20pm
 
Hello :)

I'm currently working on an audio library, and have run into a problem.  Everything works fine, except that it seems that it's recommended to use openStream(), so I have a line like this in my code to access the location of the file:

in = AudioSystem.getAudioInputStream(libraryname.parent.openStream(filename));

I was previously using sketchPath to form a path to locate the audio files in the data directory but I tried switching over to openStream so that exporting would work, but it seems openStream does something with "mark" and/or "reset", which is incompatible with some of the audio streams my library is working with, so they fail to play.

Specifically, I get the following error in the PDE console, when I use openStream():
java.io.IOException: mark/reset not supported at java.io.InputStream.reset(Unknown Source)

Just wondering if there is a recommended course of action in this case?

One other thing I noticed:

When I export to app the process locks my computer up at 100% cpu usage for about 2 minutes when I have about 4mb of audio files in the data dir.  It eventually finishes but I would think the process would only take a second.  It could easily be something I'm doing wrong.  (I have speedy computer so that shouldn't be the bottleneck, unless I misunderstand the process behind export to app).

Anyway, thank you!
Re: openStream() in audio library
Reply #1 - Dec 9th, 2005, 5:50pm
 
those both sound like issues in how the audio library is handling things.. openStream() doesn't do any sort of mark() or reset() calling, unless java does it internally with getResourceAsStream(). you can go look at the openStream() code for PApplet on dev.processing.org to see how it works.

as for the lag, that sounds like the thread blocking while it's loading 4MB of data, and that you probably need to buffer input streams and/or run the audio loading on a separate thread. but again, that's an issue of how to use java inputstreams.
Re: openStream() in audio library
Reply #2 - Dec 9th, 2005, 9:29pm
 
Hi Fry, thanks for the response.

About the openStream stuff, yeah, I'm going to look into it.  I wouldn't have posted if I didn't feel something weird was happening, but it still could very easily be my mistake.

The reason I posted was this method of opening a stream works fine with all of my audio types:

file = new File(playa.parent.sketchPath + File.separator + "data", fnp5);  // fnp5 is a String ("sound.wav")
in = AudioSystem.getAudioInputStream(file);

But this method causes the PDE console to spit out a mark/reset not supported error and not play certain audio:
in = AudioSystem.getAudioInputStream(mylib.parent.openStream(fnp5));

I'll look into getResourceStream, as that could be the culprit.  Assuming a situation where I can't use openStream(), is there another recommended way to access a file for streaming in a library so that it works from the PDE as well as when exported to application?

About that second issue -- it's not the performance of my library that hangs (it is a threaded library).  It's when, within the PDE, I do File->Export Application.  That process pins my CPU to 100% and locks up my computer for 2-3 minutes while exporting the application (on the windows platform).  It eventually finishes and I can browse the three application directories it creates.  I mentioned the 4mb of audio files in the sketch's "data" dir because I'm not sure if they are a factor in it taking so long to run the "export application" process.

(edit: using 0098 Windows with bundled JRE)

Thanks again!

Page Index Toggle Pages: 1