Speeding up playback of audio file


#1

Hi,

I’ve been using the juce library for a week or so now for R&D for a potential commercial product sometime in the future. I’m really impressed so far.

I have developed a simple multi channel mixer, which works very nicely. I’m now wondering how I can implement a system which allows the user to increase and decrease the speed of playback of a supplied wav file. Could anyone offer suggestions on how to do this :?:


#2

i can see ResamplingAudioSource in the help file but I’m not sure how to plug that into the MixerAudioSource. maybe my question is more of a c++ how to?


#3

You basically connect audio sources to each other in a chain (known as a filter graph). Something like this will change the speed of all mixer inputs at once (pseudo code):

AudioFormatReaderSource();
AudioTransportSource->setSource (AudioFormatReaderSource);
MixerAudioSource->addInputSource (AudioTransportSource);
ResamplingAudioSource (MixerAudioSource);
AudioSourcePlayer->setSource (ResamplingAudioSource );

or if you want to change the speed independently for each input into the mixer:

AudioFormatReaderSource();
AudioTransportSource->setSource (AudioFormatReaderSource);
ResamplingAudioSource (AudioTransportSource);
MixerAudioSource->addInputSource (ResamplingAudioSource );
AudioSourcePlayer->setSource (MixerAudioSource);

  • kbj

#4

thanks that did the trick :slight_smile:

onto the next question…

I can now adjust the speed of my samples using ResamplingAudioSource, which works great, but it sounds like chip monks once its sped up. I’ve heard of a technique called timestretching rather than pitch adjust which compensates, is it possible to implement a similar technique using the juce library?


#5

Timestretching is a whole 'nother can of worms. There are two basic methods: slice and dice; and DSP.

The first method slices up an audio stream into sections (usually 20 to 40 per second) and then either overlaps the sections (time compression) or repeats them (time expansion). The results are not very good, although the best algorithms usually do some sort of smoothing to supress the artifacts. The latency however is very low.

The second method, DSP, most commonly converts the frequency domain into a time domain and then changes the representation of the sample to equal a time stretch or time compression, then converts back to the frequency domain (not the clearest explanation, I know). The result is very smooth with few artifacts, but is VERY processor intensive. It also requires extensive DSP skills of the programmer and can have very high latency (100s of milliseconds).

Since JUCE doesn’t provide either method in its library, you’ll have to write your own code. A good place to start is the Soundtouch Library which you can try to adapt to JUCE. It uses DSP techniques and has a latency of around 100ms. Also visit the Linux Sounds Archive. There’s lots of code to explore and you may find some quick hack you can use. The best place to go for more information is Stephan Bernsee’s webpage which will give you all the information on the topic you could ever want.

  • kbj

#6

Rosslyn Chapel is a good place to start looking for the holy grail too.

+1 to Jules including his “ComedyTimestretch” in JUCE!

:wink: :lol:


#7

Edit >> Don’t worry, kids, I think I’ve figured it out. Thanks to open source you can tell me how bad I kludged it later!

I failed to get this pseudo code to run… I’m not sure if my sources needed to be initialised as pointers or references, I was excited after the dozenth time when it compiled, it then crashed spectacularly. Would someone mind making killerbobjr’s pseudo code a little less… pseudo? or point me in the right direction? Thanks muchly


#8