我使用AVAudioEngine
以下代码从麦克风中列出:
NSError *err2 = nil;
engine = [[AVAudioEngine alloc] init];
mainMixer = [engine mainMixerNode];
[mainMixer installTapOnBus:0 bufferSize:1024 format:[mainMixer outputFormatForBus:0] block:^(AVAudioPCMBuffer * _Nonnull buffer, AVAudioTime * _Nonnull when) {
[self normalize:buffer];
}];
[engine startAndReturnError:&err2];
然后当你看到传递缓冲区时,我进入了一个名为normalize:
-(void) normalize:(AVAudioPCMBuffer*) buffer{
float sum = 0;
NSMutableArray *values = [NSMutableArray new];
for (AVAudioFrameCount i = 0; i < buffer.frameLength; i++) {
[values addObject:@(buffer.floatChannelData[0][i])];
}
for (int i = 0 ; i< [values count]; i++){
if ([values[i] floatValue] != 0){
NSLog(@"%f", [values[i] floatValue]) ;
}
}
}
现在,我只想打印floatChannelData
. 问题是它总是打印 0。所以缓冲区的所有值都是 0。为什么会这样?这些值不应该随着麦克风接收到的声音的变化而变化吗?