Hi everyone,

How could detect the input channel’s signal intensity in DB unit in the `void MainComponent::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)`

function?

Best regards!

Hi everyone,

How could detect the input channel’s signal intensity in DB unit in the `void MainComponent::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)`

function?

Best regards!

My suggestion: take the average of the absolute value of all the samples in bufferToFill, and then apply the amplitude-to-decibels formula dB = 20 * log10(A), where A is the mean amplitude (average of absolute value of buffer samples). Here is a nice resource:

2 Likes

The result from the above formula is different from the setted db level. For example, when i set the db level -20 db, the computed db level is about -23 db

The crest factor of a sine is sqrt(2) (ratio between peak and RMS), and that’s 3dB

2 Likes

what is the sine wave db formula after plus the crest factor?

Depends. If you want to get the intensity (power/energy related) you simply calculate the RMS, however if you know it’s a sine and you want its amplitude, the you have to add 3dB to your intensity value.

1 Like

Here the signal is definite: sine wave.

```
auto* inBuffer = bufferToFill.buffer->getReadPointer(1, bufferToFill.startSample);
float audioInSampleSum = 0.0;
for (auto sample = 0; sample < bufferToFill.numSamples; ++sample)
{
audioInSampleSum = audioInSampleSum + abs(inBuffer[sample])*abs(inBuffer[sample]);
//DBG("Decibels::gainToDecibels(inBuffer["<<sample<<"]) =" << Decibels::gainToDecibels(abs(inBuffer[sample]*sqrt(2))));
}
DBG("output signal db level::" << Decibels::gainToDecibels(sqrt(audioInSampleSum / bufferToFill.numSamples) * sqrt(2)))
```

Is that OK? I just want get the input signal’s DBFS value through the accessed input channel’s audio sample.

You don’t need to use abs() if you are squaring the inBuffer[sample] value, but I think you’ve got it.

Here’s another nice resource I found:

1 Like

Just in case you missed it, there is a getRMSLevel() method in AudioBuffer:

```
auto numChannels = bufferToFill.buffer->getNumChannels();
float rms = 0;
for (int c=0; c < numChannels; ++c)
rms += bufferToFill.buffer->getRMSLevel (c, bufferToFill.startSample, bufferToFill.numSamples);
rms /= numChannels;
```

I think taking the average is appropriate since the values are already RMS values. But maybe the values should be summed as squares? IDK

1 Like