• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Problem with ExtAudioFileWriteAsync and stereo data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem with ExtAudioFileWriteAsync and stereo data


  • Subject: Problem with ExtAudioFileWriteAsync and stereo data
  • From: Tim Kemp <email@hidden>
  • Date: Wed, 05 Dec 2012 10:01:42 -0500

Hi,

Further to my recent posts on this I have narrowed my problem down to how I'm handling stereo data. 

I use this ASBD for the RemoteIO output:

        // Set desired audio output format
        memset(&_outputASBD, 0, sizeof(_outputASBD));
        _outputASBD.mSampleRate        = 44100.0;
        _outputASBD.mFormatID          = kAudioFormatLinearPCM;
        _outputASBD.mFormatFlags       = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsBigEndian | kAudioFormatFlagIsPacked;
        _outputASBD.mBytesPerPacket    = sizeof(AudioUnitSampleType);
        _outputASBD.mBytesPerFrame     = sizeof(AudioUnitSampleType);
        _outputASBD.mFramesPerPacket   = 1;
        _outputASBD.mChannelsPerFrame  = 2;
        _outputASBD.mBitsPerChannel    = 16;

And I use an identical one for the recorded file itself. I have my audio generation as a render callback on bus 0 of a multi-channel mixer which is hooked up to the RemoteIO unit in an AUGraph.

In my render callback, I take the generated buffers - the same buffers that are sent to the RemoteIO unit - and try to write them. First I tried this (this is called directly by the render callback C function):

- (OSStatus) getGeneratedSamples:(AudioBufferList *) ioData frames:(UInt32) numFrames
{
    OSStatus result = [self.delegate generateSamples:ioData frames:numFrames];

    

    if (_isRecording) {
        checkError(ExtAudioFileWriteAsync(_recFileRef,
                                          numFrames,
                                          ioData),
                   "ExtAudioFileWriteAsync failed", false);
    }

    

    return result;
}

And it gives an EXC_BAD_ACCESS like this:

* thread #11: tid = 0x2d03, 0x028e2f77 libsystem_sim_c.dylib`memcpy$VARIANT$sse42 + 154, stop reason = EXC_BAD_ACCESS (code=2, address=0x0)
    frame #0: 0x028e2f77 libsystem_sim_c.dylib`memcpy$VARIANT$sse42 + 154
    frame #1: 0x002e2cad AudioToolbox`AudioRingBuffer::Store(AudioBufferList const*, unsigned long, long long) + 765
    frame #2: 0x003ab516 AudioToolbox`ExtAudioFile::WriteFramesAsync(unsigned long, AudioBufferList const*) + 566
    frame #3: 0x003ac5f4 AudioToolbox`ExtAudioFileWriteAsync + 116
    frame #4: 0x00054f87 Cellular`-[TKCoreAudioBridge getGeneratedSamples:frames:] + 279 at TKCoreAudioBridge.m:221

Then I tried to work with just one channel, like this:

if (_isRecording) {
          AudioBuffer *leftAudioBuffer = &ioData->mBuffers[0];
        AudioBuffer *rightAudioBuffer = &ioData->mBuffers[1];
        SInt32 *leftData = (SInt32 *) leftAudioBuffer->mData;
        SInt32 *rightData = (SInt32 *) rightAudioBuffer->mData;

        

        AudioBufferList abl;
        abl.mNumberBuffers = 1;
        abl.mBuffers[0] = *leftAudioBuffer;
        
        checkError(ExtAudioFileWriteAsync(_recFileRef,
                                          numFrames,
                                          &abl),
                   "ExtAudioFileWriteAsync failed", false);
    }

And, this time, it works (though the left channel of the file is filled with static because the ASBD expects two buffers.)

If I then try this:

if (_isRecording) {
        AudioBuffer *leftAudioBuffer = &ioData->mBuffers[0];
        AudioBuffer *rightAudioBuffer = &ioData->mBuffers[1];
        SInt32 *leftData = (SInt32 *) leftAudioBuffer->mData;
        SInt32 *rightData = (SInt32 *) rightAudioBuffer->mData;

        

        AudioBufferList abl;
        abl.mNumberBuffers = 2;
        abl.mBuffers[0] = *leftAudioBuffer;
        abl.mBuffers[1] = *rightAudioBuffer;

        

        checkError(ExtAudioFileWriteAsync(_recFileRef,
                                          numFrames,
                                          ioData),
                   "ExtAudioFileWriteAsync failed", false);
    }


I get the same EXC_BAD_ACCESS error.

How should I be writing stereo data to the file using that ASBD? Should I also be changing my RemoteIO's ASBD too? Is this something to do with interleaving?

Thanks
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: AUVarispeed glitches
  • Next by Date: Re: How to capture audio generated by a render callback, iOS
  • Previous by thread: AUVarispeed glitches
  • Next by thread: Re: A number of simple questions (still a few unanswered)
  • Index(es):
    • Date
    • Thread