如何从iPhone上的录音中获取线性PCM?

时间:2012-04-26 11:07:55

标签: iphone ios avfoundation pcm audioqueueservices

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

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分: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];

    }