Re: Problems setting sample rate
Re: Problems setting sample rate
- Subject: Re: Problems setting sample rate
- From: email@hidden
- Date: Fri, 19 May 2006 15:32:08 -0400
Hi Bill,
Thanks for all of your help and advice.
After another few hours of testing, I'm pretty sure that my problem is
with the Mbox. Unfortunately I don't have enough other devices to be
certain of that. Unless you have an Mbox (not MBox 2) and have Ivory
(our plugin) installed, it will be hard to demonstrate the problem. If
you do have an Mbox and a machine with Ivory installed, I'd be more than
happy to send you a test program.
Here's my test setup.
Mac G5 running my host program and Ivory plugin. My host program does
not have the ability to select a sample rate. It does has the ability to
save and restore (in a plist) which interface and buffer size are selected.
Digidesign MBox connected via USB
SPDIF output connected to M-Audio SPDIF input
M-Audio Firewire Audiophile connected via Firewire
SPDIF output connected to Mbox SPDIF input
The Digi control program (NOT a control panel) has the ability to select
a sample rate if no clients are connected to it. It displays a sample
rate. The M-Audio control panel can display sample rate but cannot set
the rate.
1. Set the M-Audio interface to external sync. That way I can watch the
sample rate of the Digi box.
2. Launch Digi program, set the sample rate to 48k. Quit Digi program.
Observe sample rate displays as 48k on M-Audio interface.
3. Launch my host program. Previously saved interface selection was the
Digi Mbox. This automatically launches the Digi control program. At some
point, M-Audio sample rate display changes to 44.1!! Digi control
program still says 48k. Sound out is garbage. Quit my program.
4. Redo step 2
5. Launch my host program using the Debugger. Carefully step through the
entire initialization of the CoreAudio graph. M-Audio interface stays
locked at 48k.
6. When I get to the main run loop of my program, hit "continue" in
debugger. M-Audio stays locked at 48k. Program plays correctly!
I have run my host program with the debugger numerous times. If I allow
sections to "continue" and hit another breakpoint, the M-Audio display
will change to 44.1, seemingly in random places. This makes me think
that something in another thread (process, task, ???) is affecting the
Digi box sample rate. Unfortunately, the AUGraph does not seem to know
about it. When I re-select the device in my dialog box, first I query
both the Audio Device and the output graph node for the sample rate
(both report 48k). I stop, uninitialize, disconnect the nodes, reset
buffer sizes and sample rates on all of the elements, reconnect,
initialize, and start. I also have plenty of calls checking the
SampleRate property on the inputs and outputs of my graph nodes, and
they all display 48k, as does the UI of the Digi box control program,
even when the M-Audio control panel is showing me that the Digi box is
really outputting 44.1k.
I have run this scenario the other way, with the M-Audio box selected as
my output, and its sync set to "internal". I can use Audio MIDI Setup to
change the output sample rate of the M-Audio box to 48k (the M-Audio
control panel does not allow me to change the sample rate) and indeed
the M-Audio control panel shows the sample rate as 48k. If I then run my
program, it builds the graph with all nodes at 48k, and everything plays
correctly. Unfortunately, the Digi control program does not allow me to
see the incoming SPDIF sample rate, although it does allow me to select
external sync.
I know that I still need to add a listener proc to detect if a
(well-behaved?) audio device has changed sample rates, but I don't think
that it will help in this case, because the Digi Mbox is still telling
the host program that it is running at 48k, when it is actually running
at 44.1.
- Rick
William Stewart wrote:
On 18/05/2006, at 1:23 PM, Rick Cohen wrote:
Hi Bill,
Very interesting stuff! See below...
On 5/18/06, William Stewart <email@hidden> wrote:
On 18/05/2006, at 12:04 PM, Rick Cohen wrote:
> OK, I got rid of the error by disconnecting the nodes of the graph
> before setting the property, then reconnecting before I initialize
the
> graph. However, the sound coming out is pretty bad! Mostly noise,
> followed by a brief recognizable bit of audio.
>
> - Rick
>
> On 5/18/06, Rick Cohen <email@hidden> wrote:
>> Hi folks,
>>
>> I have a device here (Digidesign Mbox) that allows the user to set
>> their sample rate from its own control panel, which is called Digi
>> CoreAudio Manager. Never mind the fact that this is not
available as
>> a control panel property, that is another subject :(
>>
>> Anyway, I'm attempting to set the sample rate of my graph to
48000 if
>> the Mbox is already set to 48000, prior to launching my app. I'm
>> able
>> to get that sample rate with the
>> kAudioDevicePropertyNominalSampleRate
>> property on the Audio Device.
You can also get this by just looking at the output unit's { Output
Scope, El==0 } sample rate.
Indeed you can! I tried this and it works.
>> When I try to set the property on my output unit and my audio
unit, I
>> am getting an error result of kAudioUnitErr_PropertyNotWritable
>> (-10865) when I initialize the graph.
>>
>> RequireNoErr(AudioUnitSetProperty(
>>
>> mOutputUnit,
>>
>> kAudioUnitProperty_SampleRate,
>>
>> kAudioUnitScope_Global,
>>
>> 0, // AudioUnitElement inElement,
>>
>> &sampleRate,
>>
>> sizeof(Float64)
>>
>> ));
>>
>>
>> RequireNoErr(AudioUnitSetProperty(
>>
>> mTargetUnit, // AudioUnit ci,
>>
>> kAudioUnitProperty_SampleRate,
>>
>> kAudioUnitScope_Global,
>>
>> 0, // AudioUnitElement inElement,
>>
>> &sampleRate,
>>
>> sizeof(Float64)
>>
>> ));
You can't really set sample rate as a global scope... Sample rate is
a format property, and formats are applied to input and output scopes.
You also can't set the format on the output scope, element == 0, on a
device output unit - that is the device side, and you can't change
the format of the device through the output unit... You can set the
format on the input scope, element == 0 of course -> this is the
format you are providing to the output unit.
I tried setting sample rate only on the output scope on my target AU,
and on the input scope on my output AU, and unfortunately got the same
bad noise result.
Are these calls succeeding? You have to make sure the AU is not
initialised, and that its input doesn't have an existing connection (or
input callback).
As for setting a sample rate on a graph - at a set up point there is
an example of this in the PlaySequence code in the SDK.
What I found in PlaySequence contradicted what I thought that I had
read in the mailing list archive. I could only find
AudioUnitSetProperty (... SampleRate ...) for the output scope of the
synth, and that was after the nodes were connected!
No - they appear to be connected, but they aren't actually connected
until the graph is initialised - just for this reason...
Do a CAShow (myGraph) both before and after these calls, and you'll see
the progress through this...
I thought that
you could only set sample rates while the nodes were disconnected.
Anyway, I changed my code to connect the nodes, and then to only set
the sample rate for the output of my target AU, not setting the sample
rate of the input scope on the output unit at all. That also resulted
in bad noisy output.
If you can just send me the code as something I can run, I'd be happy
to look over this...
Bill
- Rick
Bill
>>
>> result = AUGraphInitialize( mGraph );
>>
>> Any suggestions would be helpful. Thanks!
>>
>> - Rick
>>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Coreaudio-api mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
40apple.com
>
> This email sent to email@hidden
--
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