• 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: getting generator audio unit output in render callback
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getting generator audio unit output in render callback


  • Subject: Re: getting generator audio unit output in render callback
  • From: Rich E <email@hidden>
  • Date: Wed, 09 Jan 2013 01:49:47 -0500

It appears to only be an issue when using an AUGraph; the following code successfully gives me the same setup as what I previously posted.  Can anyone see why the AUGraph version in the previous email doesn't work?

- (int)createSynthWithoutAUGraph {

// speech synthesizer
AudioComponentDescription speechCD = {0};
speechCD.componentType = kAudioUnitType_Generator;
speechCD.componentSubType = kAudioUnitSubType_SpeechSynthesis;
speechCD.componentManufacturer = kAudioUnitManufacturer_Apple;

// output device (speakers)
AudioComponentDescription outputCD = {0};
outputCD.componentType = kAudioUnitType_Output;
outputCD.componentSubType = kAudioUnitSubType_DefaultOutput;
outputCD.componentManufacturer = kAudioUnitManufacturer_Apple;

AudioComponent speechComponent = AudioComponentFindNext(NULL, &speechCD);
if(!speechComponent) {
AU_LOG(@"Error: could not locate speech unit");
return -1;
}
AU_CHECK( AudioComponentInstanceNew( speechComponent, &_speechUnit ) );
AU_CHECK( AudioUnitInitialize( _speechUnit ) );

AudioComponent outputComponent = AudioComponentFindNext(NULL, &outputCD);
if(!outputComponent) {
AU_LOG(@"Error: could not locate output unit");
return -1;
}
AU_CHECK( AudioComponentInstanceNew( outputComponent, &_outputUnit ) );
AU_CHECK( AudioUnitInitialize( _outputUnit ) );

// setup callback:
AURenderCallbackStruct callback = { &PdRenderCallback, self };
AU_CHECK( AudioUnitSetProperty( _outputUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &callback, sizeof(callback)) );

// finally init and start
AU_LOG( @"AU successfully initialized without graph." );
AU_CHECK( AudioOutputUnitStart( _outputUnit) );
return 0;
}


On Sun, Jan 6, 2013 at 1:32 AM, Rich E <email@hidden> wrote:
I've been trying without success to manipulate the samples produced by kAudioUnitType_Generator audio units by attaching an AURenderCallbackStruct to the input of the audio unit right after.  I managed to get this working on OS X using the following simple graph:

(input callback) -> multichannel mixer -> (intput callback) -> default output

But I've failed with the following (even simpler) graphs that start with a generator unit:

speech synthesis -> (intput callback) -> default output           | fails in render callback with kAudioUnitErr_Uninitialized
audiofile player -> (intput callback) -> default output               | fails when scheduling file region with kAudioUnitErr_Uninitialized

I've tried just about everything I can think of, from setting ASBD format to sample rates, but I always get these errors.  Does anyone know how to setup a graph where we can manipulate samples from these nice generator units?

Below is the failing render callback function and graph instantiation method for the attempt using speech synthesis.  The audiofile player is almost identical for this, except setting up the file playback, of course.  Both of these setups work if I remove the callback and add an AUGraphConnectNodeInput in it's place...


static OSStatus RenderCallback(void *inRefCon,
AudioUnitRenderActionFlags *ioActionFlags,
const AudioTimeStamp *inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList *ioData) {

AppDelegate *app = (AppDelegate *)inRefCon;
AudioUnit inputUnit = app->_speechUnit;
OSStatus status = noErr;

status = AudioUnitRender(inputUnit, ioActionFlags, inTimeStamp, 0, inNumberFrames, ioData);
// *** ERROR *** kAudioUnitErr_Uninitialized, code: -10867

return status;
}

- (int)createSynthGraph {
AUGRAPH_CHECK( NewAUGraph( &_graph ) );

AUNode speechNode, outputNode;

// speech synthesizer
AudioComponentDescription speechCD = {0};
speechCD.componentType = kAudioUnitType_Generator;
speechCD.componentSubType = kAudioUnitSubType_SpeechSynthesis;
speechCD.componentManufacturer = kAudioUnitManufacturer_Apple;

// output device (speakers)
AudioComponentDescription outputCD = {0};
outputCD.componentType = kAudioUnitType_Output;
outputCD.componentSubType = kAudioUnitSubType_DefaultOutput;
outputCD.componentManufacturer = kAudioUnitManufacturer_Apple;

AUGRAPH_CHECK( AUGraphAddNode( _graph, &outputCD, &outputNode ) );
AUGRAPH_CHECK( AUGraphAddNode( _graph, &speechCD, &speechNode ) );

AUGRAPH_CHECK( AUGraphOpen( _graph ) );
AUGRAPH_CHECK( AUGraphNodeInfo( _graph, outputNode, NULL, &_outputUnit ) );
AUGRAPH_CHECK( AUGraphNodeInfo( _graph, speechNode, NULL, &_speechUnit ) );

// setup stream formats:
AudioStreamBasicDescription streamFormat = [self streamFormat];
AU_CHECK( AudioUnitSetProperty( _speechUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 0, &streamFormat, sizeof(streamFormat) ) );

// setup callback:
AURenderCallbackStruct callback;
callback.inputProc = RenderCallback;
callback.inputProcRefCon = self;
AUGRAPH_CHECK( AUGraphSetNodeInputCallback ( _graph, outputNode, 0, &callback ) );

// init and start
AUGRAPH_CHECK( AUGraphInitialize( _graph ) );
AUGRAPH_CHECK( AUGraphStart( _graph ) );
return 0;
}

Thanks for reading!

cheers,
Rich

 _______________________________________________
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

References: 
 >getting generator audio unit output in render callback (From: Rich E <email@hidden>)

  • Prev by Date: Granular Synthesis and AudioFileServices in iOS 6
  • Next by Date: recording in float with AVAudioRecorder
  • Previous by thread: getting generator audio unit output in render callback
  • Next by thread: AVAssetExportSession and MetaData
  • Index(es):
    • Date
    • Thread