1

From a delegate method I am receiving an AudioBufferList while I am recording audio. I am trying to collect the data from the AudioBufferList and save it so I can load it into my AVAudioPlayer but the AVAudioPlayer throws an error and I am unable to play the recording. I need to be able to play the audio through AVAudioPlayer without having the file, just by using the AudioBufferList.

Originally I was saving the recording to a file then loading it into AVAudioPlayer but with this method I was unable to append to the recording without having to make another audio file then merging the 2 files after the append was made. This was taking to much time and I would still like to be able to listen to the recording between appends. So now I am not saving the audio file so that I can keep appending to it until I wish to save it. The problem with this is the NSData that I am saving from the AudioBufferList is not loading into the AVAudioPlayer properly.

Here is my code for gathering the NSData:

- (void)      microphone:(EZMicrophone *)microphone
       hasBufferList:(AudioBufferList *)bufferList
      withBufferSize:(UInt32)bufferSize
withNumberOfChannels:(UInt32)numberOfChannels
{
    AudioBuffer sourceBuffer = bufferList->mBuffers[0];

    if (audioBuffer.mDataByteSize != sourceBuffer.mDataByteSize)
    {
        free(audioBuffer.mData);
        audioBuffer.mDataByteSize = sourceBuffer.mDataByteSize;
        audioBuffer.mData = malloc(sourceBuffer.mDataByteSize);
    }

    int currentBuffer =0;
    int maxBuf = 800;

    for( int y=0; y< bufferList->mNumberBuffers; y++ )
    {
        if (currentBuffer < maxBuf)
        {
            AudioBuffer audioBuff = bufferList->mBuffers[y];
            Float32 *frame = (Float32*)audioBuff.mData;

            [data appendBytes:frame length:audioBuffer.mDataByteSize];
            currentBuffer += audioBuff.mDataByteSize;
        }
        else
        {
            break;
        }
    }
}

When I try and load the NSData into AVAudioPlayer I get the following error:

self.audioPlayer = [[AVAudioPlayer alloc] initWithData:data error:&err];

err: Error Domain=NSOSStatusErrorDomain Code=1954115647 "The operation couldn’t be completed. (OSStatus error 1954115647.)"

Any help would be appreciated.

Thank you,

  • possible duplicate of [iPhone: AVAudioPlayer unsupported file type](http://stackoverflow.com/questions/4901709/iphone-avaudioplayer-unsupported-file-type) – Raptor Jun 03 '15 at 03:09
  • That issue involves collecting the NSData from an existing file while I am gathering mine from an AudioBufferList. Thanks for the reply though. – Kevin Jacob Jun 03 '15 at 03:29
  • Just tried your code and got the exact same error. Let me know if you found out what was wrong – Miniroo Jan 21 '16 at 01:17
  • @Miniroo No luck so far. – Kevin Jacob Jan 28 '16 at 18:48

0 Answers0