Skip to content

Instantly share code, notes, and snippets.

@Ridwy
Created August 23, 2012 16:11
Show Gist options
  • Save Ridwy/3438128 to your computer and use it in GitHub Desktop.
Save Ridwy/3438128 to your computer and use it in GitHub Desktop.
AudioUnitCreate(), AudioUnitDispose()
#include <AudioToolbox/AudioToolbox.h>
/*
AudioUnit unit = AudioUnitCreate(kAudioUnitType_Output, kAudioUnitSubType_RemoteIO);
// set properties
AudioUnitInitialize(unit);
AudioOutputUnitStart(unit);
// play
AudioOutputUnitStop(unit);
AudioUnitUninitialize(unit);
AudioUnitDispose(unit);
*/
AudioUnit AudioUnitCreate(OSType type, OSType subType)
{
AudioComponentDescription desc;
desc.componentType = type;
desc.componentSubType = subType;
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
AudioComponent comp = AudioComponentFindNext(NULL, &desc);
if (comp == NULL) return NULL;
AudioUnit unit = NULL;
OSStatus status = AudioComponentInstanceNew(comp, &unit);
if (status != noErr) return NULL;
return unit;
}
OSStatus AudioUnitDispose(AudioUnit unit)
{
return AudioComponentInstanceDispose(unit);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment