host external audio plugins -凯发k8网页登录

main content

host external audio plugins

you can host vst, vst3, and au plugins in matlab® by using the function from audio toolbox™.

after you load an external audio plugin, you process audio through its main audio-processing algorithm.

audio toolbox enables three ways to interact with the hosted audio plugin:

the following tutorials–one version for property display mode and one version for parameter display mode–walk you through the process of hosting an externally authored vst plugin and interacting with the plugin at the matlab command line. you host a plugin from the suite of reaplugs vst plugins distributed by cockos incorporated. to download the reaplugs vst fx suite for your system, follow the instructions on the . a 64-bit windows platform is used in this tutorial. the loadaudioplugin function cannot load 32-bit plugins.

property display mode (default)

setting the display mode to property enables you to interact with the hosted plugin object using standard dot notation. for example:

hostedobject.gain = 5; % db
property is the default display mode of hosted plugins.

numeric parameters are mapped through a heuristic interpretation of the normalized parameter values and the corresponding display values. the property display mode is simple and intuitive. however, due to the heuristic mapping of normalized parameter values to real-world property values, the property display mode may break down for some plugins. in this case, you should use the parameter display mode.

host external audio plugin tutorial (property display mode)

the following tutorial walks through the steps of loading and configuring an external audio plugin in property display mode.

1. load external audio plugin

use the loadaudioplugin function to host the readelay vst plugin. if the plugin is in your current folder, you can specify just the file name. otherwise, you must specify the full path. in this example, the plugin is in the current folder. by default, the display mode is set to property.

hostedplugin = loadaudioplugin('readelay-standalone.dll')
hostedplugin = 
  vst plugin 'readelay (reaplugs edition)'  2 in, 2 out
               wet: 0 db
               dry: 0 db
        x1_enabled: 'on'
       x1_length_4: 0 ms
       x1_length_5: 4 8n
       x1_feedback: -inf db
        x1_lowpass: 20000 hz
         x1_hipass: 0 hz
     x1_resolution: 24 bits
    x1_stereowidth: 1
         x1_volume: 0 db
            x1_pan: 0 %

the first line displays the plugin type, plugin display name, and the number of input and output channels for the main audio-processing algorithm of the plugin. if you are hosting a source plugin, the number of output channels and the default samples per frame are displayed.

by default, all properties are displayed.

2. tune hosted plugin property values

you can interact with the properties of the hosted plugin using dot notation. if you go above or below the allowed range of the property, an error message will state the valid boundaries.

hostedplugin.x1_hipass = 120;
highpasssetting = hostedplugin.x1_hipass
highpasssetting = 120

you can use tab-completion to get a list of possible values for enumerated properties.

3. use hosted plugin to process audio

to process an audio signal with the hosted plugin, use process.

audioin = [1,1];
audioout = process(hostedplugin,audioin);

audio plugins are designed for variable-frame-based processing, meaning that you can call process with successive audio input frames of different lengths. the hosted plugin saves the internal states required for continuous processing. to process an audio signal read from a file and then written to your audio output device, place your hosted plugin in an audio stream loop. use and objects as the input and output to your audio stream loop, respectively. set the sample rate of the hosted plugin to the sample rate of the audio file by using setsamplerate.

filereader = dsp.audiofilereader('counting-16-44p1-mono-15secs.wav');
samplerate = filereader.samplerate;
devicewriter = audiodevicewriter('samplerate',samplerate);
setsamplerate(hostedplugin,samplerate);
while ~isdone(filereader)
    audioin = filereader();
    
    % the hosted plugin requires a stereo input.
    stereoaudioin = [audioin,audioin];
    
    x = process(hostedplugin,stereoaudioin);
    
    devicewriter(x);
end
release(filereader)
release(devicewriter)

you can modify properties in the audio stream loop. to control the wet property of your plugin in an audio stream loop, create an system object™. use the filereader, devicewriter, and hostedplugin objects you created previously to process the audio.

osc = audiooscillator('sine', ...
    'frequency',10, ...
    'amplitude',20, ...
    'dcoffset',-20, ...
    'samplesperframe',filereader.samplesperframe, ...
    'samplerate',samplerate);
while ~isdone(filereader)
    audioin = filereader();
    
    controlsignal = osc();
    hostedplugin.wet = controlsignal(1);
    
    stereoaudioin = [audioin,audioin];
    x = process(hostedplugin,stereoaudioin);
    devicewriter(x);
end
release(filereader)
release(devicewriter)

4. analyze hosted plugin

you can use the audio toolbox measurement and visualization tools to display behavior information about your hosted plugin. to display the input and output of your hosted audio plugin, create a time scope. create a object and use the 'ebu mode' visualization to monitor loudness output by the hosted plugin. use the filereader, devicewriter, osc, and hostedplugin objects you created previously to process the audio.

