Skip to content

Instantly share code, notes, and snippets.

@admsyn
Created September 26, 2012 21:53
Show Gist options
  • Save admsyn/3790864 to your computer and use it in GitHub Desktop.
Save admsyn/3790864 to your computer and use it in GitHub Desktop.
Firing up a RemoteIO
UInt32 propSize = sizeof(UInt32);
UInt32 inputAvailable;
AudioSessionGetProperty(kAudioSessionProperty_AudioInputAvailable,&propSize,&inputAvailable);
if(!inputAvailable)
{
std::cout << "No input available!" << std::endl;
return false;
}
Float64 sampleRate;
propSize = sizeof(sampleRate);
AudioSessionGetProperty(kAudioSessionProperty_CurrentHardwareSampleRate, &propSize, &sampleRate);
AudioUnitUninitialize(*_unit);
AudioUnitElement inputBus = 1;
AudioUnitElement outputBus = 0;
UInt32 on = 1;
UInt32 off = 0;
AudioUnitSetProperty(*_unit,kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output, outputBus, &off, sizeof(off));
AudioUnitSetProperty(*_unit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, inputBus, &on, sizeof(on));
AudioStreamBasicDescription asbd = {0};
asbd.mSampleRate = sampleRate;
asbd.mFormatID = kAudioFormatLinearPCM;
asbd.mFormatFlags = kAudioFormatFlagsAudioUnitCanonical;
asbd.mFramesPerPacket = 1;
asbd.mBitsPerChannel = 8 * sizeof(AudioUnitSampleType);
asbd.mBytesPerPacket = asbd.mBytesPerFrame = sizeof(AudioUnitSampleType);
asbd.mChannelsPerFrame = 2;
AudioUnitSetProperty(*_unit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &asbd, sizeof(asbd));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment