I am listing from the mic using AVAudioEngine
by this code:
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];
Then as u see passing the buffer I get into a function called 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]) ;
}
}
}
for now, I only want to print the values of floatChannelData
.
The problem is that it is always printing 0. so the buffer has all values 0.
Why is this happening? shouldn't the values be changing with the change of voices received by the mic?