scope = timescope('samplerate',samplerate, ...
    'timespansource','property', ...
    'timespanoverrunaction','scroll', ...
    'timespan',5, ...
    'bufferlength',5*2*samplerate, ...
    'ylimits',[-1 1]);
loudmtr = loudnessmeter('samplerate',samplerate);
visualize(loudmtr)
while ~isdone(filereader)
    audioin = filereader();
    
    controlsignal = osc();
    hostedplugin.wet = controlsignal(1);
    
    stereoaudioin = [audioin,audioin];
    x = process(hostedplugin,stereoaudioin);
    
    loudmtr(x);
    scope([x(:,1),audioin(:,1)])
    
    devicewriter(x);
end

release(filereader)
release(devicewriter)

parameter display mode

setting the display mode to parameter enables you to interact with the hosted plugin in the most basic way possible: by setting and getting normalized parameter values. you can use the information optionally returned by to interpret normalized values as real-world values, such as decibels and hertz.

host external audio plugin tutorial (parameter mode)

the following tutorial walks through the steps of loading and configuring an external audio plugin in parameter display mode.

1. load external audio plugin

use the loadaudioplugin function to host the readelay vst plugin. if the plugin is in your current folder, you can specify just the file name. otherwise, you must specify the full path. in this example, the plugin is in the current folder.

hostedplugin = loadaudioplugin('readelay-standalone.dll');

by default, the display mode is set to property. set the displaymode property to parameters for low-level interaction with the hosted plugin.

hostedplugin.displaymode = 'parameters'
hostedplugin = 
  vst plugin 'readelay (reaplugs edition)'  2 in, 2 out
          parameter    value    display
        ________________________________
     1          wet:   1.0000    0.0 db
     2          dry:   1.0000    0.0 db
     3   1: enabled:   1.0000     on   
     4    1: length:   0.0000    0.0 ms
     5    1: length:   0.0156   4.00 8n
   7 parameters not displayed. see all 12 params.

the first line displays the plugin type, plugin display name, and the number of input and output channels for the main audio processing algorithm of the plugin. if you are hosting a source plugin, the number of output channels and the default samples per frame are displayed.

by default, only the first five parameters are displayed. to display all parameters of the hosted plugin, click see all 12 params.

the table provides the parameter index, parameter name, normalized parameter value, displayed parameter value, and the displayed parameter value label.

the normalized parameter value is always in the range [0,1] and generally corresponds to the position of a user interface (ui) widget in a daw or the position of a midi control on a midi control surface. the parameter display value is related to the normalized parameter value by an unknown mapping internal to the plugin and typically reflects the value used internally by the plugin for processing.

2. set and get hosted plugin parameter values

you can use getparameter and setparameter to interact with the parameters of the hosted plugin. using getparameter and setparameter is the programmatic equivalent of moving widgets in a ui or controls on a midi control surface. a typical daw ui provides the parameter name, a visual representation of the normalized parameter value, the displayed parameter value, and the displayed parameter value label.

for example, the wet parameter of readelay-standalone.dll has a normalized parameter value of 1 and a display parameter value of 0.0. the wet parameter might be displayed in a daw as follows:

with audio toolbox, you can use getparameter to return the normalized parameter value and additional information about a single hosted plugin parameter. you can specify which parameter to get by the parameter index.

parameterindex = 1;
[normparamvalue,paraminfo] = getparameter(hostedplugin,parameterindex)
normparamvalue = 1
paraminfo = struct with fields:
     displayname: 'wet'
    displayvalue: ' 0.0'
           label: 'db'

you can use setparameter to set a normalized parameter value of your hosted plugin. you can specify which parameter to set by its parameter index.

normparamvalue = 0.5;
setparameter(hostedplugin,parameterindex,normparamvalue)

setting the normalized parameter value to 0.5 is equivalent to setting the indicator to the center of a slider in a daw.

to verify the new normalized parameter value for wet, use getparameter.

parameterindex = 1;
[normparamvalue,paraminfo] = getparameter(hostedplugin,parameterindex);

the displayvalue for the wet parameter updates from 0.0 to -6.0 because you set the corresponding normalized parameter value. the relationship between the displayed value and the normalized value is determined by an unknown mapping that is internal to the hosted plugin.

3. use hosted plugin to process audio

to process an audio signal with the hosted plugin, use process.

audioin = [1,1];
audioout = process(hostedplugin,audioin);

audio plugins are designed for variable-frame-based processing, meaning that you can call process with successive audio input frames of different lengths. the hosted plugin saves the internal states required for continuous processing. to process an audio signal read from a file and then written to your audio output device, place your hosted plugin in an audio stream loop. use and objects as the input and output to your audio stream loop, respectively. set the sample rate of the hosted plugin to the sample rate of the audio file by using setsamplerate.

