Skip to content

Instantly share code, notes, and snippets.

@bartolsthoorn
Created April 23, 2012 19:35
Show Gist options
  • Save bartolsthoorn/2473295 to your computer and use it in GitHub Desktop.
Save bartolsthoorn/2473295 to your computer and use it in GitHub Desktop.
Measuring dB / max amp in Novocaine
[audioManager setOutputBlock:^(float *data, UInt32 numFrames, UInt32 numChannels)
{
// Measure dB
float maxAmp = abs(data[0]);
for (int i=0; i < numFrames; ++i)
{
for (int iChannel = 0; iChannel < numChannels; ++iChannel)
{
if (abs(data[i*numChannels + iChannel]) > maxAmp) {
maxAmp = abs(data[i*numChannels + iChannel]);
}
}
}
printf("Maximum Amp in dB: %f\n", 20 * log10f(maxAmp));
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment