Re: Getting Levels While Recording
Re: Getting Levels While Recording
- Subject: Re: Getting Levels While Recording
- From: alex <email@hidden>
- Date: Thu, 17 Aug 2006 10:39:21 -0700
Perhaps you need to byte swap those floats in order to interpret them? Maybe your audio data is in a different endian format. Just a thought.
alex
At 11:09 AM -0500 8/17/06, Dan Messing wrote:
>Hi,
>
>I'm trying to get levels while recording an audio sample - or rather I'm trying to make it work on an intel machine based on existing code that works on PPC.
>
>The current code looks like this:
>
>Float32 *samples = (Float32 *)buffer->mData;
>Float32 *limit = (Float32*) (((UInt8*)samples) + buffer->mDataByteSize);
>
>where buffer is of type AudioBuffer *
>
>This is then passed to the function:
>
>static void computeMaxLevels ( float* samples, Float32* limit, Float32 levels[2] )
>{
> Float32 leftMin, leftMax, rightMin, rightMax;
> leftMax = leftMin = rightMax = rightMin = 0.0;
>
> // compute the maximum level in each channel (hardcoded Float32 samples, 2 interleaved channels).
> while ( samples < limit )
> {
> Float32 left = samples[0];
> if (left > leftMax)
> leftMax = left;
> else if (left < leftMin)
> leftMin = left;
> Float32 right = samples[1];
> if (right > rightMax)
> rightMax = right;
> else if (right < rightMin)
> rightMin = right;
> samples += 2;
> }
> levels[0] = max ( leftMax, abs(leftMin) );
> levels[1] = max ( rightMax, abs(rightMin) );
>
> levels[0] = 20.0 * log10(levels[0] * levels[0]);
> levels[1] = 20.0 * log10(levels[1] * levels[1]);
>}
>
>PPC - the levels come out fine, but on intel they are way out of whack, making me think I'm dealing with a different data format on that platform.
>
>I've been looking through all the docs I can find to see what the data in buffer->mData looks like, but I am really out of my depth with this coreAudio stuff. If anyone can offer a helping hand, I would greatly appreciate it, even if it's to tell me that I'm looking in the wrong place to fix this problem.
>
>Thanks,
>Dan
>_______________________________________________
>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
_______________________________________________
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