Re: HALOutputUnit (Pt 1)
Re: HALOutputUnit (Pt 1)
- Subject: Re: HALOutputUnit (Pt 1)
- From: Bob Stuller <email@hidden>
- Date: Tue, 3 Feb 2004 13:47:04 -0500
Bill, Greetings!
At 4:05 PM -0800 1/9/04, William Stewart wrote:
Formats.
The AUHAL units will always flatten any of the streams/interleaved
channels of a device into a single de-interleaved stream (on
either/both input and output sides). It uses an AudioConverter to do
this transformation. The AUHAL units will also use channel maps to
determine which channels to present to the user if there is not a
one-to-one correspondance between input and output formats.
For Device Output (AUHAL's Element 0), the device format is always
expressed in the output scope. This will always represents the total
number of channels the device is currently set too. It is always *not*
writable - if the format of the device needs to be changed, the user
will need to set that explicitly on the device. The sample rate of that
format is the current sample rate of the device.
For Device Input (AUHAL's Element 1), the device format is always
expressed in the input scope and is not writable as described above.
The User can set the format it will either provide (for output) or
desires (for input). Thus, for doing device output, the client sets the
format on the AUHAL's Input Element == 0. For device input, the client
sets the format on AUHAL's Output Element == 1.
AUHAL determines what kind of AudioConverter is required by comparing
the flattened device format and the client's format. Resetting either a
device format or a client format will generally be a disruptive event,
requiring a new audio converter to be established.
A client can set *any* format provided the format has a simple
conversion process. Typically, this means that a client can specify
*any* variant of the PCM formats (for eg, a client could have the
AUHAL's converters do both a sample rate conversion and/or a float-int
conversion as desired).
Okay, I'm stuck. I'm trying to use the HALOutputUnit to pull 16-bit
audio at 16 kHz and,
when I get to the point of trying to set these settings, I get a
kAudioUnitErr_PropertyNotWritable error. Here is sketch of the code
that I am using.
ComponentDescription cd =
{kAudioUnitType_Output, kAudioUnitSubType_HALOutput,
kAudioUnitManufacturer_Apple, 0, 0};
Component HALOutput = FindNextComponent(nil, &cd);
OSErr err = OpenAComponent(HALOutput, &mHALOutInstance);
OSStatus status = AudioUnitInitialize(mHALOutInstance);
AudioInputUberDescription inputDesc;
mUberDescriptions->FetchItemAt(1, &inputDesc);
status = AudioUnitSetProperty(mHALOutInstance,
kAudioOutputUnitProperty_CurrentDevice,
kAudioUnitScope_Global,
0,
&inputDesc.mDeviceID,
sizeof(AudioDeviceID));
UInt32 data = 0;
status = AudioUnitSetProperty(mHALOutInstance,
kAudioOutputUnitProperty_EnableIO,
kAudioUnitScope_Output,
0,
&data,
sizeof(data));
data = 1;
status = AudioUnitSetProperty(mHALOutInstance,
kAudioOutputUnitProperty_EnableIO,
kAudioUnitScope_Input,
1,
&data,
sizeof(data));
Boolean writable = false;
status = AudioUnitGetPropertyInfo(mHALOutInstance,
kAudioOutputUnitProperty_ChannelMap,
kAudioUnitScope_Input,
1, &propsize, &writable);
long nChannels = propsize / sizeof(SInt32);
long* channelMapPtr = (long*)malloc(propsize);
channelMapPtr[0] = 0;
for (long i = 1; i < nChannels; i++)
{
channelMapPtr[i] = -1;
}
status = AudioUnitSetProperty(mHALOutInstance,
kAudioOutputUnitProperty_ChannelMap,
kAudioUnitScope_Input,
1, channelMapPtr, propsize);
AudioStreamBasicDescription format;
memset(&format, 0, sizeof(AudioStreamBasicDescription));
format.mSampleRate = 16000.0;
format.mBytesPerFrame = 2;
format.mFramesPerPacket = 1;
format.mBytesPerPacket = 2;
format.mChannelsPerFrame = 1;
format.mBitsPerChannel = 16;
format.mFormatID = kAudioFormatLinearPCM;
format.mFormatFlags = kLinearPCMFormatFlagIsBigEndian
// | kLinearPCMFormatFlagIsSignedInteger
| kLinearPCMFormatFlagIsPacked
| kLinearPCMFormatFlagIsNonInterleaved;
status = AudioUnitSetProperty(mHALOutInstance,
kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input,
1, &format, sizeof(format));
This is the AudioUnitSetProperty call that returns the NotWritable
error. Where did I go wrong here?
Any help that you or anyone else on the Core Audio list could provide
would be appreciated.
Peace,
Bob
--
As a rule, one should avoid generalizations.
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.