Determine the version of an Audio Unit

Q: How do I determine the which version of an Audio Unit I am using?

A: Core Audio uses the Component Manager to make Audio Units available as a system-wide resource. After obtaining a valid instance of an Audio Unit, you can use the method GetComponentVersion to get the version.

This can be useful when an Audio Unit has two separate versions with different features; you would want to determine which version is installed before using the Audio Unit.

The code below determines if a suitable version of Apple's 3Dmixer Audio Unit is installed on a users system. Because the different versions of the 3Dmixer behave differently, you would want to determine which version resides on the user's system.

Listing 1: Getting the 3D Mixer Version.

#define kPreferredMixerVersion      0x20000
#define kMinimumMixerVersion        0x10300
long mixerVersion = kMinimumMixerVersion;
//The Version format is 0xMMMMmmbb
//The digits M/m/b are stored in BCD (Binary Coded Decimal) format
//where each digit has a range of 0 - 9 (normal binary digits have a range of 0 - 15)

if(Is3DMixerVersionValid(&mixerVersion)){
  // yes, we can work with it.  May want to examine the version number further if a
  // specific feature is desired.

}

bool Is3DMixerVersionValid(long *versionNumber)
{
    ComponentDescription mixerCD = { kAudioUnitType_Mixer,          // type
    kAudioUnitSubType_3DMixer,     // subType
    kAudioUnitManufacturer_Apple,   // manufacturer
    0,                              // flags
    0 };                            // flags mask

  // initially false
    bool versionValid = false;
    long version = 0;

    Component mixerC= FindNextComponent(0, &mixerCD);
    require(NULL != mixerC, bail);

  require(versionNumber != nil, bail);

    version = GetComponentVersion((ComponentInstance)mixerC);

    // if the returned version is less than 0x20000 (it may even be 0x10300
    // which is really old!) it's not the version of the 3DMixer we want to use
    // so we're not going to do anything and just return false

    // if however the version is 0x20000 or greater, then it is the version
    // of 3DMixer mixer we want to use, so we set outPreferred3DMixerExists to true
    if (version >= *versionNumber){
    versionValid = true;
    *versionNumber = version;  // validated this pointer on entry

  }

bail:
    return versionValid;
}

Note: For more information on Component's and ComponentDescriptions, please refer to the Component Manager Reference.

Document Revision History

DateNotes
2005-03-07Changed code of Is3DMixerVersionValid(). Added information about Version format (BCD).
2005-02-03Determine the version of an Audio Unit

Posted: 2005-03-07


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.