Hi there, I’m just 2 months into learning JUCE and have a long way to go. For the past couple of weeks I’ve been trying to speed up and slow down audio in the getNextAudioBlock member function, using ResamplingAudioSource() and setResamplingRatio(), however my knowledge is still too limited to figure this out. I have an audiofile loading and playing, and now hoping to get real time control of playback speed, hence the getNextAudioBlock and not simply altering the sample rate in prepareToPlay.
I would be grateful if anyone could point me in a direction to achieve this.
Nevermind, it doesn’t seem to work like that unfortunately. AudioTransportSource can’t use a ResamplingAudioSource as its audio source. I will try to see how it could be done.
AudioTransportSource has a ResamplingAudioSource built in…
But it is not very well exposed, you can only set the ratio by tweaking the sourceSampleRateToCorrectFor in setSource().
I don’t like ResamplingAudioSource, since it does only linear interpolation. It would be worthwhile to create an alternative that uses LagrangeInterpolator internally and inherits PositionableAudioSource, so you can feed it into your AudioTransportSource.
I would think so too. Didn’t see that during playback was in the request, so I thought I’d mention it.
Like I said, it is not very well exposed.
One would need to patch juce or ask for that method to be added…
EDIT, just re-read: “real time control of playback speed”… sorry
It seems to do something a bit more involved than plain linear interpolation, there’s for example a custom filter involved in the code. (But I do recall the results even then are not great, you can easily come up with test signals that break it…)
Implementing (and testing) this properly is quite work intensive and I am not sure if I really want to be looking more into this right now.
Basically, what you should do is what Daniel suggested above : implement a PositionableAudioSource subclass that can do the variable speed playback and can be used together with AudioTransportSource as its audio source. While ResamplingAudioSource is not great, it can do the basic job of producing the varispeeded audio inside your PositionableAudioSource subclass. (If you want really high quality results, Juce does not have the tools to easily implement that anyway, you will need a 3rd party audio resampling library.)