views:

37

answers:

1

I'm very new to core audio and I just would like some help in coding up a little volume meter for whatever's being outputted through headphones or built-in speaker, like a dB meter. I have the following code, and have been trying to go through the apple source project "SpeakHere", but it's a nightmare trying to go through all that, without knowing how it works first... Could anyone shed some light?

Here's the code I have so far...

(void)displayWaveForm 
{
 while (musicIsPlaying == YES {
  NSLog(@"%f",sizeof(AudioQueueLevelMeterState));
 }
}

(IBAction)playMusic 
{
 if (musicIsPlaying == NO) {
  NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/track7.wav",[[NSBundle mainBundle] resourcePath]]];

  NSError *error;

  music = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
  music.numberOfLoops = -1;

  music.volume = 0.5;
  [music play];
  musicIsPlaying = YES;
  [self displayWaveForm];
 }

 else {
  [music pause];
  musicIsPlaying = NO;
 }

}
A: 

you can use metering with the AVAudioPlayer class, first enable it then get the average power to use as your meter data avTouch has a working example

Aran Mulholland
Thanks for the quick reply, i figured this out a long time ago :P I thought it was something more complicated, however because of the fact that AVAudioPlayer is somewhat limited, I'm learning CoreAudio, well attempting to start, hopefully I can find some actual documentation/tutorials to get me started...
Adam
mark it as answered if it is answered, there are a few test projects i put together some time ago on core audio, have a look at them from my profile
Aran Mulholland