Use a MixerAudioSource to play more than one file at a time
Monday 3 August 2020
1. Go to MainComponent.h and in private add:
juce::MixerAudioSource mixerSource;
2. We need to hook this into the Audio Life Cycle now. In MainComponent.cpp in MainComponent::prepareToPlay we add:
mixerSource.prepareToPlay(samplesPerBlockExpected, sampleRate);
3. We also need to set up player 2 in prepareToPlay because we haven't done that yet. So add
player2.prepareToPlay(samplesPerBlockExpected, sampleRate);
4. Then we need to add this in the same function:
mixerSource.addInputSource(&player1, false);
mixerSource.addInputSource(&player2, false);
5. In MainComponent::getNextAudioBlock we replace player1.getNextAudioBlock(bufferToFill); with
mixerSource.getNextAudioBlock(bufferToFill);We do this because we are delegating the responsibilty of dealing with player1 and player2 to mixerSource.
6. In MainComponent::releaseResources we put:
player1.releaseResources();although the worksheet said
player2.releaseResources();
mixerSource.releaseResources();
mixerSource.removeAllInputs();
mixerSource.releaseResources();
player1.releaseResources();
player2.releaseResources();
All seems to be working after another compile and build.
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