Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Every audio module has an associated instance data structure that holds the variables – state and parameters – needed by the module. In this example, there are 4 variables described in the module m-file:

Code Block
add_variable(M, 'gain', 'float', 0, 'parameter', 'Target gain');

...


M.gain.range=[-10 10];

...


M.gain.units='linear';

...


 
add_variable(M, 'smoothingTime', 'float', 10, 'parameter', 'Time constant of the smoothing process');

...


M.smoothingTime.range=[0 1000];

...


M.smoothingTime.units='msec';

...


 
add_variable(M, 'currentGain', 'float', M.gain, 'state', 'Instantaneous gain applied by the module.  This is also the starting gain of the module.', 1);

...


M.currentGain.range=M.gain.range;

...


M.currentGain.units='linear';

...


 
add_variable(M, 'smoothingCoeff', 'float', NaN, 'derived', 'Smoothing coefficient', 1);

The type definition for the instance data structure is contained in the file ModScalerSmoothedExample.h and is automatically generated by Audio Weaver:

Code Block
typedef struct _awe_modScalerSmoothedExampleInstance

...


{

...


  ModuleInstanceDescriptor instance;

...

float gain; // Target gain

float smoothingTime; // Time constant of the ...

float currentGain; // Instantaneous gain applied ...

float smoothingCoeff; // Smoothing coefficient

...


  float     	gain;                // Target gain
  float     	smoothingTime;       // Time constant of the ...
  float     	currentGain;         // Instantaneous gain applied ...
  float     	smoothingCoeff;      // Smoothing coefficient
} awe_modScalerSmoothedExampleInstance;

The instance structure begins with a common substructure of type ModuleInstanceDescriptor. This substructure points to the module's input and output wires, points to the real-time function currently used by the module (Processing, Bypassed, Muted, etc.), and points to the class instance structure.

...

The header file also contains a few other items. First, there is a bit mask for each variable in the data structure. The mask corresponds to the position of the variable within the instance structure. Note that the module header is 8 words long and thus the first bit starts in the 9th bit position. These bit masks can be used by the _Set() and _Get() functions to determine which variable within the instance structure has been modified.

#define MASK_ScalerSmoothedExample_gain 0x00000100

#define MASK_ScalerSmoothedExample_smoothingTime 0x00000400

#define MASK_ScalerSmoothedExample_currentGain 0x00000200

#define MASK_ScalerSmoothedExample_smoothingCoeff 0x00000800

The header file also defines an offset for each instance variable. Again, this is the offset from the start of the data structure, in 32-bit words. These offsets are provided to help implement system control using a host interface.

#define OFFSET_ScalerSmoothedExample_gain 0x00000008

#define OFFSET_ScalerSmoothedExample_smoothingTime 0x0000000A

#define OFFSET_ScalerSmoothedExample_currentGain 0x00000009

#define OFFSET_ScalerSmoothedExample_smoothingCoeff 0x0000000B

There is a unique class ID.

#define CLASSID_SCALERSMOOTHEDEXAMPLE (CLASS_ID_MODBASE + 32768)

This integer uniquely defines the module class to the Server. Next is the definition of the module's constructor function. In this case, since the module does not have any arrays, the generic module constructor ClassModule_Constructor is used.

Info

The generic module constructor applies to modules that do not have indirect arrays in the instance data structure.  It is used by a large number of modules.  The constructor function awe_modScalerSmoothedExample_Constructor() is provided as a macro so that the module can be constructed within subsystems.  We'll see shortly that the constructor function is defined as NULL within the module's class structure.

Code Block
#ifndef AWE_STATIC_CODE

...


// This points the constructor for this class to the base constructor

...


#define awe_modScalerSmoothedExampleConstructor(ARG1, ARG2, ARG3, ARG4, ARG5) ClassModule_Constructor(CLASSID_SCALERSMOOTHEDEXAMPLE, ARG1, ARG2, ARG3, ARG4, ARG5)

...


#endif

And finally, there are definitions for the processing and set functions:

void awe_modScalerSmoothedExampleProcess(void *pInstance);

UINT awe_modScalerSmoothedExampleSet(void *pInstance, UINT mask);

Note

...

: Many of the items are surrounded by #ifdef / #endif pairs. This allows various features of the modules to be enabled or disabled at compile time.

Audio Module Source Code (.c and .h files)

...