Question about AudioAnalyzeRMS code

WeTec

Member
Can some one explain this part of code found in the update() function of analyze_rms.cpp:
Code:
audio_block_t *block = receiveReadOnly();
if (!block) {
    count++;
    return;
}

If I have understood correctly, count is incremented once every time if an audio block is analyzed. It therefore represents the number of analyzed blocks. If count is > 0, data is available. Calling read() resets count to 0.

But why it is also incremented if block is zero/null? available() would return true but read() would return 0 (if no other blocks are analyzed yet).

In all other analyze objects the update() function starts like this:
Code:
block = receiveReadOnly();
if (!block) return;
 
Because the audio library rules say the block pointer "may be NULL, which should be treated as if a block of silent zeros was received". For the purposes of AudioAnalyzeRMS a block of silence has been received, so it's counted, but there's no need to do further work because the accumulator wouldn't change. 0 is indeed the correct answer...

Other objects do indeed use the code you reference ... often, it's completely incorrect to do that, e.g. in older versions of reverb, envelope and fader objects where their internal state will change even if supplied with silence.
 
Back
Top