Hello,
Is it possible to route iPhone audio to the bluetooth speaker? I want to process audio from microphone and send result to bluetooth A2DP speaker. I use following code:
AudioComponentDescription componentDescription = {
.componentType = kAudioUnitType_Output,
.componentSubType = kAudioUnitSubType_RemoteIO,
.componentManufacturer = kAudioUnitManufacturer_Apple,
.componentFlags = 0,
.componentFlagsMask = 0
};
AudioComponent component = AudioComponentFindNext(NULL, &componentDescription);
checkResult(AudioComponentInstanceNew(component, &_audioUnit), "AudioComponentInstanceNew");
UInt32 oneFlag = 1;
AudioUnitElement bus0 = 0;
checkResult(AudioUnitSetProperty(_audioUnit,
kAudioOutputUnitProperty_EnableIO,
kAudioUnitScope_Output,
bus0,
&oneFlag,
sizeof(oneFlag)), "AudioUnitSetProperty");
AudioUnitElement bus1 = 1;
checkResult(AudioUnitSetProperty(_audioUnit,
kAudioOutputUnitProperty_EnableIO,
kAudioUnitScope_Input,
bus1,
&oneFlag,
sizeof(oneFlag)), "AudioUnitSetProperty");
AudioStreamBasicDescription streamDescription = {
.mSampleRate = 44100,
.mFormatID = kAudioFormatLinearPCM,
.mFormatFlags = kAudioFormatFlagIsSignedInteger,
.mChannelsPerFrame = 2,
.mBytesPerPacket = 2 * sizeof(SInt16),
.mFramesPerPacket = 1,
.mBytesPerFrame = 2 * sizeof(SInt16),
.mBitsPerChannel = 8 * sizeof(SInt16)
};
checkResult(AudioUnitSetProperty(_audioUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
bus0,
&streamDescription,
sizeof(streamDescription)), "AudioUnitSetProperty");
checkResult(AudioUnitSetProperty(_audioUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Output,
bus1,
&streamDescription,
sizeof(streamDescription)), "AudioUnitSetProperty");
AURenderCallbackStruct renderCallback {
.inputProc = callback,
.inputProcRefCon = this
};
checkResult(AudioUnitSetProperty(_audioUnit,
kAudioUnitProperty_SetRenderCallback,
kAudioUnitScope_Global,
bus0,
&renderCallback,
sizeof(renderCallback)), "AudioUnitSetProperty");
checkResult(AudioUnitInitialize(_audioUnit), "AudioUnitInitialize");
But this send audio to headphones or default speaker.