Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pull audio data from graph kAudioUnitSubType_GenericOutput

I am constructing audio graph, which has: AudioFilePlayer (Generator unit) -> GenericOutput (Output unit)

The basic idea:

AudioFilePlayer is producing audio frames to it's output. Generic output takes data from AudioFilePlayer's output as input. Than I can take that data and save it to other buffer.

My question is how to pull data from generic output to get data for offline rendering.

I did some research on it, and find out that I have to use AudioUnitRender on GenericOutput unit to pull audio data from it.

Uint32 frames = 512;
timestamp.mSampleTime = 0;

... While Loop ...

timestamp.mFlags = kAudioTimeStampSampleTimeValid;

bufferList.mNumberBuffers = 1;
bufferList.mBuffers[0].mNumberChannels = param->inputFormat.mChannelsPerFrame;
bufferList.mBuffers[0].mDataByteSize = frames * param->inputFormat.mChannelsPerFrame * sizeof(float);
bufferList.mBuffers[0].mData = NULL;

AudioUnitRenderActionFlags flags = 0;

OSStatus error = noErr;
if ((error = AudioUnitRender(param->genericOutput, &flags, &timestamp, 0, frames, &bufferList)) != noErr)
{
    printf("Cannot AudioUnitRender: %d\n", error);
}

timestamp.mSampleTime += frames;

But i get error with number -50.

Am I setting input parameters wrong? Do I need to register any render callback functions to GenericOutput unit?

like image 849
kestutisb Avatar asked Jan 27 '26 11:01

kestutisb


1 Answers

The problem was that I set GenericOutput StreamFormat after calling AUGraphInitialize(). It must be done before that.

I used CAShow(reader.graph) to get log of audio graph, which helped me to notice that format is't changed after trying to set it.

like image 156
kestutisb Avatar answered Jan 31 '26 19:01

kestutisb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!