filereader = dsp.audiofilereader('counting-16-44p1-mono-15secs.wav');
samplerate = filereader.samplerate;
devicewriter = audiodevicewriter('samplerate',samplerate);
setsamplerate(hostedplugin,samplerate);
while ~isdone(filereader)
    audioin = filereader();
    
    % the hosted plugin requires a stereo input.
    stereoaudioin = [audioin,audioin];
    
    x = process(hostedplugin,stereoaudioin);
    
    devicewriter(x);
end
release(filereader)
release(devicewriter)

you can modify parameters in the audio stream loop. to control the wet parameter of your plugin in an audio stream loop, create an system object™. use the filereader, devicewriter, and hostedplugin objects you created previously to process the audio.

osc = audiooscillator('sine', ...
    'frequency',10, ...
    'amplitude',0.5, ...
    'dcoffset',0.5, ...
    'samplesperframe',filereader.samplesperframe, ...
    'samplerate',samplerate);
while ~isdone(filereader)
    audioin = filereader();
    
    controlsignal = osc();
    setparameter(hostedplugin,1,controlsignal(1));
    
    stereoaudioin = [audioin,audioin];
    x = process(hostedplugin,stereoaudioin);
    devicewriter(x);
end
release(filereader)
release(devicewriter)

4. analyze hosted plugin

you can use the audio toolbox measurement and visualization tools to display behavior information about your hosted plugin. to display the input and output of your hosted audio plugin, create a time scope. create a object and use the 'ebu mode' visualization to monitor loudness output by the hosted plugin. use the filereader, devicewriter, osc, and hostedplugin objects you created previously to process the audio.

scope = timescope('samplerate',samplerate, ...
    'timespansource','property', ...
    'timespanoverrunaction','scroll', ...
    'timespan',5, ...
    'bufferlength',5*2*samplerate, ...
    'ylimits',[-1 1]);
loudmtr = loudnessmeter('samplerate',samplerate);
visualize(loudmtr)
while ~isdone(filereader)
    audioin = filereader();
    
    controlsignal = osc();
    setparameter(hostedplugin,1,controlsignal(1));
    
    stereoaudioin = [audioin,audioin];
    x = process(hostedplugin,stereoaudioin);
    
    loudmtr(x);
    scope([x(:,1),audioin(:,1)])
    
    devicewriter(x);
end

release(filereader)
release(devicewriter)

graphical interaction

you can also interact with an externally authored audio plugin graphically using the . the audio test bench mimics the default graphical user interface common to most digital audio workstations.

heuristic mapping

investigate parameter/property mapping

parameter display values are related to normalized parameter values by unknown mapping rules internal to the plugin. you can investigate the relationship between the normalized parameter values and the displayed values by creating a sweeping function. you can use the sweeping function to map parameter values to their displayed output.

the properties display mode of hosted plugins uses a similar approach to enable you to interact directly with the real-world (displayed) values, instead of the normalized parameter values.

save the displayparametermapping function in your current folder. this function performs a simplified version of the parameter sweeping used to create the property display mode for hosted plugins.

function displayparametermapping(hplugin,prmindx)
x = 0:0.001:1; % normalized parameter range
[~,prminfo] = getparameter(hplugin,prmindx);
if isnan(str2double(prminfo.displayvalue))
    % non-numeric displays - prints normalized parameter range associated
    % with string
    setparameter(hplugin,prmindx,0);
    [~,prminfo] = getparameter(hplugin,prmindx);
    txtold = prminfo.displayvalue;
    oldindx = 1;
    
    for i = 2:numel(x)
        setparameter(hplugin,prmindx,x(i))
        [~,prminfo] = getparameter(hplugin,prmindx);
        txtnew = prminfo.displayvalue;
        if ~strcmp(txtnew,txtold)
            fprintf('%s: %g - %g\n',txtold, x(oldindx),x(i-1));
            oldindx = i;
            txtold = txtnew;
        end
    end
    fprintf('%s: %g - %g\n',txtold, x(oldindx),x(i));
else
    % numeric displays - plots normalized parameter value against displayed
    % parameter value
    y = zeros(numel(x),1);
    for i = 1:numel(x)
        setparameter(hplugin,prmindx,x(i))
        [~,prminfo] = getparameter(hplugin,prmindx);
        y(i) = str2double(prminfo.displayvalue);
    end
    if any(isnan(y))
        warning('nan detected in numeric display.')
    end
    plot(x,y)
    xlabel('normalized parameter value')
    ylabel(['displayed parameter value (',prminfo.label,')'])
    title(prminfo.displayname)   
end
end

load the readelay-standalone.dll plugin into matlab®. call the displayparametermapping function with the hosted plugin and a parameter index.

hostedplugin = loadaudioplugin('readelay-standalone.dll');
displayparametermapping(hostedplugin,1);

if you use the displayparametermapping function with a nonnumeric parameter, the relationship displays in the command window:

displayparametermapping(hostedplugin,3)
off: 0 - 0.499
on: 0.5 - 1

see also

functions

classes

  • |

related topics

网站地图