I am posting a Variable-Speed-Loop Playback program I wrote this week.
http://www.hexara.com/VariSpeedLooper.jar Removed.
[EDIT: Now runnable as an Applet! http://www.hexara.com/VSL/VSL2.htm
There’s a big diagnostic field in pink that can be ignored, and the control pad is a bit deformed from what it was in the jarred version, but I’m just happy to have worked through BOTH learning JNLP api and dealing with InputStreams that have to be converted to ByteArrayOutputStreams to ByteArrayInputStreams in order to get AudioFileFormat, blah, blah. Unclear if this code works on a Mac. One friend with a Mac reports non-looping behavior. Now he says it is working fine.]
You can load a .wav file (only format implemented: 16-bit, 44100fps, stereo, little endian). (It’s not too hard to convert .wavs in Audacity.)
This was inspired by hearing the clicks in the sound for the demo movie of “Opposite Lock Racing”. I’m thinking: put in a motor sound and do dopplers and volume changes based upon the speed of the car. The goal was to show that one CAN do volume and doppler changes to a sound file without clicks. I think both (in this app) are fairly smooth despite some clunkiness in the GUI. [EDIT: turns out the clicks in “Opposite Lock Racing” were due to another cause!]
I’ve set it up so that the GUI only interacts with the coded VariSpeedPlayer object which in turn reads data from a VariSpeedTargetDataLine object. When the wav is loaded, it is encoded into two float arrays in the VariSpeedTDL. Playback is done via linear interpolation into this array, with the read data sent to a SourceDataLine for playback. The volume changes are handled via a volume controller built in change incrementally with every frame.
[EDIT: following was solved by using a double to track my position “in between” the frames rather than a float.]
[s]A couple things are a bit disconcerting, and I don’t know whether they are expected artifacts or the result of buggy coding. (1) the pitch wobbles back and forth between two frequencies every few seconds. The degree this occurs varies in a way I can’t predict yet. It is subtle though. Best heard with a sound that has a continuous pitch. (2) There is a bit of fuzziness or distortion when the overlap occurs. I put in some IF statements to check for aliasing, but that doesn’t seem to be it. It is pretty soft.
Any suggestions or explanations about these two artifacts?[/s]