Using ResamplingAudioPlayer to implement variable speed playback
Thursday 30 July 2020
We're adding one more piece of functionality - to be able to change the speed which DJs often do.
1. The component we're going to use is called ResamplingAudioSource. So we need to add this to private: in .h
juce::ResamplingAudioSource resampleSource{&transportSource, false, 2};
2. Go to the .cpp file and to the PrepareToPlay function. Under transportSource.prepareToPlay(samplesPerBlockExpected, sampleRate); we can add
resampleSource.prepareToPlay(samplesPerBlockExpected, sampleRate);
3. In getNextAudioBlock we need to get rid of transportSource.getNextAudioBlock(bufferToFill); and change it to
resampleSource.getNextAudioBlock(bufferToFill);
4. We need to add a slider to change the speed. In .h we add
juce::Slider speedSlider;
5. In the .cpp file we add the three steps as before:
addAndMakeVisible(speedSlider);
speedSlider.addListener(this);
speedSlider.setBounds(0, rowH * 3, getWidth(), rowH);
6. Finally we need to add some code for the listener for the slider. So in MainComponent::sliderValueChanged we can add:
if (slider == &speedSlider)
{
resampleSource.setResamplingRatio(slider->getValue());
}
And that will get that working!
More posts in cpp
- Add a component ID and converting between ints and strings
- Implement a play button and add a listener
- Implement paintRowBackground and paintCell
- Add a vector to store a list of files
- Add a TableListBox
- Create a PlaylistComponent in the Projucer project
- Threads
- Implement a timer
- Add getPosition and setPosition functions
- Refactor DJAudioPlayer to use app-scope formatManager
- Draw the thumbnail
- Hook up the load button to trigger the AudioThumbnail load
- The AudioThumbnail class in the API
- Creating a new component - WaveformDisplay
- Implementing drag and drop triggers
- Use a MixerAudioSource to play more than one file at a time
- Implement the listener interfaces to DeckGUI
- Creating a DeckGUI class
- setPosition control
- Implementing setGain and setSpeed
- Add audio playback functionality
- Writing the DJAudioPlayer class
- Creating a new JUCE class with Projucer
- Refactoring our code
- Using ResamplingAudioPlayer to implement variable speed playback
- Add stop, start and volume functionality
- Add a file chooser
- Audio file playback in JUCE
- Realtime sound synthesis in JUCE
- Adding a slider listener
- Introduction to event listeners
- Macros
- Inheritance
- Adding a GUI widget to the JUCE app
- Introduction to JUCE