What you are doing is correct... The "problem" is that AUHAL is an AU
that
can be used for either/or/both input and output, so it will always
have a
device that it is using...
Another way to do this with the AUHal unit is to get the format for
the
input scope on element 1 (this is where the input side of the device
lives)
- if that returns an error, you can assume that you have no input
capability
on the device currently being used by the AUHAL unit
This is what I did before (if that is what you mean?):
CAStreamBasicDescription clientFmt;
UInt32 ioDataSize = sizeof(CAStreamBasicDescription);
XThrowIfError(AudioUnitGetProperty(
mInputUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
1, //AudioUnitElement 1 is input
(void *)&clientFmt,
&ioDataSize), "failed to get audio input format");
this returns no error regardless if the input device is available or
not
so I checked the sample rate and/or the number of channels
// returns 0 channels and/or(?) 0 Hz as sample rate if no input device
on system
XThrowIf(clientFmt.mSampleRate == 0 || clientFmt.NumberChannels() ==
0, -1, "This computer does not appear to have any audio input device.
Application will quit.");
Also seems to work allthough I'm not sure the sample rate and/or the
number of channels will always be zero?
Rolf Nilsson
Bill
On 28/9/04 12:15 PM, "Rolf Nilsson" <email@hidden> wrote:
Hi,
I'm trying out the "afrecord" example in the
/CoreAudio/Services/AudioFileTools folder.
That example uses the default audio input.
Some computers does not come with a built in audio input.
How do I detect that a system does not have an audio input?
Even if there is no audio input, the following does not return an
error:
// Get the Current Input Device ID
// this should be done only after IO has been enabled on the
AUHAL.
propSize = sizeof(mInputDevice.mID);
XThrowIfError(AudioUnitGetProperty(mInputUnit,
kAudioOutputUnitProperty_CurrentDevice,
kAudioUnitScope_Global,
0,
&mInputDevice.mID,
&propSize), "failed to get current
audio input
device ID");
So I tried kAudioDevicePropertyDeviceIsAlive:
propSize = sizeof(UInt32);
UInt32 isAlive;
XThrowIfError(AudioDeviceGetProperty(mInputDevice.mID,
0,
true/*isInput*/,
kAudioDevicePropertyDeviceIsAlive,
&propSize,
&isAlive), "failed to check if the device is
alive");
This one fails if there is no audio input. So this kind of works for
my
purpose but my feeling is that there should be a better way?
Thanks for any help
Rolf Nilsson