• 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: Changing an AudioUnit's sample rate in an AUGraph
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Changing an AudioUnit's sample rate in an AUGraph


  • Subject: Re: Changing an AudioUnit's sample rate in an AUGraph
  • From: William Stewart <email@hidden>
  • Date: Tue, 29 May 2007 18:56:12 -0700

The basic problem is that formats cannot be changed on audio units when they have been initialised; when you initialise a graph, it initialises all of its audio units. So, to resolve this you have to uninitialise the audio units.

The second issue, is that you cannot change the format of an input to an audio unit if that AU has a connection to that input. Why? Because the connection between two audio units is a sharing of a common "connection" format (if I have to get audio from you, then we better agree on what format/layout that audio is). So, you have to break the connection to change the format.

Here's a routine that basically does this for you (I've stripped it down a little bit, but it should be what you need). The graph has to be stopped before you call this

OSStatus	MyClass::DoSetSampleRate (Float64 inSampleRate)
{
	OSStatus result;

	AudioUnitNodeConnection	*conns = NULL;

UInt32 numConns;
require_noerr (result = AUGraphGetNumberOfConnections (mGraph, &numConns), home);
conns = new AudioUnitNodeConnection [numConns];

for (UInt32 i = 0; i < numConns; i++) {
require_noerr (result = AUGraphGetConnectionInfo (mGraph, i,
&conns[i].sourceNode, &conns [i].sourceOutputNumber,
&conns[i].destNode, &conns [i].destInputNumber), home);
}
require_noerr (result = AUGraphClearConnections (mGraph), home);


UInt32 numNodes;
require_noerr (result = AUGraphGetNodeCount(mGraph, &numNodes), home);

// OK - now we go through and set the sample rate on each connection...
for (UInt32 i = 0; i < numNodes; i++)
{
AUNode node;
require_noerr (result = AUGraphGetIndNode(mGraph, i, &node), home);

AudioUnit au;
require_noerr (result = AUGraphGetNodeInfo(mGraph, node, NULL, NULL, NULL, &au), home);

{
CAAudioUnit unit(au);
if (mOutput.GetAUNode() == node) {
// this is for AUHAL as the output node. You can't set the device side here, so you just set the client side
require_noerr (result = unit.SetSampleRate (kAudioUnitScope_Input, 0, inSampleRate), home);
require_noerr (result = unit.SetSampleRate (kAudioUnitScope_Output, 1, inSampleRate), home);
} else
require_noerr (result = unit.SetSampleRate (inSampleRate), home); // see CAAudioUnit.SetSampleRate(...)
}
}

for (UInt32 i = 0; i < numConns; ++i) {
// ok, now we can connect this up again
require_noerr (result = AUGraphConnectNodeInput (mGraph, conns [i].sourceNode, conns[i].sourceOutputNumber,
conns[i].destNode, conns[i].destInputNumber), home);

}


	mOutputFormat.mSampleRate = inSampleRate;

	if (wasInitialized)
		require_noerr (result = Initialize (), home);

	delete [] conns;
	return result;
}


On 26/05/2007, at 9:21 AM, Stephen F. Booth wrote:

Is it possible to change the sample rate for the AudioUnits contained in an AUGraph after AUGraphIntitialize() has been called? I've tried every variation I can think of, but with no luck.

Here is some more background: I am working with an AUGraph containing a ScheduledSoundPlayer -> Peak Limiter -> Graphic Equalizer -> Default Output Unit. I would like to create the graph once, and then use it for the output of multiple files. However, it is possible that the files will have different sample rates. I am able to get playback working for any sample rate as long as I set the AudioUnit properties before calling AUGraphInitialize. But, once AUGraphInitialize has been called, I am never able to change the sample rate, even if I call AUGraphUninitialize (I've even tried AUGraphClose). Here is the code I'm using to (attempt to) set the sample rate:

--
mailto:email@hidden
tel: +1 408 974 4056
________________________________________________________________________ __
"Much human ingenuity has gone into finding the ultimate Before.
The current state of knowledge can be summarized thus:
In the beginning, there was nothing, which exploded" - Terry Pratchett
________________________________________________________________________ __


_______________________________________________
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: 
 >Changing an AudioUnit's sample rate in an AUGraph (From: "Stephen F. Booth" <email@hidden>)

  • Prev by Date: DragAndDrop midi
  • Next by Date: Re: What is the way to set the timestamp for sending MIDI events?
  • Previous by thread: Changing an AudioUnit's sample rate in an AUGraph
  • Next by thread: DragAndDrop midi
  • Index(es):
    • Date
    • Thread