Note that there are some explanatory texts on larger screens.

plurals
  1. POThe math behind Apple's Speak here example
    text
    copied!<p>I have a question regarding the math that Apple is using in it's <a href="http://developer.apple.com/library/ios/#samplecode/SpeakHere/Introduction/Intro.html">speak here example</a>.</p> <p>A little background: I know that average power and peak power returned by the AVAudioRecorder and AVAudioPlayer is in dB. I also understand why the RMS power is in dB and that it needs to be converted into amp using <code>pow(10, (0.5 * avgPower))</code>.</p> <p>My question being:</p> <p>Apple uses this formula to create it's "Meter Table"</p> <pre><code>MeterTable::MeterTable(float inMinDecibels, size_t inTableSize, float inRoot) : mMinDecibels(inMinDecibels), mDecibelResolution(mMinDecibels / (inTableSize - 1)), mScaleFactor(1. / mDecibelResolution) { if (inMinDecibels &gt;= 0.) { printf("MeterTable inMinDecibels must be negative"); return; } mTable = (float*)malloc(inTableSize*sizeof(float)); double minAmp = DbToAmp(inMinDecibels); double ampRange = 1. - minAmp; double invAmpRange = 1. / ampRange; double rroot = 1. / inRoot; for (size_t i = 0; i &lt; inTableSize; ++i) { double decibels = i * mDecibelResolution; double amp = DbToAmp(decibels); double adjAmp = (amp - minAmp) * invAmpRange; mTable[i] = pow(adjAmp, rroot); } } </code></pre> <p>What are all the calculations - or rather, what do each of these steps do? I think that <code>mDecibelResolution</code> and <code>mScaleFactor</code> are used to plot 80dB range over 400 values (unless I'm mistaken). However, what's the significance of <code>inRoot</code>, <code>ampRange</code>, <code>invAmpRange</code> and <code>adjAmp</code>? Additionally, why is the i-th entry in the meter table "<code>mTable[i] = pow(adjAmp, rroot);</code>"?</p> <p>Any help is much appreciated! :)</p> <p>Thanks in advance and cheers!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload