Reputation: 11745
I plan to have ~100 synchronized audio tracks playing with live controllable volume per track. The audio comes from wav
files.
Are there any libraries / best practices to achieve this in Java?
Upvotes: 1
Views: 667
Reputation: 7910
I'd recommend looking at Praxis and JAudioLibs. Neil Smith knows his stuff.
I've gotten maybe 30-50 wavs playing at once, and my library is certainly not the most efficient. And I wasn't changing volumes or pans for those wav files. If some of those sounds of yours are short enough to be stored in memory (e.g., a bank of sound effects) then you have a bit more chance of success in having so many tracks. I've gotten 100 short clips running at once (using a custom made clip, but again, no volume or panning added except the trigger values).
There's a good article on the real-time issues with Java. The issues are real but not insurmountable. Java is pretty low-level and fast, if you stick with the lowest level tools provided by javax.audio.sampled library, and don't mind a bit of latency.
http://quod.lib.umich.edu/cgi/p/pod/dod-idx?c=icmc;idno=bbp2372.2007.131
Controlling volume real-time is tough, as it requires either a very small buffer or a means of going in and doing per-frame calculations, or else risk getting effects like zippering or clicks. I had some success with real-time volume changing when I time-stamped mouse-motion-listener output and calculated the intermediate volumes. But I haven't tried applying that to more than one channel at a time. (It was a virtual Theremin project).
However, there might be a way to pre-build a selection of envelopes that would be quite efficient, and control volume via selecting from a menu of these envelopes. Hmmmm.
It's a challenging problem, and I don't know if even my DAW (Cakewalk Sonar, written in some flavor of C) would be able to handle this.
Upvotes: 1