Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

audioPlugin class

Base class for audio plugins

Description

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 System Toolbox™ functionality.

To inherit from the audioPlugin base class directly, type this syntax as the first line of your class definition file:

classdef myAudioPlugin < audioPlugin
myAudioPlugin is the name of your object.

For a tutorial on designing audio plugins, see Design an Audio Plugin.

Methods

getSampleRateGet sample rate at which the plugin is run
setSampleRateSet sample rate at which the plugin is run

Copy Semantics

Handle. To learn how handle classes affect copy operations, see Object Behavior (MATLAB) in the MATLAB® documentation.

Examples

expand all

Design a valid basic audio plugin class

Terminology:

  • A valid audio plugin is one that can be deployed in a digital audio workstation (DAW) environment. To validate it, use the validateAudioPlugin function. To generate it, use the generateAudioPlugin function.

  • A basic audio plugin inherits from the audioPlugin class but not the matlab.System class.

Define a basic audio plugin class that inherits from audioPlugin.

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

Design an 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

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Introduced in R2016a

Was this topic helpful?