This article mainly introduces the composition of AudioUnit
This article is made up of your own understanding. If you have any errors, please contact our netizens for correction.
Understand the architecture of Audio Unit
Before we started, we realized audioUnit through an AudioUnit object, which is an Effect type AudioUnit of this type. This unit consists of many small scopes, scope has element, elementt has channel, stream format, and properties.
Document structure Preview
The following is the structure of the Audio Unit Component Services Reference document.
Preview)
Function by tasks)
There are three main parts: initializing or rendering audio, using audio attributes, and using audio parameters.
Initialize or render audio:
// Initialize an audio unit. Once the audio unit is created successfully, the input and output stream formats of the audio are both valid and ready for rendering. At this stage, the system creates the maximum frame memory for the audio unit.
OSStatus AudioUnitInitialize (AudioUnit inUnit // The audio you want to initialize );
// Before you change the characteristics of an audio unit, for example, to change the format or sampling rate of an input/output stream, you must cancel initialization. Call this method to release Audio object Resources. After calling this method, you can reconfigure the audio parameters and Reinitialize them.
OSStatus AudioUnitUninitialize (AudioUnit inUnit // The object you want to cancel initialization );
// Register a callback method to receive audio rendering notifications. Registered events are called when audio rendering operations (each pre-rendered bit mark is set) and audio rendering operations are completed (each rendered bit mark is set. InProc and inProcUserData are two parameters considered for authentication. To remove the rendering listener, you must pass these two values to audiounitremoverendery notify.
OSStatus AudioUnitAddRenderNotify (AudioUnit inUnit, // The rendering object of the notification you want to receive, AURenderCallback inProc, // your registered callback event void * inProcUserData // custom data that you want to pass to your call event. For example, recognition of rendering notifications .);
// Cancel the previously registered rendering call.
OSStatus AudioUnitRemoveRenderNotify (AudioUnit inUnit, AURenderCallback inProc, void * inProcUserData );
// Initialize a rendering loop for an audio unit.
OSStatus AudioUnitRender (AudioUnit inUnit, // The rendering object you want to access AudioUnitRenderActionFlags * ioActionFlags, // configure the rendering object const AudioTimeStamp * inTimeStamp, // The time stamp of the audio rendering operation. Each timestamp must contain a valid monotonic incremental sampling time. The next timestamp is inTimeStamp = inTimeStamp + inNumberFrames. If the sampling time does not increase continuously, they will be interrupted.
UInt32 inOutputBusNumber, // buffer range of the output to be rendered UInt32 inNumberFrames, // number of audio frames to be rendered AudioBufferList * ioData );
// Reset the audio rendering status.
OSStatus AudioUnitReset (AudioUnit inUnit, AudioUnitScope inScope, // scope is generally kAudioUnitScope_Global AudioUnitElement inElement // element range is generally 0 );
Use audio Properties
// Registers a callback to receive audio unit property change configurations.
OSStatus AudioUnitAddPropertyListener ( AudioUnit inUnit, AudioUnitPropertyID inID, AudioUnitPropertyListenerProc inProc, void *inProcUserData);
// Unregisters a previusly-registered property listener callback function.
OSStatus AudioUnitRemovePropertyListenerWithUserData ( AudioUnit inUnit, AudioUnitPropertyID inID, AudioUnitPropertyListenerProc inProc, void *inProcUserData);
// Gets the value of an audio unit property.
OSStatus AudioUnitGetProperty ( AudioUnit inUnit, AudioUnitPropertyID inID, AudioUnitScope inScope, AudioUnitElement inElement, void *outData, UInt32 *ioDataSize);
// Gets information about an audio unit property.
OSStatus AudioUnitGetPropertyInfo ( AudioUnit inUnit, AudioUnitPropertyID inID, AudioUnitScope inScope, AudioUnitElement inElement, UInt32 *outDataSize, Boolean *outWritable);
// Sets the value of an audio unit property.
OSStatus AudioUnitSetProperty ( AudioUnit inUnit, AudioUnitPropertyID inID, AudioUnitScope inScope, AudioUnitElement inElement, const void *inData, UInt32 inDataSize);
Use audio Parameters
// Gets the value of an audio unit parameter.
OSStatus AudioUnitGetParameter ( AudioUnit inUnit, AudioUnitParameterID inID, AudioUnitScope inScope, AudioUnitElement inElement, AudioUnitParameterValue *outValue);
// Sets the value of an audio unit parameter.
OSStatus AudioUnitSetParameter ( AudioUnit inUnit, AudioUnitParameterID inID, AudioUnitScope inScope, AudioUnitElement inElement, AudioUnitParameterValue inValue, UInt32 inBufferOffsetInFrames);
// Schedules changes to the value of an audio unit parameter.
OSStatus AudioUnitScheduleParameters ( AudioUnit inUnit, const AudioUnitParameterEvent *inParameterEvent, UInt32 inNumParamEvents);
Function task callback Data Type
Typedef AudioComponentInstance AudioUnit; // AudioUnit is of the AudioComponentInstance type.
// The types are as follows:
Enum {
kAudioUnitType_Output = 'auou', kAudioUnitType_MusicDevice = 'aumu', kAudioUnitType_MusicEffect = 'aumf', kAudioUnitType_FormatConverter = 'aufc', kAudioUnitType_Effect = 'aufx', kAudioUnitType_Mixer = 'aumx', kAudioUnitType_Panner = 'aupn', kAudioUnitType_OfflineEffect = 'auol', kAudioUnitType_Generator = 'augn',};
Converter Audio Unit Subtypes // Conversion Type
enum { kAudioUnitSubType_AUConverter = 'conv', kAudioUnitSubType_NewTimePitch = 'nutp', kAudioUnitSubType_TimePitch = 'tmpt', kAudioUnitSubType_DeferredRenderer = 'defr', kAudioUnitSubType_Splitter = 'splt', kAudioUnitSubType_Merger = 'merg', kAudioUnitSubType_Varispeed = 'vari', kAudioUnitSubType_AUiPodTime = 'iptm', kAudioUnitSubType_AUiPodTimeOther = 'ipto'};
Effect Audio Unit Subtypes // Effect type.
Effect (digital signal processing) audio unit subtypes for audio units provided by Apple.
enum { kAudioUnitSubType_PeakLimiter = 'lmtr', kAudioUnitSubType_DynamicsProcessor = 'dcmp', kAudioUnitSubType_Reverb2 = 'rvb2', kAudioUnitSubType_LowPassFilter = 'lpas', kAudioUnitSubType_HighPassFilter = 'hpas', kAudioUnitSubType_BandPassFilter = 'bpas', kAudioUnitSubType_HighShelfFilter = 'hshf', kAudioUnitSubType_LowShelfFilter = 'lshf', kAudioUnitSubType_ParametricEQ = 'pmeq', kAudioUnitSubType_Delay = 'dely', kAudioUnitSubType_Distortion = 'dist', kAudioUnitSubType_AUiPodEQ = 'ipeq', kAudioUnitSubType_NBandEQ = 'nbeq'};
Mixer Audio Unit Subtypes // Mixed Type
Audio mixing audio unit subtypes for audio units provided by Apple.
enum { kAudioUnitSubType_MultiChannelMixer = 'mcmx', kAudioUnitSubType_MatrixMixer = 'mxmx', kAudioUnitSubType_AU3DMixerEmbedded = '3dem',};
Input/Output Audio Unit Subtypes // Input/Output type
enum { kAudioUnitSubType_GenericOutput = 'genr', kAudioUnitSubType_RemoteIO = 'rioc', kAudioUnitSubType_VoiceProcessingIO = 'vpio'};
Music Instrument Audio Unit Subtypes
Audio units that can be played as musical instruments via MIDI control.
enum { kAudioUnitSubType_Sampler = 'samp'};
Typedef UInt32 AudioUnitScope; // The AudioUnitScope type is UInt32
enum { kAudioUnitScope_Global = 0, kAudioUnitScope_Input = 1, kAudioUnitScope_Output = 2, kAudioUnitScope_Group = 3, kAudioUnitScope_Part = 4, kAudioUnitScope_Note = 5};
Typedef UInt32 AudioUnitElement; // The AudioUnitElement type is UInt32
AudioUnitElement is set based on the Scope value. When the scope is input and output, it is determined based on the hardware's digital signal buffer. Global scope is always 0.
Core Audio SDK uses Buffer to replace Channel
Multiple buffers can use bufferlist
Struct AudioUnitParameter {AudioUnit mAudioUnit; AudioUnitParameterID mParameterID; AudioUnitScope msement; AudioUnitElement mElement;}; typedef struct AudioUnitParameter; // Structure Type
There are Setter and Getter methods.
AudioUnitParameterID
typedef UInt32 AudioUnitParameterID;
AudioUnitParameterValue
typedef Float32 AudioUnitParameterValue;
Defines an attribute or behavior for an audio unit with a key-value.
struct AudioUnitProperty { AudioUnit mAudioUnit; AudioUnitPropertyID mPropertyID; AudioUnitScope mScope; AudioUnitElement mElement;};typedef struct AudioUnitProperty AudioUnitProperty;
There are Setter and Getter methods.
AudioUnitPropertyID
typedef UInt32 AudioUnitPropertyID;
A scheduled change to an audio unit parameter's value.
struct AudioUnitParameterEvent { AudioUnitScope scope; AudioUnitElement element; AudioUnitParameterID parameter; AUParameterEventType eventType; union { struct { SInt32 startBufferOffset; UInt32 durationInFrames; AudioUnitParameterValue startValue; AudioUnitParameterValue endValue; } ramp; struct { UInt32 bufferOffset; AudioUnitParameterValue value; } immediate; } eventValues;};typedef struct AudioUnitParameterEvent AudioUnitParameterEvent;
Audio Unit Parameter Event Types
Audio unit parameter event types.
enum { kParameterEvent_Immediate = 1, kParameterEvent_Ramped = 2};typedef UInt32 AUParameterEventType;
Configure the audio unit rendering tag
enum { kAudioUnitRenderAction_PreRender = (1 << 2), kAudioUnitRenderAction_PostRender = (1 << 3), kAudioUnitRenderAction_OutputIsSilence = (1 << 4), kAudioOfflineUnitRenderAction_Preflight = (1 << 5), kAudioOfflineUnitRenderAction_Render = (1 << 6), kAudioOfflineUnitRenderAction_Complete = (1 << 7), kAudioUnitRenderAction_PostRenderError = (1 << 8), kAudioUnitRenderAction_DoNotCheckRenderArgs = (1 << 9)};typedef UInt32 AudioUnitRenderActionFlags;
The corresponding audio unit component generates the audio unit composition method.
enum { kAudioUnitRange = 0x0000, kAudioUnitInitializeSelect = 0x0001, kAudioUnitUninitializeSelect = 0x0002, kAudioUnitGetPropertyInfoSelect = 0x0003, kAudioUnitGetPropertySelect = 0x0004, kAudioUnitSetPropertySelect = 0x0005, kAudioUnitAddPropertyListenerSelect = 0x000A, kAudioUnitRemovePropertyListenerSelect = 0x000B, kAudioUnitRemovePropertyListenerWithUserDataSelect = 0x0012, kAudioUnitAddRenderNotifySelect = 0x000F, kAudioUnitRemoveRenderNotifySelect = 0x0010, kAudioUnitGetParameterSelect = 0x0006, kAudioUnitSetParameterSelect = 0x0007, kAudioUnitScheduleParametersSelect = 0x0011, kAudioUnitRenderSelect = 0x000E, kAudioUnitResetSelect = 0x0009, kAudioUnitComplexRenderSelect = 0x0013, kAudioUnitProcessSelect = 0x0014, kAudioUnitProcessMultipleSelect = 0x0015};
Constant