• 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
Re: How to capture audio generated by a render callback, iOS
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to capture audio generated by a render callback, iOS


  • Subject: Re: How to capture audio generated by a render callback, iOS
  • From: Tim Kemp <email@hidden>
  • Date: Thu, 06 Dec 2012 08:43:29 -0500

Your audio is 16-bit wide but you are using 32-bit integers in your
interleaving code. That can't be right.

I understand your point. 

SInt16 *intlvData    = (SInt16 *) _tmpBuf.mData;
SInt16 *leftSrcData  = (SInt16 *) ioData->mBuffers[0].mData;
SInt16 *rightSrcData = (SInt16 *) ioData->mBuffers[1].mData;
_tmpBuf.mDataByteSize = sizeof(SInt16) * numFrames * 2;

Done. Sound is completely garbled from the speakers now, so I changed the sample generation code from this, which was working fine although you make me suspect that was more luck than judgement:

- (OSStatus) stereoGenerateSamples:(AudioBufferList *) buffers frames:(int) numFrames
{
    AudioBuffer *leftAudioBuffer = &buffers->mBuffers[0];
    AudioBuffer *rightAudioBuffer = &buffers->mBuffers[1];
    SInt32 *leftData = (SInt32 *) leftAudioBuffer->mData;
    SInt32 *rightData = (SInt32 *) rightAudioBuffer->mData;

        

    engine->getStereoSamples(_tmpBuf, numFrames);
    for (int i = 0; i < numFrames; ++i) {
        leftData[i] = _tmpBuf[i].left * 16777216L; // _tmpBuf contains structs { float left; float right; }
        rightData[i] = _tmpBuf[i].right * 16777216L;
    }

        

    return noErr;
}

to this:

- (OSStatus) stereoGenerateSamples:(AudioBufferList *) buffers frames:(int) numFrames
{
    AudioBuffer *leftAudioBuffer = &buffers->mBuffers[0];
    AudioBuffer *rightAudioBuffer = &buffers->mBuffers[1];
    SInt16 *leftData = (SInt16 *) leftAudioBuffer->mData;
    SInt16 *rightData = (SInt16 *) rightAudioBuffer->mData;

        

    engine->getStereoSamples(_tmpBuf, numFrames);
    for (int i = 0; i < numFrames; ++i) {
        leftData[i] = _tmpBuf[i].left * INT16_MAX;
        rightData[i] = _tmpBuf[i].right * INT16_MAX;
    }

        

    return noErr;
}

It sounds very cool, but not the actual simple waveforms it should be.

This method here (stereoGenerateSamples) is called by the callback you've been looking at. For context:

OSStatus auRenderCallback(void *inRefCon,
                          AudioUnitRenderActionFlags *ioActionFlags,
                          const AudioTimeStamp *inTimeStamp,
                          UInt32 inBusNumber,
                          UInt32 inNumberFrames,
                          AudioBufferList *ioData)
{
    TKCoreAudioBridge * output = (__bridge TKCoreAudioBridge *) inRefCon;
    
    return [output getGeneratedSamples:ioData frames:inNumberFrames];
}

- (OSStatus) getGeneratedSamples:(AudioBufferList *) ioData frames:(UInt32) numFrames
{
    OSStatus result = [self.delegate generateSamples:ioData frames:numFrames]; // This is the first method I posted

    

    if (_isRecording) {
        SInt16 *intlvData    = (SInt16 *) _tmpBuf.mData;
        SInt16 *leftSrcData  = (SInt16 *) ioData->mBuffers[0].mData;
        SInt16 *rightSrcData = (SInt16 *) ioData->mBuffers[1].mData;
        _tmpBuf.mDataByteSize = sizeof(AudioSampleType) * numFrames * 2;

        // Interleave
        int l = 0;
        int r = 1;
        for (int i = 0; i < numFrames; i++) {
            intlvData[l] = leftSrcData[i];
            intlvData[r] = rightSrcData[i];
            l += 2;
            r += 2;
        }

        

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

    

    return result;
}
 _______________________________________________
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

  • Follow-Ups:
    • Re: How to capture audio generated by a render callback, iOS
      • From: Tim Kemp <email@hidden>
References: 
 >How to capture audio generated by a render callback, iOS (From: Tim Kemp <email@hidden>)
 >Re: How to capture audio generated by a render callback, iOS (From: Gregory Wieber <email@hidden>)
 >Re: How to capture audio generated by a render callback, iOS (From: Tim Kemp <email@hidden>)
 >Re: How to capture audio generated by a render callback, iOS (From: Tim Kemp <email@hidden>)
 >Re: How to capture audio generated by a render callback, iOS (From: Aran Mulholland <email@hidden>)
 >Re: How to capture audio generated by a render callback, iOS (From: Tim Kemp <email@hidden>)
 >Re: How to capture audio generated by a render callback, iOS (From: Tim Kemp <email@hidden>)
 >Re: How to capture audio generated by a render callback, iOS (From: Joel Reymont <email@hidden>)
 >Re: How to capture audio generated by a render callback, iOS (From: Tim Kemp <email@hidden>)
 >Re: How to capture audio generated by a render callback, iOS (From: Paul Davis <email@hidden>)
 >Re: How to capture audio generated by a render callback, iOS (From: Joel Reymont <email@hidden>)
 >Re: How to capture audio generated by a render callback, iOS (From: Tim Kemp <email@hidden>)
 >Re: How to capture audio generated by a render callback, iOS (From: Joel Reymont <email@hidden>)
 >Re: How to capture audio generated by a render callback, iOS (From: Tim Kemp <email@hidden>)
 >Re: How to capture audio generated by a render callback, iOS (From: Joel Reymont <email@hidden>)

  • Prev by Date: Re: How to capture audio generated by a render callback, iOS
  • Next by Date: Re: How to capture audio generated by a render callback, iOS
  • Previous by thread: Re: How to capture audio generated by a render callback, iOS
  • Next by thread: Re: How to capture audio generated by a render callback, iOS
  • Index(es):
    • Date
    • Thread