Mercurial > hg > beaglert
diff examples/02-Digital/level-meter/render.cpp @ 543:8f8809c77dda prerelease
updated basics, digital, instruments, extras examples
author | chnrx <chris.heinrichs@gmail.com> |
---|---|
date | Fri, 24 Jun 2016 13:19:52 +0100 |
parents | 8fcfbfb32aa0 |
children |
line wrap: on
line diff
--- a/examples/02-Digital/level-meter/render.cpp Fri Jun 24 13:00:31 2016 +0100 +++ b/examples/02-Digital/level-meter/render.cpp Fri Jun 24 13:19:52 2016 +0100 @@ -57,6 +57,12 @@ rt_printf("Error: this project needs the audio and digital sample rates to be the same.\n"); return false; } + + // For this example we need the same amount of audio input and output channels + if(context->audioInChannels != context->audioOutChannels){ + printf("Error: for this project, you need the same number of audio input and output channels.\n"); + return false; + } // Initialise threshold levels in -3dB steps. One extra for efficiency in render() // Level = 10^(dB/20) @@ -77,10 +83,10 @@ for(unsigned int n = 0; n < context->audioFrames; n++) { // Get average of audio input channels float sample = 0; - for(unsigned int ch = 0; ch < context->audioChannels; ch++) { - context->audioOut[n * context->audioChannels + ch] = - context->audioIn[n * context->audioChannels + ch]; - sample += context->audioIn[n * context->audioChannels + ch]; + for(unsigned int ch = 0; ch < context->audioInChannels; ch++) { + context->audioOut[n * context->audioOutChannels + ch] = + context->audioIn[n * context->audioInChannels + ch]; + sample += context->audioIn[n * context->audioInChannels + ch]; } // Do DC-blocking on the sum @@ -92,7 +98,7 @@ gLastY[1] = gLastY[0]; gLastY[0] = out; - out = fabsf(out / (float)context->audioChannels); + out = fabsf(out / (float)context->audioOutChannels); // Do peak detection: fast-responding local level if(out > gAudioLocalLevel)