Convert Audio Plugin System Objects to Simulink Blocks
You can convert System object™ audio plugins to blocks for real-time parameter tuning in Simulink®. Use this workflow to convert your own System object plugins to Simulink blocks, or to convert any of the System object plugins found in the Audio Plugin Example Gallery.
Open the Basic Audio Player Template in Simulink
On the Simulink Start Page, under Audio Toolbox™, click Basic Audio Player. See Real-Time Audio in Simulink for a tutorial on using Simulink model templates.
Import Audio Plugin Functionality
To import System object plugins into Simulink, use the MATLAB System block. This block is compatible with System object plugins but not basic plugins. See Audio Plugins in MATLAB for more information about defining plugins in MATLAB®.
Add the System object plugin used in this example to the MATLAB path. At the command prompt, enter:
addpath(fullfile(matlabroot,'examples','audio','main'))
From the Simulink / User-Defined Functions library, drag a MATLAB System block to your model.
In the MATLAB System block, enter the name of your System object:
SoundPosition
The SoundPosition
audio plugin enables you
to tune two parameters: stereo width, and panning.
Create an Audio Plugin Block Interface
When you import a plugin into a Simulink model, the plugin parameters are set to the initial values defined in the properties section of the plugin class. To use dials for tunable parameters, create a custom interface by using a block mask. See Masking Fundamentals (Simulink) for more information.
Open the SoundPosition block.
Set Width to the variable
W
.Set Pan to the variable
P
.Click OK.
Make your SoundPosition block a subsystem. Select the SoundPosition block then, in the Modeling tab, select Create Subsystem.
Add a mask to your Subsystem block. In the Subsystem Block tab, select Create Mask.
In the Mask Editor, click the Parameters & Dialog tab.
Add a dial to the dialog box for controlling stereo width. From the Controls pane, drag a Dial to the Dialog box pane. Then, in the Property editor pane, set these properties:
Name ––
W
Value ––
2
Prompt ––
Stereo width
Type ––
dial
Minimum ––
0
Maximum ––
4
To control the panning, add another dial to the dialog box. From the Controls pane, drag a Dial to the Dialog box pane. Then, in the Property editor pane, set these properties:
Name ––
P
Value ––
0
Prompt ––
Pan
Type ––
dial
Minimum ––
-1
Maximum ––
1
Click OK.
Run the Model
Open the From Multimedia File block.
To modify the frame size used in your model, set Samples per audio channel to
256
.To hear the effect of the stereo widening, specify an audio file with a distinct stereo field recording. Set File name to
FunkyDrums-44p1-stereo-25secs.mp3
.Click OK.
To open the parameter controls of your SoundPosition block, double-click the Subsystem block.
Run your model. To hear the effect of your audio plugin, open the Subsystem block and modify the Stereo width and Pan parameters in real time.
Open the completed model.
After you complete this tutorial, it is a best practice to undo the modification to the MATLAB path. At the command prompt, enter:
rmpath(fullfile(matlabroot,'examples','audio','main'))