2012-04-26 59 views
1

我想在iPhone上做一些演讲者验证(作为课程项目)。我想知道如何从扬声器获得线性PCM。我阅读关于队列服务的文档,似乎它会记录声音,然后将其存储到文件中。有没有办法直接从这个线性PCM?文档中提到了一些有关缓冲区的内容,但我不太明白。也许这是做到这一点的关键?如何从iPhone上的录音中获取线性PCM?

回答

0
 AVAudioRecorder *audioRecorder = [[AVAudioRecorder alloc] 
        initWithURL:soundFileURL 
        settings:recordSettings 
        error:&error]; 
     audioRecorder.delegate = self; 
     audioRecorder.meteringEnabled = YES; 

然后开始使用的NSTimer如调用定时器拍摄时,你点击录音键

-(IBAction)record:(id)sender{ 
     NSTimer *recordTimer = [NSTimer scheduledTimerWithTimeInterval:.01 target:self 
     selector:@selector(recordTimerAction:) userInfo:nil repeats:YES];  
    } 

    -(void)recordTimerAction:(id)sender { 

      [audioRecorder updateMeters]; 
      const double ALPHA = 0.05; 
      double peakPowerForChannel = pow(10, (0.05 * [audioRecorder peakPowerForChannel:0])); 
      lowPassResults = ALPHA * peakPowerForChannel + (1.0 - ALPHA) * lowPassResults; 
      NSLog(@"The Amplitude of the recording Sound is %f",lowPassResults); 
      NSLog(@"The Normal Linear PCM Value is %f",[audioRecorder peakPowerForChannel:0]); 
    } 

//委托方法

-(void)audioRecorderDidFinishRecording: (AVAudioRecorder *)recorder successfully:(BOOL)flag{ 

     [recordTimer invalidate]; 

    } 
+0

的幅度将在范围从0到1,这可能是有益的 – Bala 2012-04-26 11:32:33

+0

请让我知道,如果不工作 – Bala 2012-05-01 07:22:34

+0

我发现,苹果有它的内置INT API这个被称为音频队列服务。我认为你的回答是正确的,但内置的API会更好。 – yoyosir 2012-05-04 04:47:35