Newbie question: using DSP with transportSource

dsp_module

#1

Hi. I have a rather basic question, since I’ve only recently started with JUCE. I’ve been following the tutorials on how to make an audio player and trying to expand on that. So I did the player, and also added a gain slider following another tutorial, which worked well. Then I decided to add a basic EQ with 5 bands using the dsp module. I think I set it up correctly (the filters and the chain), but no sound comes out (also no obvious errors, so I’m not sure how to debug it) and I think that I might have misunderstood how to implement it in the processBlock function.

void AudioPlayerBpAudioProcessor::processBlock (AudioBuffer<float>& buffer, MidiBuffer& midiMessages)
 {
    
auto totalNumInputChannels  = getTotalNumInputChannels();
auto totalNumOutputChannels = getTotalNumOutputChannels();
 
 	for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
 		buffer.clear(i, 0, buffer.getNumSamples());
 
 	transportSource.getNextAudioBlock(AudioSourceChannelInfo(buffer));
 
 	auto phase = *phaseParameter < 0.5f ? 1.0f : -1.0f;
 	auto currentGain = *gainParameter * phase;
 
 	if (currentGain == previousGain)
 	{
 		buffer.applyGain(currentGain);

 		dsp::AudioBlock<float>              block(buffer);
 		dsp::ProcessContextReplacing<float> context(block);
 		filter.process(context);
 	}
 	else
 	{
 		buffer.applyGainRamp(0, buffer.getNumSamples(), previousGain, currentGain);
 		previousGain = currentGain;

 		dsp::AudioBlock<float>              block(buffer);
 		dsp::ProcessContextReplacing<float> context(block);
 		filter.process(context);
 	}   
 }

Also, this here’s the prepare code

 void AudioPlayerBpAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
 {
 	transportSource.prepareToPlay(samplesPerBlock, sampleRate);
 	auto phase = *phaseParameter < 0.5f ? 1.0f : -1.0f;
 	previousGain = *gainParameter * phase;
 
 	dsp::ProcessSpec spec;
 	spec.sampleRate = sampleRate;
 	spec.maximumBlockSize = uint32(samplesPerBlock);
 	spec.numChannels = uint32(getTotalNumOutputChannels());
 
 	filter.prepare(spec);
 }

Based on what I read about the dsp module and the examples I saw, I thought this should work, but I guess not. Is this the wrong way to approach this?


#2

Why is i going from totalNumInputChannels to totalNumOutputChannels? If totalNumInputChannels is 3 (for instance with a mic input and 2 line inputs) and totalNumOutputChannels is 2 (for instance with stereo speakers), your loop is doing nothing.

If you are making a simple audio player, then I guess you don’t really care about inputs, so i should go from 0 to totalNumOutputChannels (excluded).


#3

I just left that line as it was written already when you start building the app template from projucer, I defined somewhere that the number of inputs is 0 (since, as you said it’s an audio player), so it’s actually going from 0 to 2. Either way, that’s just to clear the buffers, so it shouldn’t really cause any problems. I tried just placing 0 as you said and there’s no difference related to my problem.

Thank you anyway, I’ll keep this in mind when doing something with more inputs