Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9193191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:06:06+00:00 2026-06-17T21:06:06+00:00

I have a question regarding the math that Apple is using in it’s speak

  • 0

I have a question regarding the math that Apple is using in it’s speak here example.

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 pow(10, (0.5 * avgPower)).

My question being:

Apple uses this formula to create it’s “Meter Table”

MeterTable::MeterTable(float inMinDecibels, size_t inTableSize, float inRoot)
    : mMinDecibels(inMinDecibels),
    mDecibelResolution(mMinDecibels / (inTableSize - 1)), 
    mScaleFactor(1. / mDecibelResolution)
{
    if (inMinDecibels >= 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 < inTableSize; ++i) {
        double decibels = i * mDecibelResolution;
        double amp = DbToAmp(decibels);
        double adjAmp = (amp - minAmp) * invAmpRange;
        mTable[i] = pow(adjAmp, rroot);
    }
}

What are all the calculations – or rather, what do each of these steps do? I think that mDecibelResolution and mScaleFactor are used to plot 80dB range over 400 values (unless I’m mistaken). However, what’s the significance of inRoot, ampRange, invAmpRange and adjAmp? Additionally, why is the i-th entry in the meter table “mTable[i] = pow(adjAmp, rroot);“?

Any help is much appreciated! 🙂

Thanks in advance and cheers!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:06:07+00:00Added an answer on June 17, 2026 at 9:06 pm

    It’s been a month since I’ve asked this question, and thanks, Geebs, for your response! 🙂

    So, this is related to a project that I’ve been working on, and the feature that is based on this was implemented about 2 days after asking that question. Clearly, I’ve slacked off on posting a closing response (sorry about that). I posted a comment on Jan 7, as well, but circling back, seems like I had a confusion with var names. >_<. Thought I’d give a full, line by line answer to this question (with pictures). 🙂

    So, here goes:

    //mDecibelResolution is the "weight" factor of each of the values in the meterTable.
    //Here, the table is of size 400, and we're looking at values 0 to 399.
    //Thus, the "weight" factor of each value is minValue / 399.
    
    
    MeterTable::MeterTable(float inMinDecibels, size_t inTableSize, float inRoot)
        : mMinDecibels(inMinDecibels),
        mDecibelResolution(mMinDecibels / (inTableSize - 1)), 
        mScaleFactor(1. / mDecibelResolution)
    {
        if (inMinDecibels >= 0.)
        {
            printf("MeterTable inMinDecibels must be negative");
            return;
        }
    
        //Allocate a table to store the 400 values
        mTable = (float*)malloc(inTableSize*sizeof(float));
    
        //Remember, "dB" is a logarithmic scale.
        //If we have a range of -160dB to 0dB, -80dB is NOT 50% power!!!
        //We need to convert it to a linear scale. Thus, we do pow(10, (0.05 * dbValue)), as stated in my question.
    
        double minAmp = DbToAmp(inMinDecibels);
    
        //For the next couple of steps, you need to know linear interpolation.
        //Again, remember that all calculations are on a LINEAR scale.
        //Attached is an image of the basic linear interpolation formula, and some simple equation solving.
    

    Linear Interpolation Equation

        //As per the image, and the following line, (y1 - y0) is the ampRange - 
        //where y1 = maxAmp and y0 = minAmp.
        //In this case, maxAmp = 1amp, as our maxDB is 0dB - FYI: 0dB = 1amp.
        //Thus, ampRange = (maxAmp - minAmp) = 1. - minAmp
        double ampRange = 1. - minAmp;
    
        //As you can see, invAmpRange is the extreme right hand side fraction on our image's "Step 3"
        double invAmpRange = 1. / ampRange;
    
        //Now, if we were looking for different values of x0, x1, y0 or y1, simply substitute it in that equation and you're good to go. :)
        //The only reason we were able to get rid of x0 was because our minInterpolatedValue was 0.
    
        //I'll come to this later.
        double rroot = 1. / inRoot;
    
        for (size_t i = 0; i < inTableSize; ++i) {
            //Thus, for each entry in the table, multiply that entry with it's "weight" factor.
            double decibels = i * mDecibelResolution;
    
            //Convert the "weighted" value to amplitude using pow(10, (0.05 * decibelValue));
            double amp = DbToAmp(decibels);
    
            //This is linear interpolation - based on our image, this is the same as "Step 3" of the image.
            double adjAmp = (amp - minAmp) * invAmpRange;
    
            //This is where inRoot and rroot come into picture.
            //Linear interpolation gives you a "straight line" between 2 end-points.
           //rroot =  0.5
           //If I raise a variable, say myValue by 0.5, it is essentially taking the square root of myValue.
           //So, instead of getting a "straight line" response, by storing the square root of the value,
           //we get a curved response that is similar to the one drawn in the image (note: not to scale).
            mTable[i] = pow(adjAmp, rroot);
        }
    }
    

    Response Curve image: As you can see, the “Linear curve” is not exactly a curve. >_<
    Square root response image

    Hope this helps the community in some way. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question regarding using intptr_t vs. long int . I've observed that
I have a question regarding the best practise of handling formated text when using
I have question regarding polymorphism about its assignment statement, for Example this is The
I have a question regarding interfaces. I understood that you cannot create instances of
I have a question regarding template parts. I want to create a control that
I have a question regarding the std::sort algorithm. Here is my test code: struct
I have a question regarding the development of liferay portlets using the liferay plugin
I have a question regarding editing/saving data in database using Django. I have template
I have a question regarding javascript Math.random() : I have (for a game I'm
I have question regarding about finding subview using '.tags' in one UIView. for (UIView

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.