1

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

4

2 回答 2

1

Audio Queue Services is for doing this. Just type in the code you need in the call back function. http://developer.apple.com/library/ios/#documentation/MusicAudio/Conceptual/AudioQueueProgrammingGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40005343

于 2012-05-04T04:49:36.930 回答
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];

    }
于 2012-04-26T11:27:17.500 回答