• 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: VU Meter
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: VU Meter


  • Subject: Re: VU Meter
  • From: Lieven Dekeyser <email@hidden>
  • Date: Fri, 2 Aug 2002 14:50:07 +0200 (CEST)

Hi!

Thanks to Kurt Revis and Herbie Robinson, I managed to put together an
acceptible VU-meter. It could probably use some optimizing, and I guess
it won't be too accurate, but hey... if it's good enough for me, maybe
someone might find it useful :-)

--Lieven


// when setting up the AudioUnits
Float32 * level = malloc(numChannels*sizeof(Float32));
AudioUnitSetRenderNotification(theAudioUnit, OutputRenderNotification, level);

// then you can check the level of each channel at any time: e.g:
[leftVU setLevel:level[leftChannel]];
[rightVU setLevel:level[rightChannel]];

// the RenderNotification callback
OSStatus OutputRenderNotification(void *inRefCon, AudioUnitRenderActionFlags inActionFlags,
const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, AudioBuffer *ioData)
{
static Float32 scalar = 0.0f;

Float32 * output = (Float32*)inRefCon;

if (scalar == 0.0f) scalar = pow(0.5f, ((Float32)ioData->mDataByteSize)/44100.0f);

// only execute after rendering
if (output != 0 && inActionFlags & kAudioUnitRenderAction_PostRender)
{
UInt32 numChannels = ioData->mNumberChannels;
int i, j, numFrames = ioData->mDataByteSize/(4*numChannels);
Float32 abs;
Float32 input[numChannels];
Float32 *src = (Float32*)ioData->mData;

for (i = 0; i < numChannels; i++) input[i] = 0.0f;

for (i = 0; i < numFrames; i++)
{
for (j = 0; j < numChannels; j++)
{
abs = *(src++); if (abs < 0.0f) abs = -abs;
input[j] += abs;
}
}

for (i = 0; i < numChannels; i++)
{
input[i] /= (Float32)numFrames;

if (input[i] >= output[i])
{
output[i] = input[i];
}
else
{
output[i] *= scalar;
if (output[i] < 0.00001f) output[i] = 0.0f;
}
}
}

return noErr;
}

---
The frustration Windows users often experience is reflected in a
clickable link I found in Windows XP's online help: "I still can't scan."



On Wed, 31 Jul 2002, Kurt Revis wrote:

> > I'd like to have something like a VU-meter for my app, but I'm not sure
> > how to do this.
> >
> > Given the played array of floats, how should I transform this into the
> > current volume level?
>
> See http://www.musicdsp.org.
> Specifically:
> http://www.musicdsp.org/archive.php?classid=2#19
>
> You can also search the archives of the music-dsp mailing list here:
> http://shoko.calarts.edu/~glmrboy/musicdsp/musicdsparchives.html
>
> searching for 'music-dsp "vu meter"' returned some useful hits. It's a
> more complicated subject than you might expect.
>
> --
> Kurt Revis
> email@hidden
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Playing lots of tiny sounds with different formats?
  • Next by Date: Quicktime 6 and Multichannel Audio
  • Previous by thread: <UPDATE> Java Sample rate Conversation - AudioConverter.fillBuffer quits app with exitcode 10 ??? wth?
  • Next by thread: Quicktime 6 and Multichannel Audio
  • Index(es):
    • Date
    • Thread