Hi Everyone,
I am totally desperate now with this new class. I managed to make it work and record audio without problems but for some reason the metering does not work.
Could you please give me some help with this, what am I doing wrong:
In this very simple example I just want to display the current peak or average level, but I always get 0 or -160.
some code:
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayAndRecord error: nil];
NSDictionary *recordSettings =
[[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithFloat: 44100.0], AVSampleRateKey,
[NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey,
[NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
[NSNumber numberWithInt: AVAudioQualityMax], AVEncoderAudioQualityKey,
nil];
soundRecorder = [[AVAudioRecorder alloc] initWithURL: recURL
settings: recordSettings
error: nil];
soundRecorder.meteringEnabled = TRUE;
soundRecorder.delegate = self;
[soundRecorder prepareToRecord];
[soundRecorder record];
and I have a timer for checking:
[soundRecorder updateMeters];
for (int k=0; k < 3; k++) {
float peak = [soundRecorder peakPowerForChannel:k];
float average = [soundRecorder averagePowerForChannel:k];
NSLog(@”Peak power for channel %i: %4.2f”,k,peak);
NSLog(@”Average power for channel %i: %4.2f”,k,average);
}
I am not sure with the channels, 0 and 1 gives always 0, all the other gives -160