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:
I am not sure with the channels, 0 and 1 gives always 0, all the other gives -160.
What am I doing wrong? Please help
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:
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:
for (int k=0; k < 2; 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);
NSString *aString = [[NSString alloc] initWithFormat:mad:"%4.2f",peak];
peakLabel.text = aString ;
}
What am I doing wrong? Please help
Last edited by a moderator: