Changing an AudioUnit's sample rate in an AUGraph
Changing an AudioUnit's sample rate in an AUGraph
- Subject: Changing an AudioUnit's sample rate in an AUGraph
- From: "Stephen F. Booth" <email@hidden>
- Date: Sat, 26 May 2007 09:21:33 -0700
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:
- (OSStatus) setAUGraphSampleRate:(Float64)sampleRate
{
// First check and see if the sample rate differs from the current
Float64 currentSampleRate = kAudioStreamAnyRate;
UInt32 dataSize = sizeof(currentSampleRate);
OSStatus err = AudioUnitGetProperty(_generatorUnit,
kAudioUnitProperty_SampleRate,
kAudioUnitScope_Output,
0,
¤tSampleRate,
&dataSize);
if(noErr != err) return err;
// If the sample rates match, do nothing
if(currentSampleRate == sampleRate) return noErr;
// If the graph is running, stop it
Boolean graphIsRunning = NO;
err = AUGraphIsRunning(_auGraph, &graphIsRunning);
if(noErr != err) return err;
if(graphIsRunning) {
err = AUGraphStop(_auGraph);
if(noErr != err) return err;
}
// If the graph is initialized, uninitialize it
Boolean graphIsInitialized = NO;
err = AUGraphIsInitialized(_auGraph, &graphIsInitialized);
if(noErr != err) return err;
if(graphIsInitialized) {
err = AUGraphUninitialize(_auGraph);
if(noErr != err) return err;
}
err = AudioUnitSetProperty(_generatorUnit,
kAudioUnitProperty_SampleRate,
kAudioUnitScope_Output,
0,
&sampleRate,
sizeof(sampleRate));
if(noErr != err) return err;
err = AudioUnitSetProperty(_limiterUnit,
kAudioUnitProperty_SampleRate,
kAudioUnitScope_Output,
0,
&sampleRate,
sizeof(sampleRate));
if(noErr != err) return err;
err = AudioUnitSetProperty(_equalizerUnit,
kAudioUnitProperty_SampleRate,
kAudioUnitScope_Output,
0,
&sampleRate,
sizeof(sampleRate));
if(noErr != err) return err;
err = AudioUnitSetProperty(_outputUnit,
kAudioUnitProperty_SampleRate,
kAudioUnitScope_Input,
0,
&sampleRate,
sizeof(sampleRate));
if(noErr != err) return err;
// If the graph was initialized, reinitialize it
if(graphIsInitialized) {
err = AUGraphInitialize(_auGraph);
if(noErr != err) return err;
}
// If the graph was running, restart it
if(graphIsRunning) {
err = AUGraphStart(_auGraph);
if(noErr != err) return err;
}
return noErr;
}
Once the AUGraph is uninitialized, when I try to set the sample rate
on the output unit I get a -10865
(kAudioUnitErr_PropertyNotWritable)- all the other calls to the other
units succeed. I tried commenting out the block that sets the output
device's input sample rate, but then the call to AUGraphInitialize
returns a -10865.
What have I missed?
Stephen
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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