Base class for audio plugins
audioPlugin is the base class for audio plugins. In your
class definition file, you must subclass your object from this base class or from the
audioPluginSource class, which inherits from
audioPlugin. Subclassing enables you to inherit
the attributes necessary to generate plugins and access Audio Toolbox™ functionality.
To inherit from the
audioPlugin base class
directly, type this syntax as the first line of your class definition
classdef myAudioPlugin < audioPlugin
myAudioPluginis the name of your object.
For a tutorial on designing audio plugins, see Audio Plugins in MATLAB.
|getSampleRate||Get sample rate at which the plugin is run|
|setLatencyInSamples||Set latency in samples reported to DAW|
|setSampleRate||Set sample rate at which the plugin is run|
Handle. To learn how handle classes affect copy operations, see Object Behavior.
Design a valid basic audio plugin class.
Define a basic audio plugin class that inherits from
classdef myAudioPlugin < audioPlugin end
Add a processing function to your plugin class. All valid audio plugins include a processing function. For basic audio plugins, the processing function is named process. The processing function is where audio processing occurs. It always has an output.
classdef myAudioPlugin < audioPlugin methods function out = process(~,in) out = in; end end end
audioPlugin class that uses the
getSampleRate method to get the sample rate at which the plugin is run. The plugin in this example,
simpleStrobe, uses the sample rate to determine a constant 50 ms strobe period.
classdef simpleStrobe < audioPlugin % simpleStrobe Add audio strobe effect % Add a strobe effect by gain switching between 0 and 1 in % 50 ms increments. Although the input sample rate can change, % the strobe period remains constant. % % simpleStrobe properties: % period - Number of samples between gain switches % gain - Gain multiplier, one or zero % count - Number of samples since last gain switch % % % simpleStrobe methods: % process - Multiply input frame by gain, element by element % reset - Reset count and gain to initial conditions % and get sample rate properties Period = 44100*0.05; Gain = 1; end properties (Access = private) Count = 1; end methods function out = process(plugin,in) for i = 1:size(in,1) if plugin.Count == plugin.Period plugin.Gain = 1 - plugin.Gain; plugin.Count = 1; end in(i,:) = in(i,:)*plugin.Gain; plugin.Count = plugin.Count + 1; end out = in; end function reset(plugin) plugin.Period = floor( getSampleRate(plugin)*0.05 ); plugin.Count = 1; plugin.Gain = 1; end end end
audioPlugin class that uses the
setLatencyInSamples method to report the latency of the plugin. The plugin in this example,
simpleDelay, delays the audio signal by a fixed integer and reports the delay to the host application.
classdef simpleDelay < audioPlugin % simpleDelay Add delay to audio signal % This plugin adds a 100 sample delay to the audio input and reports % the latency to the host application. properties (Access = private) Delay end methods function plugin = simpleDelay plugin.Delay = dsp.Delay(100); end function out = process(plugin,in) out = plugin.Delay(in); end function reset(plugin) setLatencyInSamples(plugin,100) end end end
This example is intended to show the pattern for using
setLatencyInSamples. For a detailed use-case, see
audiopluginexample.FastConvolver in the Audio Plugin Example Gallery.