I have recorded an audio file using AVAudioEngine:
[mainMixer installTapOnBus:0 bufferSize:4096 format:[mainMixer outputFormatForBus:0] block:^(AVAudioPCMBuffer *buffer, AVAudioTime *when) {
NSError *error;
// as AVAudioPCMBuffer's are delivered this will write sequentially. The buffer's frameLength signifies how much of the buffer is to be written
// IMPORTANT: The buffer format MUST match the file's processing format which is why outputFormatForBus: was used when creating the AVAudioFile object above
NSAssert([mixerOutputFile writeFromBuffer:buffer error:&error], @"error writing buffer data to file, %@", [error localizedDescription]);
}];
Now I want to take the samples of that file and delete the silent parts at the beginning and at the end of the file. I' m using a buffer to read the file:
AVAudioFrameCount kBufferFrameCapacity = 128 * 1024L;
AVAudioPCMBuffer *readBuffer = [[AVAudioPCMBuffer alloc]initWithPCMFormat:audioFile.processingFormat frameCapacity:kBufferFrameCapacity];
[audioFile readIntoBuffer:readBuffer error: &error]
and then I 'm trying to access the float values of the samples of the audioFile:
for (AVAudioChannelCount channelIndex = 0; channelIndex < readBuffer.format.channelCount; ++channelIndex)
{
float *channelData = readBuffer.floatChannelData[channelIndex];
for (AVAudioFrameCount frameIndex = 0; frameIndex < readBuffer.frameLength; ++frameIndex)
{
float sampleLevel = channelData[frameIndex];
....
If I NSLog sampleLevel always return 0.0. What am I doing wrong? Am I taking the samples of the audioFile with the right way or I am totally wrong here?