Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Wellington2k

macrumors regular
Original poster
Jun 4, 2011
131
0
Hello.

I've made some code that gets the dB level of a recorder that's always recording. Here's the code:
Code:
-(void)logit:(NSTimer*)timer {
    if (![recorder isRecording]) {
		[decmeter updateMeters];
		level = [decmeter averagePowerForChannel:1];
		NSLog(@"DEC:%@",[NSString stringWithFormat:@"%.01f",level]);
    }
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/DEC.caf", NSTemporaryDirectory()]];
    decmeter = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSetting error:nil];
    
    //prepare to record
    decmeter.delegate = self;
    [decmeter prepareToRecord];
    [decmeter setMeteringEnabled:YES];
    
    // start recording
    [decmeter record];
    
    [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(logit:) userInfo:nil repeats:YES];
    
}

But It always outputs -160.

Plus it seems to not record.

Any help?
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.