Getting sound in decibels

I need the sound that I am recording from the iPhone microphone in decibels. I use

[recorder peakPowerForChannel:]

but it gives a range of -160 to 0 and I have a requirement to take 140 dB as a threshold. Can anyone help me with the same ...?

Here is some sample code below that I am trying:

NSMutableDictionary *recordSettings = [[NSMutableDictionary alloc] init];

[recordSettings setObject:[NSNumber numberWithInt:kAudioFormatAppleLossless] forKey:   AVFormatIDKey];
[recordSettings setObject:[NSNumber numberWithFloat:22050.0] forKey: AVSampleRateKey];
//  [recordSettings setObject:[NSNumber numberWithInt:2] forKey:AVNumberOfChannelsKey];
[recordSettings setObject:[NSNumber numberWithInt:12800] forKey:AVEncoderBitRateKey];
[recordSettings setObject:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[recordSettings setObject:[NSNumber numberWithInt: AVAudioQualityLow] forKey: AVEncoderAudioQualityKey];
NSError* error = nil;
recorder = [[AVAudioRecorder alloc] initWithURL:recordedFile  settings:recordSettings  error:&error];


[recorder prepareToRecord];
recorder.meteringEnabled = YES;
[recorder record];
NSTimer *blowTimer=[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(timerTask) userInfo:nil repeats:YES];

[[NSRunLoop currentRunLoop] addTimer: blowTimer
                             forMode: NSDefaultRunLoopMode];

-(void)timerTask
{
    [recorder updateMeters];
    float averagePower = [recorder averagePowerForChannel:0];

}

      

+3


source to share





All Articles