Re: Swift set AudioUnit current device failure
Re: Swift set AudioUnit current device failure
- Subject: Re: Swift set AudioUnit current device failure
- From: Bill Farmer <email@hidden>
- Date: Sun, 18 Feb 2018 09:42:36 +0000
I don't think it's anything to do with that because if I read the input
device out of the AudioUnit and then write it back using the same code
there is no error. I know exactly what the error is because I check
status after each API call and the error code is looked up in a function
I didn't show for brevity. The error is
"AudioUnitErr_InvalidPropertyValue" which is quite specific. The code
for reading the input device from the AudioUnit so it can be written
back for testing is...
// Get device
status =
AudioObjectGetPropertyData(UInt32(kAudioObjectSystemObject),
&inputDeviceAOPA,
0, nil, &size, &id)
if (status != noErr)
{
// AudioObjectGetPropertyData
NSLog("Error in AudioObjectGetPropertyData: " +
"kAudioHardwarePropertyDefaultInputDevice %d", status)
return status
}
NSLog("System input device %d", id!)
After reading the Apple Swift docs I am not much wiser on what exactly
putting a '!' or a '?' after a variable definition or reference is
supposed to achieve. I wrote this code as a direct translation of the C
version without spurious adornments and then added them as advised by
the compiler error messages. The C version of this code fragment is...
// Tuner.h
typedef struct
{
AudioUnit output;
AudioDeviceID id;
bool downsample;
bool filter;
int divisor;
int frames;
float *buffer;
float sample;
float reference;
} Audio;
// Tuner.c
UInt32 size;
AudioDeviceID id;
size = sizeof(id);
// Get the default input device
status =
AudioHardwareGetProperty(kAudioHardwarePropertyDefaultInputDevice,
&size, &id);
if (status != noErr)
{
DisplayAlert(CFSTR("AudioHardwareGetProperty"),
CFSTR("Can't get the default input device"),
status);
return status;
}
// Set the audio unit device
status = AudioUnitSetProperty(audio.output,
kAudioOutputUnitProperty_CurrentDevice,
kAudioUnitScope_Global, 0, &id, sizeof(id));
if (status != noErr)
{
DisplayAlert(CFSTR("AudioUnitSetProperty"),
CFSTR("Can't set output audio unit current device"),
status);
return status;
}
Much simpler and it works.
_______________________________________________
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