Reverb in audio plugin


#1

Good day to everyone, I appreciate you taking your time to read and help me with a problem I’ve got in front of me.
I want to implement a reverb in my audio plugin, using Reverb JUCE class. I have made Reverb object in header file of my audio processor, set up parameters for reverb object and sample rate and now I face the problem of processing audio with it. I figured I have to do that in processBlock method, but processing with Reverb needs a array of float values passed to it, but I have an Audio Buffer only available which can only give me FloatType type of values for samples. Can I somehow cast it to float, or this is not a good method for doing this? And if so, how could i fix this problem?
Thanks again,Cila.


#2

Hi,
FloatType is not an actual type, but a parameter for a template.
So the template <typename FloatType>AudioBuffer<FloatType> means, FloatType could be anything. To give you a hint, it is named FloatType, because it is meant to be used with any floating point type (i.e. float, double, long double).
AudioSampleBuffer e.g. is simply a typedef for AudioBuffer<float>.

Have a read on templates, and if anything is unclear, just ask again.

HTH


#3

Hello again. Your explanation made a lot of things clear for me, but I had some issues after so I’ve skipped on other parts of my project, but now here I’m back again on it.
So, I have a problem with AudioBuffer getWritePointer function which should give me back FloatType.

float* channelDataRight = buffer.getWritePointer(1);

When I write like this I got an error saying:
Error C2440 ‘initializing’: cannot convert from ‘double *’ to ‘float *’

Then I guess that getWritePointer gives me back double* types,and I try this.

double* channelDataRight = buffer.getWritePointer(1);

but compiler says:

Error C2440 ‘initializing’: cannot convert from ‘float *’ to ‘double *’

I don’t get it.Sorry if being dumb on something obvious I maybe miss,but I really have no idea what is going on.

Thank you,Cila.


#4

Based on the information you have given so far, I can only guess you have overridden the “double” version of the processBlock method in AudioProcessor and trying to work with the 64 bit floating point data you get into that. You could try putting your processing code in the “float” version of processBlock instead since the Juce Reverb class only works with floats.


#5

In my header file of processor I have:

void processBlock(AudioBuffer<float>& buffer, MidiBuffer& midiMessages) override

	{

		jassert(!isUsingDoublePrecision());

		process(buffer, midiMessages, delayBufferFloat);

	}
	void processBlock(AudioBuffer<double>& buffer, MidiBuffer& midiMessages) override
	{
		jassert(isUsingDoublePrecision());
		process(buffer, midiMessages, delayBufferDouble);
	}

Where process function is defined in cpp file and its declaration is following:

template <typename FloatType>
void DrPadAudioProcessor::process(AudioBuffer<FloatType>& buffer,
	MidiBuffer& midiMessages,
	AudioBuffer<FloatType>& delayBuffer)

#6

Try removing your void processBlock(AudioBuffer& buffer… method entirely and also remove the double precision support from your plugin. You can’t directly use it with the Juce Reverb class anyway. (You could convert the 64 bit samples to 32 bit, but it would be kind of pointless…)


#7

your buffer variable is templated to FloatType, so this statement doesn’t return a float* but a FloatType*

change that to:

FloatType* channelDataRight = buffer.getWritePointer(1);

and you should be fine…


#8

Okay so I’ve tried what Daniel said.
It works okay for getting that pointers from getWritePointer function,but when I call reverb.processStereo I encounter some problems because it asks for float* and apparently FloatType* is double*.

FloatType* channelDataLeft = buffer.getWritePointer(0);
	FloatType*  channelDataRight = buffer.getWritePointer(1);
	reverb.processStereo(channelDataLeft, channelDataRight, buffer.getNumSamples());

Error C2664 ‘void juce::Reverb::processStereo(float *const ,float *const ,const int) noexcept’: cannot convert argument 1 from ‘double *’ to 'float *const ’


#9

How do I remove double precision support from my plugin?


#10

Yes, FloatType can be both, actually the compiler will create two copies, one where it replaces FloatType with double and one with FloatType replaced with float (and if somebody calls using AudioBuffer(), it would create a third copy using int.

If your reverb has only a float version (that’s what seems to be the case), then there is no way. You would have to copy the actual data into the correct format, so it makes no sense.

remove AudioProcessor::supportsDoublePrecisionProcessing() or return false. Also don’t implement the specialisation for double but leave it untouched

HTH

Sorry xenakios, I cheated, was still editing within 4 minutes :wink:


#11

Remove the processBlock method version that has “double” in it from your plugin class. Also if you have a call to setProcessingPrecision, remove that too. Hopefully that is enough and you won’t need to go back to the Projucer to change something there or manually edit the AppConfig.h…


#12

I’ve tried to use JUCE built-in Reverb class here,does that mean I am not able to use it here,should I implement my own Reverb that would work with doubles?

Edit: I’ve tried Xenakios’s solution.Error is gone,I will test results now.

Edit_2: Everything works perfectly.Thank you!