Re: AudioUnit without AUGraph
Re: AudioUnit without AUGraph
- Subject: Re: AudioUnit without AUGraph
- From: Timo Rozendal <email@hidden>
- Date: Thu, 20 Sep 2012 08:52:52 +0200
Hi Niels,
" or is this standalone, unconnected use of an AudioUnit just not possible?"
I think it is best if you connect a Generic Output audiounit at the
output of your NewTimePitch unit.
This is the preferred way to do offline rendering of audio with
audiounits as far as I understand.
I have this working with an AUgraph, but I think it should work
without that as well.
Good luck
Timo Rozendal
On Thu, Sep 20, 2012 at 12:06 AM, Niels Bogaards
<email@hidden> wrote:
> Hi,
>
> I'm trying to use an AudioUnit (kAudioUnitSubType_NewTimePitch) without an AUGraph. I want my app to be the AU host, provide samples in the RenderNotify callback and provide an AudioBufferList to the AudioUnitRender function to obtain the processed samples.
> Creating and initializing the AU seems to work fine (no errors when I do AudioComponentInstanceNew, add the rendernotify and set the kAudioUnitProperty_SampleRate and kAudioUnitProperty_StreamFormat). However, when I call AudioUnitRender, it gives me a kAudioUnitErr_InvalidElement (-10877) error, and my render function is not called.
> Am I missing an initialization step, or is this standalone, unconnected use of an AudioUnit just not possible?
>
> my code:
>
> AudioComponentDescription desc;
> desc.componentType = kAudioUnitType_FormatConverter;
> desc.componentSubType = kAudioUnitSubType_NewTimePitch;
> desc.componentManufacturer = kAudioUnitManufacturer_Apple;
> AudioComponent c = AudioComponentFindNext(NULL, &desc);
>
> if(c){
> OSStatus err = AudioComponentInstanceNew(c, &mAudioUnit);
>
> err = AudioUnitAddRenderNotify(mAudioUnit, SendAudioToAU, self);
>
> AudioStreamBasicDescription asbd;
>
> Float64 samplerate = 44100.;
> err = AudioUnitSetProperty(mAudioUnit, kAudioUnitProperty_SampleRate, kAudioUnitScope_Global, 0, &samplerate, sizeof(Float64));
> UInt32 dataSize;
> err = AudioUnitGetProperty(mAudioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &asbd, &dataSize);
> err = AudioUnitSetProperty(mAudioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Global, 0, &asbd, sizeof(AudioStreamBasicDescription));
>
> err = AudioUnitInitialize(mAudioUnit);
>
> AudioTimeStamp ts;
> ts.mSampleTime = 0;
> ts.mFlags = kAudioTimeStampSampleTimeValid;
>
> UInt32 outputBusNumber = 0;
>
> AudioBufferList bufList;
>
> UInt32 numFrames = 1024;
> AudioBuffer bufL;
> bufL.mNumberChannels = 1;
> bufL.mDataByteSize = sizeof(Float32) * numFrames;
> bufL.mData = malloc(bufL.mDataByteSize);
> AudioBuffer bufR;
> bufR.mNumberChannels = 1;
> bufR.mDataByteSize = sizeof(Float32) * numFrames;
> bufR.mData = malloc(bufR.mDataByteSize);
>
> bufList.mNumberBuffers = 2;
> bufList.mBuffers[0] = bufL;
> bufList.mBuffers[1] = bufR;
>
> AudioUnitRenderActionFlags ioActionFlags = kAudioOfflineUnitRenderAction_Render;
> err = AudioUnitRender (mAudioUnit, &ioActionFlags, &ts, outputBusNumber, numFrames, &bufList);
> }
>
>
> Thanks,
>
> Niels
>
>
> _______________________________________________
> 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
_______________________________________________
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