This section page walks through a complete example of an audio module, starting from the high-level MATLAB model and continuing through the generated code. This example is identical to the scaler_smoothed_module.m contained in the Deprecated module library. We go through this module in a systematic fashion and reference the source files listed in the section Scaler Smoothed Example Source Files. The Examples Module Library contains additional module examples which highlight advanced features.
This module example is part of a larger audio module DLL containing several example modules. The base directory for the audio module examples is <AWE>\AWEModules\Source\Examples\
where <AWE> refers to the root directory of the Audio Weaver Designer installation.
The directory contains several subdirectories and this . This directory structure must be followed when creating other custom audio module libraries. In order to build the examples modules, the above path must be on the Audio Weaver module path variable, which can be retrieved in MATLAB with the ‘add_module_path’ command. The correct path should already be included in a normal installation of Designer, but if it is not, or if another path needs to be added, the module path can be updated using the ‘add_module_path’ command or with the File ->Set > Set Module Path menu in Designer.
Module M-files
Anchor |
---|
| ModuleM-files |
---|
| ModuleM-files |
---|
|
Each audio module has an associated module M-file, item 1 shown in Figure 1. For this example, the file is found in
...
and a listing is shown in Section 2.9.1. scaler_smoothed_example_module.m. When you first initialize Audio Weaver using awe_init.m, this file will be placed on your MATLAB path. The module m-file completely describes the audio module to MATLAB. It contains:
...
All of these items above are documented in the Audio Weaver Matlab API. The specific items in the module m-file pertaining to module generation are variables, code markers, and wiring allocation guidelines described in Generating Module Libraries (in particular, the sections Specifying Wiring Constraints and Code Markers and Template Substitution).
Subsystems are very similar to modules, but also contain a list of internal modules and a list of connections between modules.
Audio Module Instance Structure
Anchor |
---|
| AudioModuleInstanceStructure |
---|
| AudioModuleInstanceStructure |
---|
|
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:
...
The entire schema file for the example module library is shown in Section 2ExamplesSchema.9sch. 7. The portion corresponding to the ScalerSmoothedExample module is shown below.
...
The string $processFunction$
is taken from the file Inner\InnerScalerSmoothedExample_Process.c
shown in the section InnerScalerSmoothedExample_Process.c. You'll note that this is bare code missing even the function definition (which is in the template file). The other code markers – "preProcessFunction" and "postProcessFunction" are not defined. After template substitution, we end up with the final processing function ModScalerSmoothedExample.c shown in the section ModScalerSmoothedExample.c.
...
Create the MATLAB module m-file described in Section 2.1 Module M-files. It defines:
Input and output pins
Instance structure variables
Links to inner C code.
Documentation
User interface
Module browser for AWE Designer
Write the inner C code for the processing function.
Write the inner C code for the other module functions, Constructor()
, Set(),
Get()
, and Bypass()
, if needed.
Pick a unique integer ID (any number in the range 32768 to 63487) for the new module class ID. Add this information to the file classids.csv associated with the module library.
Add the module function to the specific module pack library generation script, for example make_examples.m. Run the script file to generate the source code and create the schema file.
Add the generated .c and .h files to the project for building the audio module pack library (e.g., ExamplesLib.vcproj) and build the library.
Build the audio module DLL so that the new modules are visible by the Server.
...
The following sections feature expandable code blocks with the contents of example source files.
scaler_smoothed_example_module.m
Anchor |
---|
| scaler_smoothed_example_module.m |
---|
| scaler_smoothed_example_module.m |
---|
|
Expand |
---|
title | Click to expand "scaler_smoothed_example_module.m" example source |
---|
|
Code Block |
---|
function M=scaler_smoothed_example_module(NAME)
% M=scaler_smoothed_example_module(NAME)
% Creates a smoothly varying scaler module with a single input
% and single output pin. This module operates on floating-point
% signals. Arguments:
% NAME - name of the module.
% Copyright 2007-2016. DSP Concepts, Inc. All Rights Reserved.
% ----------------------------------------------------------------------
% Create the high-level object with interface variables only.
% ----------------------------------------------------------------------
M=awe_module('ScalerSmoothedExample', 'Linear multichannel smoothly varying scaler');
% Version is auto-updated by SVN:
M.moduleVersion = generate_version('$Revision: 30333 $');
if (nargin == 0)
return;
end
M.name=NAME;
M.preBuildFunc=@scaler_smoothed_example_prebuild;
M.processFunc=@scaler_smoothed_example_process;
M.setFunc=@scaler_smoothed_example_set;
PT=new_pin_type;
add_pin(M, 'input', 'in', 'audio input', PT);
add_pin(M, 'output', 'out', 'audio output', PT);
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);
awe_addcodemarker(M, 'processFunction', 'Insert:InnerScalerSmoothedExample_Process.c');
awe_addcodemarker(M, 'setFunction', 'Insert:InnerScalerSmoothedExample_Set.c');
awe_addcodemarker(M, 'srcFileInclude', '#include "FilterDesign.h"');
M.wireAllocation='across';
% ----------------------------------------------------------------------
% Documentation
% ----------------------------------------------------------------------
M.docInfo.discussion={'Scales all input channels by a single gain value. ', ...
'Changes to the gain parameter are exponentially smoothed (first order IIR) at the sample rate, with the time constant determined by the smoothingTime parameter. ', ...
'This module is controlled by varying the gain variable. Internally, currentGain represents the instantaneous smoothed gain that is applied. ', ...
'currentGain exponentially approaches gain with a time constant equal to smoothingTime. ', ...
'', ...
'The module''s prebuild function initializes the currentGain equal to the gain. Thus, the module begins in a converged state.'};
% ----------------------------------------------------------------------
% Add the inspector information
% ----------------------------------------------------------------------
M.guiInfo.isExpanded=0;
M.gain.guiInfo.controlType='slider';
add_control(M, '.gain');
add_control(M, '.moduleStatus', 'right', 1);
add_control(M, '.smoothingTime', 'below', 1);
% ----------------------------------------------------------------------
% Module browser information
% ----------------------------------------------------------------------
M.moduleBrowser.path = 'Examples';
M.moduleBrowser.image = '../images/ExamplesIcon.bmp';
M.moduleBrowser.searchTags = 'scaler volume';
M.shapeInfo.basicShape = 'triangle';
M.shapeInfo.legend = ' ';
return;
% ----------------------------------------------------------------------
% Prebuild function. Behavior is based on the data type of the
% input pin
% ----------------------------------------------------------------------
function M=scaler_smoothed_example_prebuild(M)
M.currentGain=M.gain;
M.currentGain.range=M.gain.range;
% Propagate the type of the input pin to the output
M.outputPin{1}.type=M.inputPin{1}.type;
return;
% ----------------------------------------------------------------------
% Set function. Computes the smoothing coefficient
% ----------------------------------------------------------------------
function M=scaler_smoothed_example_set(M)
% Compute the smoothing coefficient based on the smoothing time
SR=M.inputPin{1}.type.sampleRate;
M.smoothingCoeff = design_smoother(M.smoothingTime, SR, 1);
return; |
|
...
Expand |
---|
title | Click to expand "classids.csv" example source |
---|
|
Code Block |
---|
% Class ID list for the examples that are included in the Audio Weaver
% documentation.
IDOFFSET=32768
ScalerSmoothedExample,0
ScalerExample,1
FaderExample,2
FaderExampleFract32,3
PeakHoldExample,4
DownsamplerExample,5
LAHLimiterExample,6
PeakHoldExampleFract32,7
FeedbackExample,8 |
|
ExamplesSchema.sch
Anchor |
---|
| ExamplesSchema.sch |
---|
| ExamplesSchema.sch |
---|
|
Expand |
---|
title | Click to expand "ExamplesSchema.sch" example source |
---|
|
Code Block |
---|
ModuleDownsamplerExample 0xBEEF8805, BaseModule
{
D int // Decimation factor. 1 out of every D samples is output
}
ModuleFaderExampleFract32 0xBEEF8803, BaseModule
{
scaleFval float // Scaler Front
scaleBval float // Scaler Back
smoothingTimeF float // Time constant of the smoothing process
smoothingTimeB float // Time constant of the smoothing process
scalerF *ModuleScalerSmoothedFract32 // Linear multichannel smoothly varying scaler
scalerB *ModuleScalerSmoothedFract32 // Linear multichannel smoothly varying scaler
inter *ModuleInterleave // Interleaves multiple audio signals
}
ModuleFaderExample 0xBEEF8802, BaseModule
{
fade float // Front/back Balance. +1 = front only. -1 = rear only.
smoothingTime float // Time constant of the smoothing process
scalerF *ModuleScalerSmoothed // Gain control with linear units and smoothing
scalerB *ModuleScalerSmoothed // Gain control with linear units and smoothing
inter *ModuleInterleave // Interleaves multiple audio signals
}
ModuleLAHLimiterExample 0xBEEF8806, BaseModule
{
maxDelayTime float // Maximum delay time
max_abs *ModuleMaxAbs // Computes the maximum absolute value of all input channels on a sample-by-sample basis
core *ModuleAGCLimiterCore // Gain computer used to realize soft-knee peak limiters
delay *ModuleDelayMsec // Time delay in which the delay is specified in milliseconds
mult *ModuleAGCMultiplier // Mono x N-channel multiplier
}
ModulePeakHoldExampleFract32 0xBEEF8807, BaseModule
{
Reset int // reset the current peak values
attackTime float // Envelope detector attack time constant
decayTime float // Envelope detector decay time constant
decayCoef fract32 // Computed coefficient used for decay
attackCoef fract32 // Computed coefficient used for attack
peakHold *fract32 // Array of peak values
peakDecay *fract32 // Array of decaying peak values
}
ModulePeakHoldExample 0xBEEF8804, BaseModule
{
Reset int // reset the current peak values
attackTime float // Envelope detector attack time constant
decayTime float // Envelope detector decay time constant
decayCoef float // Computed coefficient used for decay
attackCoef float // Computed coefficient used for attack
peakHold *float // Array of peak values
peakDecay *float // Array of decaying peak values
}
ModuleScalerExample 0xBEEF8801, BaseModule
{
gain float // Linear gain
}
ModuleScalerSmoothedExample 0xBEEF8800, BaseModule
{
gain float // Target gain
smoothingTime float // Time constant of the smoothing process
currentGain float // Instantaneous gain applied by the module. This is also the starting gain of the module.
smoothingCoeff float // Smoothing coefficient
} |
|
...