dB Meter Help

Discussion in 'iOS Programming' started by Wellington2k, Mar 30, 2012.

  1. Wellington2k, Mar 30, 2012
    Last edited: Mar 31, 2012

    Wellington2k macrumors regular

    Joined:
    Jun 4, 2011
    #1
    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?
     
  2. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #2
    Just a stupid question, i haven't read through the code, did you test on a device or the simulator? :)
     
  3. Wellington2k thread starter macrumors regular

    Joined:
    Jun 4, 2011

Share This Page