J'ai un plantage au niveau de AudioUnitInitialize... Voici mon code :
Component comp;
ComponentDescription desc;
//There are several different types of Audio Units.
//Some audio units serve as Outputs, Mixers, or DSP
//units. See AUComponent.h for listing
desc.componentType = kAudioUnitType_Output;
//Every Component has a subType, which will give a clearer picture
//of what this components function will be.
desc.componentSubType = kAudioUnitSubType_HALOutput;
//all Audio Units in AUComponent.h must use
//"kAudioUnitManufacturer_Apple" as the Manufacturer
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
//Finds a component that meets the desc spec's
comp = FindNextComponent(NULL, &desc);
if (comp == NULL) exit (-1);
//gains access to the services provided by the component
err = OpenAComponent(comp, &theInputUnit);
checkError("opening audio component", err);
checkStatus(err);
UInt32 enableIO;
size=0;
//When using AudioUnitSetProperty the 4th parameter in the method
//refer to an AudioUnitElement. When using an AudioOutputUnit
//the input element will be '1' and the output element will be '0'.
enableIO = 1;
err = AudioUnitSetProperty(theInputUnit,
kAudioOutputUnitProperty_EnableIO,
kAudioUnitScope_Input,
1, // input element
&enableIO,
sizeof(enableIO));
checkError("opening audio component", err);
checkStatus(err);
enableIO = 0;
err = AudioUnitSetProperty(theInputUnit,
kAudioOutputUnitProperty_EnableIO,
kAudioUnitScope_Output,
0, //output element
&enableIO,
sizeof(enableIO));
checkError("opening audio component", err);
checkStatus(err);
/****/
size = sizeof(AudioDeviceID);
AudioDeviceID inputDevice;
err = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultInputDevice,
&size,
&inputDevice);
checkError("opening audio component", err);
checkStatus(err);
err =AudioUnitSetProperty(theInputUnit,
kAudioOutputUnitProperty_CurrentDevice,
kAudioUnitScope_Global,
0,
&inputDevice,
sizeof(inputDevice));
checkError("opening audio component", err);
checkStatus(err);
/****/
AudioStreamBasicDescription DeviceFormat;
AudioStreamBasicDescription DesiredFormat;
//Use CAStreamBasicDescriptions instead of 'naked'
//AudioStreamBasicDescription to minimize errors.
//CAStreamBasicDescription.h can be found in the CoreAudio SDK.
size = sizeof(AudioStreamBasicDescription);
//Get the input device format
err = AudioUnitGetProperty (theInputUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
1,
&DeviceFormat,
&size);
checkError("opening audio component", err);
checkStatus(err);
//set the desired format to the device's sample rate
DesiredFormat.mSampleRate = DeviceFormat.mSampleRate;
//set format to output scope
err = AudioUnitSetProperty(
theInputUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Output,
1,
&DesiredFormat,
sizeof(AudioStreamBasicDescription));
checkError("opening audio component", err);
checkStatus(err);
/****/
SInt32 *channelMap =NULL;
UInt32 numOfChannels = DesiredFormat.mChannelsPerFrame; //2 channels
UInt32 mapSize = numOfChannels *sizeof(SInt32);
channelMap = (SInt32 *)malloc(mapSize);
//for each channel of desired input, map the channel from
//the device's output channel.
for(UInt32 i=0;i<numOfChannels;i++)
{
channelMap=-1;
}
//channelMap[desiredInputChannel] = deviceOutputChannel;
channelMap[0] = 2;
channelMap[1] = 3;
err = AudioUnitSetProperty(theInputUnit,
kAudioOutputUnitProperty_ChannelMap,
kAudioUnitScope_Output,
1,
channelMap,
size);
checkError("opening audio component", err);
checkStatus(err);
free(channelMap);
/****/
err = AudioUnitInitialize(theInputUnit);
checkError("opening audio component", err);
checkStatus(err);
err = AudioOutputUnitStart(theInputUnit);
checkError("opening audio component", err);
checkStatus(err);