Main Content

generateSimulinkAudioPlugin

Create object class compatible with Simulink

Since R2022b

    Description

    generateSimulinkAudioPlugin(plugin) generates code for a System object™ class with the same functionality as the provided audio plugin and opens the generated file. The generated System object is compatible with Simulink® through the MATLAB System (Simulink) block. See Audio Plugin for a block that uses generateSimulinkAudioPlugin to include an audio plugin in a Simulink model.

    example

    generateSimulinkAudioPlugin(plugin,fileName) generates code and saves the resulting System object class to the file specified by fileName.

    example

    Examples

    collapse all

    You can include an audio plugin in your Simulink model by generating a System object with generateSimulinkAudioPlugin and then using that System object with the MATLAB System (Simulink) block.

    Call generateSimulinkAudioPlugin with the audiopluginexample.LFOFilter audio plugin to generate a System object class.

    generateSimulinkAudioPlugin(audiopluginexample.LFOFilter)

    In Simulink, place the MATLAB System block in your model.

    Double-click the block to open the dialog box, and specify the System object name as the generated class, audioSimulinkSysObj. Click OK to generate a block with the same functionality as the original plugin.

    You can now use the block in your model. The block has the same parameters as the original plugin. For more information about the generated block and its parameters, see Audio Plugin.

    Specify the fileName as "myPlugin" to generate the System object class with that name in the current directory.

    generateSimulinkAudioPlugin(audiopluginexample.Echo,"myPlugin")

    Input Arguments

    collapse all

    Audio plugin from which to generate the System object class, specified as an audio plugin object. Plugins authored in MATLAB® derive from audioPlugin or audioPluginSource. Externally authored plugins derive from externalAudioPlugin or externalAudioPluginSource and are returned by loadAudioPlugin.

    If the input plugin is an externally hosted plugin returned by loadAudioPlugin, the function generates additional files required by the System object. For more information, see Code Generation.

    Example: audiopluginExample.Echo

    File name of the generated System object class, specified as a string or character vector. You can optionally specify the path and .m file extension. By default, generateSimulinkAudioPlugin creates a class named audioSimulinkSysObj in the current directory.

    Example: "myLFO"

    Example: "plugins/myEchoPlugin.m"

    Data Types: char | string

    Limitations

    Some Simulink functionality, such as Step Back, requires saving and restoring the simulation state. Blocks that use hosted external plugins do not support simulation save and restore and therefore do not support associated functionality. For tips on using simulation save and restore functionality with blocks that use plugins authored in MATLAB, see Tips.

    Tips

    To use Simulink functionality that requires saving and restoring the simulation state, such as Step Back, with a block that uses a plugin authored in MATLAB, the original plugin implementation must correctly save and load its state.

    • If the original plugin is a System object, it must correctly save and load its state using the saveObjectImpl and loadObjectImpl methods.

    • If the original plugin is an audioPlugin and not a System object plugin, it must correctly save and load its state using the saveobj and loadobj methods.

    Note

    If the original plugin does not maintain any state, no additional considerations are necessary for the save and restore functionality.

    Extended Capabilities

    Version History

    Introduced in R2022b