Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams
  • I'm getting audio (PCM) from the microphone using TheAmazingAudioEngine and putting it in a buffer;
  • Using TPAACAudioConverter I'm reading audio from my buffer and writing to a temp file (AAC);
  • In the processing thread of TPAACAudioConverter I replaced this:

    OSStatus status = ExtAudioFileWrite(destinationFile, numFrames, &fillBufList);
    

    with this:

    OSStatus status = ExtAudioFileWrite(destinationFile, numFrames, &fillBufList);
    UInt32 framesWritten = numFrames;
    totalFramesWritten += framesWritten;
    AudioBufferList readData;
    readData.mNumberBuffers = 1;
    ExtAudioFileSeek(destinationFile, totalFramesWritten - framesWritten);
    OSStatus readStatus = ExtAudioFileRead(destinationFile, &numFrames, &readData);
    ExtAudioFileSeek(destinationFile, totalFramesWritten);
    NSLog(@"Bytes read=%d", numFrames);
    

    but what I get is 0 numFrames read from file.

  • Any idea on what I may be doing wrong or any suggestion on alternative paths to achieve what I need?

    I don't quite get what are you doing: writing to destinationFile , then immediately re-reading what you've just written? user3078414 Jul 18, 2016 at 12:58 From what I understand encoding happen on ExtAudioFileWrite so I'm trying to use this write/read loop to get the encoded data. This is one of different way I'm trying to achieve the goal exposed in the first part of the question and also here stackoverflow.com/questions/38430805/… . Francesco Papagno Jul 19, 2016 at 7:19

    The issue is that whatever ExtAudioFile does under the hood doesn't allow for seeking on a file that is open for writing. If you look at the documentation for ExtAudioFileSeek it says "This function's behavior with files open for writing is currently undefined".

    You can solve this by using the more extensible (and difficult) Audio File Services and the Audio Converter Services directly instead of the convenient Extended audio file services.

    I abandoned this approach and reused the AQRecorder class from the SpeakHere example by Apple.

    The project is available here https://github.com/robovm/apple-ios-samples/tree/master/SpeakHere .

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question . Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers .