So, you have a signal flow that is input->mixer->output (where
input and output are the same node).
You should be able to hear the audio as with this connection you
are passing input data to an output. Is this the case?
- this will also confirm that you've set up the AUHAL input unit
correctly.
You also have to enable metering (the reason being that it adds
cost, so we have it disabled by default). The property is:
kAudioUnitProperty_MeteringMode
and there are some comments on this in AudioUnitProperties.h
Bill
No. I cannot hear any audio being played through. For my testing,
I'm choosing my Edirol UA25 as the device. I've connected some
headphones to it's monitor, to hear any output sent back.
I'll try to explain exactly what I'm doing code wise, in the hope
that I, or someone reading this, uncovers a silly mistake on my
part.
Note: The part I'm unsure about is settings the formats. So far,
I've taken the code from http://developer.apple.com/technotes/
tn2002/tn2091.html and assumed that this is correct. It talks
about cases whereby you are either outputting data, or obtaining
data, but not both. Since I'm feeding the input, to the ouput
(via a mixer), I'm assuming I'm doing both (so my stream format
setup may be incomplete, dunno). I could be entirely wrong there.
1) Start a new graph
NewAUGraph(&auGraph);
2) Create the AUHAL
ComponentDescription desc;
desc.componentType = kAudioUnitType_Output;
desc.componentSubType = kAudioUnitSubType_HALOutput;
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
AUGraphNewNode(auGraph, &desc, 0, NULL, &inputNode);
3) Create the mixer
ComponentDescription mixer;
mixer.componentType = kAudioUnitType_Mixer;
mixer.componentSubType = kAudioUnitSubType_MatrixMixer;
mixer.componentManufacturer = kAudioUnitManufacturer_Apple;
mixer.componentFlags = 0;
mixer.componentFlagsMask = 0;
AUGraphNewNode(auGraph, &mixer, 0, NULL, &mixerNode);
4) Connect the output of element 1 (the input bus) to the mixer,
and also the output of the mixer to the input scope of element 0
(the output bus)
AUGraphConnectNodeInput(auGraph, inputNode, 1, mixerNode, 0);
AUGraphConnectNodeInput(auGraph, mixerNode, 0, inputNode, 0);
5) Open the AU Graph
AUGraphOpen(auGraph);
6) Get references to the AU Units. Only two required (the input/
output unit, and the mixer itself)
AUGraphGetNodeInfo(auGraph, inputNode, NULL, NULL, NULL,
&inputUnit);
AUGraphGetNodeInfo(auGraph, mixerNode, NULL, NULL, NULL,
&mixerUnit);
7) Enable IO on the input scope of the AUHAL, and disable the
output scope of the AUHAL
UInt32 enableIO = 1;
AudioUnitSetProperty(inputUnit,
kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1,
&enableIO, sizeof(enableIO));
enableIO = 0;
AudioUnitSetProperty(inputUnit,
kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output, 0,
&enableIO, sizeof(enableIO));
8) Enable metering, on the mixer
UInt32 meteringMode = 1;
AudioUnitSetProperty(mixerUnit, kAudioUnitProperty_MeteringMode,
kAudioUnitScope_Global, 0, &meteringMode, sizeof(meteringMode) );
9) Setup the input device, on the AUHAL (element 1, the source)
UInt32 size;
size = sizeof(AudioDeviceID);
AudioUnitSetProperty(inputUnit,
kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global,
0, &deviceId, sizeof(deviceId));
10) Set the stream format of the input device, to be the same as
the output (using code from http://developer.apple.com/technotes/
tn2002/tn2091.html)
CAStreamBasicDescription DeviceFormat;
CAStreamBasicDescription DesiredFormat;
size = sizeof(CAStreamBasicDescription);
//Get the input device format
AudioUnitGetProperty (inputUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
1,
&DeviceFormat,
&size);
DesiredFormat.mSampleRate = DeviceFormat.mSampleRate;
//set format to output scope
AudioUnitSetProperty(
inputUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Output,
1,
&DesiredFormat,
sizeof(CAStreamBasicDescription));
11) Initialize and start the graph
AUGraphInitialize(auGraph);
AUGraphStart(auGraph);