我想做一些像iPhone上的演讲者验证(作为课程项目)。我想知道如何从扬声器中获得线性PCM。我读到了有关队列服务的文档,它似乎记录了声音,然后将其存储到文件中。有没有办法从这直接获得线性PCM?文档提到了缓冲区的一些内容,但我不太明白。也许这是做到这一点的关键?
答案 0 :(得分:1)
音频队列服务就是这样做的。只需在回调函数中输入您需要的代码即可。 http://developer.apple.com/library/ios/#documentation/MusicAudio/Conceptual/AudioQueueProgrammingGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40005343
答案 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];
}