Search code examples
iosios7core-audioaudiounit

is there a way to programmatically get all the parameters of an Audio Unit in iOS?


AUParamInfo() doesn't seem to exist in the iOS7 frameworks (CoreAudio, AudioUnit, AudioToolbox). I'm wondering what would be the way to get all parameters for a unit. That is, without knowing what type or subtype of unit it is, since if not the answer would be to look up in the Audio Unit Parameters Reference.


Solution

  • Greg's answer is right in the sense that kAudioUnitProperty_ParameterList is the right property ID to query to eventually get all parameters of a unit. However, the way to get all parameters is a bit more involved:

    1. Use AudioUnitGetPropertyInfo to see if the property is available and if it is, get back its data size (data size for the whole info which might be a collection, not for a single element of whatever type the property is, mind you).
    2. Use AudioUnitGetProperty proper to get the property back. Also, at this point, if the property you got back is a collection of elements as opposed to a single one, you'll have to call AudioUnitGetProperty once for each element. Specifically, you'll call it dataSize / sizeof(TypeToHoldSingleInstanceOfYourProperty) times.

      //  Get number of parameters in this unit (size in bytes really):
      UInt32 parameterListSize = 0;
      AudioUnitGetPropertyInfo(_audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global, 0, &parameterListSize, NULL);
      
      //  Get ids for the parameters:
      AudioUnitParameterID *parameterIDs = malloc(parameterListSize);
      AudioUnitGetProperty(_audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global, 0, parameterIDs, &parameterListSize);
      
      AudioUnitParameterInfo parameterInfo_t;
      UInt32 parameterInfoSize = sizeof(AudioUnitParameterInfo);
      UInt32 parametersCount = parameterListSize / sizeof(AudioUnitParameterID);
      for(UInt32 pIndex = 0; pIndex < parametersCount; pIndex++){
          AudioUnitGetProperty(_audioUnit, kAudioUnitProperty_ParameterInfo, kAudioUnitScope_Global, parameterIDs[pIndex], &parameterInfo_t, &parameterInfoSize);
          // do whatever you want with each parameter...
      }