2

I'm capturing audio within an AVCaptureSession, now I'm about to play it.

I'm really not into lower level audio processing, so ObjectAL seems a fair choice for this, so I tried to get buffer pointer, some format information, then create an ObjectAL buffer.

 -(void)captureOutput:(AVCaptureOutput*) captureOutput
didOutputSampleBuffer:(CMSampleBufferRef) sampleBuffer
       fromConnection:(AVCaptureConnection*) connection
{
    if ([captureOutput isKindOfClass:[AVCaptureAudioDataOutput class]])
    {

        // Get samples.
        CMBlockBufferRef audioBuffer = CMSampleBufferGetDataBuffer(sampleBuffer);
        size_t lengthAtOffset;
        size_t totalLength;
        char *samples;
        CMBlockBufferGetDataPointer(audioBuffer, 0, &lengthAtOffset, &totalLength, &samples);

        // Get format.
        CMAudioFormatDescriptionRef format = CMSampleBufferGetFormatDescription(sampleBuffer);
        const AudioStreamBasicDescription *description = CMAudioFormatDescriptionGetStreamBasicDescription(format);

        ALBuffer *openALbuffer = [ALBuffer bufferWithName:@"buffer just captured before"
                                                     data:sampleBuffer
                                                     size:totalLength
                                                   format:description->mFormatID
                                                frequency:description->mSampleRate];
    }
}

It says Invalid Value:

OAL Error: +[ALWrapper bufferDataStatic:format:data:size:frequency:]: Invalid Value (error code 0x0000a003)

ObjectAL actually hooks to some OpenAL stuff I did not get into, you may understand it better:ALBuffer.m, ALWrapper.m

Is there any format / buffer conversation I have to utilize before create such ObjectAL (OpenAL) buffer?

Geri Borbás
  • 15,810
  • 18
  • 109
  • 172
  • What data is being passed into bufferWithName (size, format, frequency)? OpenAL requires uncompressed little endian signed 16-bit PCM data. – Karl Apr 23 '14 at 15:51
  • 1
    Some example code to print an ASBD is at the bottom of this page: https://developer.apple.com/library/ios/documentation/MusicAudio/Conceptual/AudioUnitHostingGuide_iOS/ConstructingAudioUnitApps/ConstructingAudioUnitApps.html – Karl Apr 23 '14 at 15:55
  • Thanks for getting back, it uses `AVCaptureAudioDataOutput` default. Will try to override with the above. – Geri Borbás Apr 23 '14 at 16:05
  • Just can't use audioSettings. :( Here I can see, https://developer.apple.com/library/mac/samplecode/AVCaptureToAudioUnitOSX/Listings/CaptureSessionController_mm.html, but this property seems to be unavailable as of https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVCaptureAudioDataOutput_Class/Reference/Reference.html (Ahh, it is an OSX feature) – Geri Borbás Apr 23 '14 at 16:24
  • You just need to print out the AudioStreamBasicDescription you got from CMAudioFormatDescriptionGetStreamBasicDescription so that you can see what kind of audio data you have. My first guess is that the format of the captured audio data is something OpenAL doesn't understand. – Karl Apr 23 '14 at 17:11
  • I'm fine with this, but have no idea how to **set** audio capture format actually, as there is no hook for that. Gonna capture audio separately then (where I can set format manually), but sync with video looks to be more painful then. – Geri Borbás Apr 23 '14 at 17:36
  • It goes like: https://gist.github.com/eppz/11254372 – Geri Borbás Apr 24 '14 at 13:21
  • Then I create like: https://gist.github.com/eppz/11254457 – Geri Borbás Apr 24 '14 at 13:24
  • So it outputs like: https://gist.github.com/eppz/11254491 – Geri Borbás Apr 24 '14 at 13:25
  • Do you have any suggestion I can try here? Or I have to play with... ...some Audio Unit I really wanted to spare. :( – Geri Borbás Apr 24 '14 at 13:26
  • I can't really debug something like `Invalid Value`... :/ – Geri Borbás Apr 24 '14 at 13:36
  • Implemented painfully with `AudioToolbox`. :( – Geri Borbás Apr 24 '14 at 17:20

0 Answers0