I’m trying to implement a volume meter and getting the RMS values in the normal way.
But I look at the variables for rmsLevelRight
and rmsLevelLeft
and they seem to be reporting quieter than is true. I have my plugin open and showing the RMS on the right hand side, and Izotopes Insight showing the RMS on the left (same audio track). Insight is reporting consistently 4 to 5 Db louder than my plugin, which is accurate. Why the discrepency?
PluginProcessor.h
juce::LinearSmoothedValue<float> rmsLevelLeft, rmsLevelRight;
PluginProcessor.cpp
prepareToPlay()
rmsLevelLeft.reset(sampleRate, 0.5); //half a second decay
rmsLevelRight.reset(sampleRate, 0.5);
rmsLevelLeft.setCurrentAndTargetValue(-100.f);
rmsLevelRight.setCurrentAndTargetValue(-100.f);
processBlock()
rmsLevelLeft.skip(buffer.getNumSamples());
rmsLevelRight.skip(buffer.getNumSamples());
//I also tried .getNextValue() but range was even narrower
const auto volume_valueL = juce::Decibels::gainToDecibels(buffer.getRMSLevel(0, 0, buffer.getNumSamples())); //Left channel first
if (volume_valueL < rmsLevelLeft.getCurrentValue()) {
rmsLevelLeft.setTargetValue(volume_valueL);
}
else {
rmsLevelLeft.setCurrentAndTargetValue(volume_valueL);
}
const auto volume_valueR = juce::Decibels::gainToDecibels(buffer.getRMSLevel(1, 0, buffer.getNumSamples())); //do right channel
if (volume_valueR < rmsLevelRight.getCurrentValue()) {
rmsLevelRight.setTargetValue(volume_valueR);
}
else {
rmsLevelRight.setCurrentAndTargetValue(volume_valueR);
}
float myplugin::getRMSValue(const int channel) const
{
if (channel == 0)
return rmsLevelLeft.getCurrentValue();
if(channel == 1)
return rmsLevelRight.getCurrentValue();
return 0.f;
}```