kailoon
kailoon

Reputation: 2069

How can I make the iPhone recording and playback audio level meter look the same?

I display an audio level meter for recording and playback of that recording. The level values are from 0 - 1.0. I draw a bar representing the 0 - 1.0 value on screen. To get the audio levels for recording I use:

OSStatus status = AudioQueueGetProperty(aqData.mQueue, kAudioQueueProperty_CurrentLevelMeter, aqLevelMeterState, &levelMeterStateDataSize);

float level = aqLevelMeterState[0].mAveragePower;

For playback I use:

// soundPlayer is an AVSoundPlayer
float level = [soundPlayer averagePowerForChannel:0];

I normalize level from 0 - 1.0.

Right now they look very different when showing the bar. The recording meter bar is more on the low end while the playback bar meter, when playing back that same recorded audio, stays more in the middle.

I'm trying to make the two meters look the same, but I'm fairly new to audio. I've done a bit of research and know that the recording is returning an RMS value and the playback is returning it in decibels.

Can someone knowledgeable in audio point me to links or documents, or give a little hint to make sense of these two values so that I can start making them look the same?

Upvotes: 1

Views: 929

Answers (2)

hotpaw2
hotpaw2

Reputation: 70733

Decibels are logarithmically scaled. So you probably want some equation such as:

myDb = 20.0 * log (myRMS / scaleFactor);

somewhere, where you'd have to calibrate the scaleFactor to match up the values you want for full scale.

Upvotes: 1

madmik3
madmik3

Reputation: 6983

It is the RMS or root mean square for a given timer interval. RMS is calculated by summing the square of each signal value for the total, divining that the number of samples to get the mean and then taking the square root of the mean.

     uint64 avgTotal;
    for(int i =0; i < sampleCount; i++)
       avgTotal+= (sample[i]*sample[i])/(uint64)sampleCount; //divide to help with overlfow

    float rms = sqrt(avgTotal);

You will have to understand enough about the data you a playing to get the signal values. The durration of time that you consider should not matter that much. 50-80ms should do it.

Upvotes: 1

Related Questions