How to apply effects to only one AudioTransportSource in a multi-transport app?

Hi all,

The Tutorials and the Forum has been really helpful as a new JUCE and C++ programmer – thanks heaps.

So I have a standalone audioapp inheriting from AudioAppComponent with two AudioTransportSources – one for vocals and one for music, and a mixer to play them in sync.

std::unique_ptr<AudioFormatReaderSource> mVocalSource;
std::unique_ptr<AudioFormatReaderSource> mMusicSource;
AudioTransportSource mTransportSourceVocals;
AudioTransportSource mTransportSourceMusic;
MixerAudioSource mAudioMixer;
//Load file into transport
    auto* musicFileReader = mFormatManager.createReaderFor(File(filePath));
    if (musicFileReader != nullptr)
    {
        std::unique_ptr<AudioFormatReaderSource> newMusicSource(new AudioFormatReaderSource(musicFileReader, true));
        mTransportSourceMusic.setSource(newMusicSource.get(), 0, nullptr, musicFileReader->sampleRate);
        mAudioMixer.addInputSource(&mTransportSourceMusic, false);
        mMusicSource.reset(newMusicSource.release());
    }

    //Load vocals
    AudioFormatReader* vocalFileReader = nullptr;
        auto* vocalFileReader = mFormatManager.createReaderFor(File("C:/Users/aman_/Music/Beats/Beat01.wav"));
    }
    if (vocalFileReader != nullptr)
    {
        std::unique_ptr<AudioFormatReaderSource> newVocalSource(new AudioFormatReaderSource(vocalFileReader, true));
        mTransportSourceVocals.setSource(newVocalSource.get(), 0, nullptr, vocalFileReader->sampleRate);
        mAudioMixer.addInputSource(&mTransportSourceVocals, false);
        mVocalSource.reset(newVocalSource.release());
    }
    //Rewind both tracks to the start and play
    mTransportSourceVocals.setPosition(0.0);
    mTransportSourceMusic.setPosition(0.0);
    mMusicSource->setLooping(true);

    mTransportSourceVocals.start();
    mTransportSourceMusic.start();

Then in the getNextAudioBlock, I play the mixer:

void SelectTrackComponent::prepareToPlay(int samplesPerBlockExpected, double sampleRate)
{
    mSamplesPerBlockExpected = samplesPerBlockExpected;
    mSampleRate = sampleRate;

    // This function will be called when the audio device is started, or when its settings (i.e. sample rate, block size, etc) are changed.
    //mAudioMixer.prepareToPlay(samplesPerBlockExpected, int(mSampleRate / mSampleRateXRatio
    mAudioMixer.prepareToPlay(samplesPerBlockExpected, int(mSampleRate / mSampleRateXRatio));
}

void SelectTrackComponent::getNextAudioBlock(const AudioSourceChannelInfo& bufferToFill)
{
    // Your audio-processing code goes here!
    mAudioMixer.getNextAudioBlock(bufferToFill);
    mAudioVisualiser.pushBuffer(bufferToFill);
}

This all works. Except I now want to add effects to ONLY ONE AudioTransportSource / track / audiosource (mTransportSourceVocals). All the tutorials and forum entries I’ve seen only seem to cover manipulating the entire buffer (see https://docs.juce.com/master/tutorial_processing_audio_input.html).

How do I apply effects / do signal processing for only 1 AudioTransportSource?

Hey man,

Got your ping in the other thread :wink: It’s been a while since I’ve tinkered with JUCE now, but if I understand your problem correctly, the first half, presented by Fabian Renn-Giles solves your issue: https://www.youtube.com/watch?v=dl-2hhNUvZQ