Versions Compared

Key

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

...

The following sections feature expandable code blocks containing example source code.

scaler_smoothed_example_module.m

Expand
titlescaler_smoothed_example_module.m 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;

...