Possible to use Codegen options in AudioPlugin generation?

7 views (last 30 days)
I am trying to write an audio plugin in Matlab, and while trying to write it, run into various problems, e.g. variables are considered unbounded, cannot use FFTW instead of built-in FFT algorithms, etc. And many of these problems point to changing codegen options as an answer. Yet, codegen options appear inaccessible for the generateAudioPlugin function. What is the workaround?
  5 Comments
Joseph
Joseph on 19 Nov 2024 at 19:36
Hi Umar,
4. Once you have generated the C/C++ code with the desired codegen options, you can integrate it back into your audio plugin project.
How? It doesn't seem possible to use a .m calling .mex code in a generateAudioPlugin call either.
Umar
Umar on 20 Nov 2024 at 4:15

Hi @Joseph,

Since generateAudioPlugin does not allow for direct manipulation of code generation options, consider manually generating C/C++ code for your audio plugin using MATLAB Coder. This method provides greater control over code generation settings. Convert Your Plugin to a Standalone Function by ensuring that your audio processing logic is encapsulated in a standalone MATLAB function that adheres to the requirements for code generation. Execute the following command in your MATLAB environment:

codegen -config:mex yourFunctionName -args {inputArgs}

Replace yourFunctionName with the name of your function and inputArgs with example inputs that match the expected dimensions and types. Then, use configuration objects to specify various options such as optimization settings or linking external libraries like FFTW:

cfg = coder.config('mex');
cfg.CustomSource = 'path_to_your_custom_code';
cfg.CustomInclude = 'path_to_include_files';
codegen yourFunctionName -config cfg -args {exampleInputs}

Once you have generated the necessary C/C++ code, you can integrate it back into your audio plugin project. Although direct integration of MEX files into generateAudioPlugin is not feasible, you can create a hybrid approach, write a wrapper MATLAB function that calls your generated MEX function. This function can serve as an interface between your plugin and the MEX functionality. Update your audio plugin class to call this wrapper function instead of directly executing the original MATLAB code.

If you're encountering issues with unbounded variables, ensure that all variables have defined sizes before calling codegen. You can do this by utilizing input validation within your function using argument blocks or by specifying fixed-size arrays during the codegen command.

Example:

function output = myAudioFunction(input) %#codegen
  arguments
      input (1, :) double % Specify input as a row vector
  end
  % Your processing logic here
end

If you want to utilize FFTW, ensure that you link it correctly in your custom source settings during code generation. This may involve including header files and linking against the appropriate libraries. Refer to MATLAB's official documentation on [MATLAB Coder]

Matlab Coder

for more insights into specific options available for code generation and examples of integrating external libraries. Also, engaging with communities such as Stack Overflow may provide additional solutions from other developers who have faced similar issues.

By following these steps, you should be able to effectively navigate around the limitations imposed by generateAudioPlugin and enhance the functionality of your audio plugin in MATLAB.

If you have further questions or need clarification on any specific point, feel free to ask!

Sign in to comment.

Answers (0)

Categories

Find more on Code Generation and Deployment in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!