Re: Setting Input Sample Format and Rate
Re: Setting Input Sample Format and Rate
- Subject: Re: Setting Input Sample Format and Rate
- From: Doug Wyatt <email@hidden>
- Date: Thu, 14 Sep 2006 12:48:35 -0700
On Sep 14, 2006, at 10:38 , Doug Zwick wrote:
I think you missed the gist of my question: I'm not looking for
rate conversion here, I'm looking to set the input device to record
at a device-supported sample rate. I am testing with two audio
devices: a USB mic (supports input at 8000, 11025, 22050, 44100 and
48000 Hz according to Audio MIDI Setup and HALLab), and an iSight
(48000 Hz only). I would expect that trying to set a sample rate of
8000 Hz in the set property call for SampleFormat would work
properly for the USB mic (as the device supports that rate), but
return an error code for the iSight. I always get a zero error code
back from the set property call, and it fails in both cases when
AudioUnitRender is called. Is setting the mSampleRate field of the
kAudioUnitProperty_StreamFormat property the correct way to select
a supported device sample rate that is not set as the current
nominal sample rate?
No.
If you set it on the client side of AUHAL's converter (input scope/
element 0 or output scope/element 1) you're changing the format that
you're sending/receiving to AUHAL.
If you set it on the device side (input scope/element 1 or output
scope/element 0), you get an error.
To change a device's sample rate, use the HAL APIs.
If I change the nominal rate of the USB mic to 8000 Hz via Audio
MIDI Setup, setting a rate of 8000 Hz via the SampleFormat property
for the USB mic works as I expect. If setting the mSampleRate field
of the StreamFormat property works as I thought it did, it would
set the device to record at the specified rate for device-supported
sample rates, and return an error code for unsupported sample
rates. Since this doesn't happen, I must be missing something. Is
this the proper way to select an alternate, supported sample rate?
Perhaps it is the meaning of "nominal sample rate" I don't
understand, I assume it to mean the preferred sample rate. Is it
mandatory to set the nominal sample rate for the device before
trying to set the format of the audio unit (I'm trying to avoid
making any persistent changes to the audio device state that I'd
have to set back later)?
The simplest thing (while you get things up and running) to do is not
touch the device sample rate, and do that in Audio MIDI Setup. Make
sure your client sample rate matches the hardware sample rate -- if
you're doing input, that means fetching element 1's stream format in
the input scope, changing it to a different PCM format (if desired)
then setting element 1's stream format in the output scope.
I will want to look at rate conversion at some point. My
understanding is that this must be done using an AUGraph with a
converter unit connected to the AUHAL.
Not necessarily; you might just use an AudioConverter without a graph.
You definitely cannot do rate conversion as part of getting input
from AUHAL. That's the most common cause of those "cannot do in
current context" errors. It's caused by there not being any extra
buffering in AUHAL. Due to the rate conversion, during each I/O
cycle, not all of the incoming samples can be consumed.
One way to handle this is to store your incoming samples in a ring
buffer, then on a separate thread, run an AudioConverter to pull them
out of the ring buffer and convert them to the desired sample rate.
Doug
--
Doug Wyatt
Core Audio, Apple
_______________________________________________
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