Re: Setting Input Sample Format and Rate
Re: Setting Input Sample Format and Rate
- Subject: Re: Setting Input Sample Format and Rate
- From: William Stewart <email@hidden>
- Date: Wed, 13 Sep 2006 11:00:53 -0700
On 13/09/2006, at 10:35 AM, Doug Zwick wrote:
I'm converting some old Sound Manager input code to use CoreAudio,
using TN 2091 as a guide, and have had some odd issues. TN 2091
suggests that AUHAL will automatically convert the data format as
long as it is linear PCM. I have tried to set the input format to
16-bit signed integer, non-interleaved, packed, native endian, and
the set property call (kAudioUnitProperty_StreamFormat) succeeds
but calls to AudioUnitRender return -10863
(kAudioUnitErr_CannotDoInCurrentContext).
Have you started the AUHAL unit? If you haven't, its got no data to
give you.
Are you asking it for the same number of sample frames in the render
call as it told you it had in the callback? It doesn't provide more
or less data than what it has.
These are the two circumstances where this error arises.
Bill
Converting between Float32 and SInt16 is no big deal, but I was
surprised that it didn't fail until the call to AudioUnitRender. I
also found that the set property call is mandatory, attempting to
get the default behaviour by simply not setting the property also
doesn't seem to work -- I get back -50 (paramErr) from
AudioUnitRender on all devices except built-in audio (dual G4 MDD).
I have also tried changing the sample rate when setting the stream
format, which does not work (which is expected, as TN 2091 states
that the requested rate must match the device rate), but again the
set property call succeeds, and failure doesn't occur until the
AudioUnitRender call (-10863 return code again). I would have
expected the set property call to fail if the device is unable to
honour the request. Am I missing something here? Is this the right
way to go about trying to do this?
I also tried changing the nominal sample rate of the input device,
as per Q&A 1196. However, when I start with the device set to a
different rate than what I am requesting, the set property
succeeds, but AudioUnitRender returns -10863 (the USB device can
support the requested rate of 8000 Hz). Audio MIDI Setup reports
that the device has changed its sample rate. Retrying my code then
succeeds. If I use Audio MIDI Setup to change the sample rate to
anything other than what I'm requesting, I get -10863 from
AudioUnitRender again. Changing the nominal sample rate for the
input device also seems to be a global, persistent change. What I
want to do is simply open the device "just this once" at my
requested rate, without permanently changing the device settings.
Is there a more appropriate way to do this?
The end goal is to get 8000 Hz, 16-bit integer, mono audio samples
into a cross-platform Java teleconferencing app (via a native
library). The Java code is able to resample if I cannot produce
8000 Hz data, but I'd prefer to do the resampling in CodeAudio,
rather than in Java, for performance reasons.
Here is the format setting code:
err = AudioUnitGetProperty (unit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input, 1,
&streamFormat, &fmtLen);
/* this doesn't seem to work, even keeping the current sample rate...
streamFormat.mFormatID = kAudioFormatLinearPCM;
streamFormat.mFormatFlags =
kLinearPCMFormatFlagIsSignedInteger |
kAudioFormatFlagsNativeEndian |
kLinearPCMFormatFlagIsPacked |
kAudioFormatFlagIsNonInterleaved;
streamFormat.mBytesPerPacket = bytesPerSample;
streamFormat.mFramesPerPacket = 1;
streamFormat.mBytesPerFrame = bytesPerSample;
streamFormat.mChannelsPerFrame = nChannels;
streamFormat.mBitsPerChannel = bitsPerSample;
*/
err = AudioUnitSetProperty (unit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Output, 1,
&streamFormat, sizeof
(streamFormat));
_______________________________________________
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
--
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