I'm developing an application for iOS, that uses the RemoteIO audio unit to record audio from the microphone, process it and output to the speakers (headset). Currently I use a single channel (mono) for input and output.
What I'd like to do, is to allow the users to choose an output speaker: left-only, right-only or both. My current code supports only the "both" setting - the same sound is coming from both speakers.
Here's how I set the stream format (kAudioUnitProperty_StreamFormat) of the input and output bus:
AudioStreamBasicDescription ASBD = {0};
size_t bytesPerSample = sizeof(SInt16);
ASBD.mFormatID = kAudioFormatLinearPCM;
ASBD.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
ASBD.mSampleRate = 44100;
ASBD.mFramesPerPacket = 1;
ASBD.mBytesPerFrame = bytesPerSample;
ASBD.mBytesPerPacket = bytesPerSample;
ASBD.mBitsPerChannel = 8 * bytesPerSample;
ASBD.mChannelsPerFrame = 1;
And my render callback (kAudioUnitProperty_SetRenderCallback) looks roughly like this:
AudioUnitRender(remoteIO, ioActionFlags, inTimeStamp, inputBus, inNumberFrames, ioData);
SInt16 *renderBuffer = ioData->mBuffers[0].mData;
// Process renderBuffer and modify the samples
What would be the simplest way to implement the left-only/right-only settings? I don't mind changing a device setting if there's anything relevant.