• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: metering mixer output on ios
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: metering mixer output on ios


  • Subject: Re: metering mixer output on ios
  • From: Michael Tyson <email@hidden>
  • Date: Sun, 12 Aug 2012 09:50:34 +0100

No problem, Ash.

Be aware that that solution is very slow - it'll use up a big chunk of your CPU doing all those scalar operations. You'll get much better performance using the vector processor.

Here's what I'm doing, using Accelerate:

1. Create a scratch buffer that's an adequately large number of frames long, using floats

malloc(sizeof(float) * kScratchBufferSize).

2. When you have some output you want to monitor, loop though the data in lengths of kScratchBufferSize (or not, if you make your scratch buffer big enough so that you don't have to worry about it - although maybe add an assert to be sure you're not going to overrun in case the hardware buffer duration changes.

3. Convert the block into float: If it's 16-bit integer:

vDSP_vflt16(buffer->mBuffers[i].mData, 1, scratchBuffer, 1, numberOfFrames). 

If it's 32-bit integer, you can use vDSP_vflt32. If it's already float, you don't have to worry about that, or the scratch buffer, for that matter.

4. Determine the max value: 

float peak = 0.0; 
vDSP_maxmgv(scratchBuffer, 1, &peak, numberOfFrames); 
if ( peak > _monitorRecord->peak ) _monitorRecord->peak = peak;

5. Determine the average: 

float avg = 0.0; 
vDSP_meamgv(scratchBuffer, 1, &avg, numberOfFrames); 
_monitorRecord->meanAccumulator += avg; 
_monitorRecord->meanAccumulator->meanBlockCount++; 
_monitorRecord->average = _monitorRecord->meanAccumulator / _monitorRecord->meanBlockCount;

6. When queried, convert the peak/average into dB: 

averagePower = 10.0 * log10((double)_monitorRecord->average / (audioDescription.mBitsPerChannel == 16 ? INT16_MAX : INT32_MAX));

peakLevel = 10.0 * log10((double)_monitorRecord->peak / (audioDescription.mBitsPerChannel == 16 ? INT16_MAX : INT32_MAX));

7. After querying, reset the values (the most thread-safe way to do this is to set a "reset" flag which causes the monitoring code to reset when it sees it).


-- 
Michael Tyson | atastypixel.com

Live, app-to-app audio streaming is coming soon.
Don't want to miss our launch? Then sign up here: http://audiob.us



On 12 Aug 2012, at 04:22, Ash Gibson <email@hidden> wrote:

Thanks for your help Michael. Glad to hear that someone else has had the issue.

I'll take a look at the accelerate framework but in the meantime I found a solution that works well for me.

See here - http://www.politepix.com/2010/06/18/decibel-metering-from-an-iphone-audio-unit/#decibels

Cheers,

Ash
Do not post admin requests to the list. They will be ignored. Coreaudio-api mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Re: metering mixer output on ios (From: Ash Gibson <email@hidden>)

  • Prev by Date: Re: How to handle a packet lost with AudioQueue ?
  • Next by Date: Re: How to handle a packet lost with AudioQueue ?
  • Previous by thread: Re: metering mixer output on ios
  • Next by thread: Re: metering mixer output on ios
  • Index(es):
    • Date
    • Thread