This example shows how to use the MATLAB Compiler to create a standalone application from a MATLAB function, which uses System objects.
In this example, you compile the Freeverb audio reverberation example freeverbReverberationExampleAppfreeverbReverberationExampleApp using the MATLAB compiler and then run the generated standalone application. Note that compilation is supported only for System objects used inside MATLAB functions. MATLAB scripts using System objects are not supported by MATLAB compiler.
Freeverb Reverberation Algorithm
Freeverb is a popular implementation of the Schroeder reverberator. This algorithm is based on the public domain 'Freeverb' model written by Jezar at Dreampoint (June 2000). A high-level model of the Freeverb algorithm is shown below. For more information on the algorithm and its implementation, follow the example: 'Adding Reverberation to Audio Using Freeverb Algorithm''Adding Reverberation to Audio Using Freeverb Algorithm'.
Create a Temporary Directory for Compilation
To compile the MATLAB function to create the standalone application, you use a temporary directory where you will have write permissions. Copy the MATLAB function to compile and the required helper files into this temporary directory.
compilerDir = fullfile(tempdir,'compilerDir'); % Name of temporary directory if ~exist(compilerDir,'dir') mkdir(compilerDir); % Create temporary directory end curdir = cd(compilerDir); copyfile(which('freeverbReverberationExampleApp')); copyfile(which('guitar10min.ogg')); copyfile(which('HelperCreateParamTuningUI')); copyfile(which('HelperFreeverbReverberation')); copyfile(which('HelperUnpackUDP')); dspdemoDir = fullfile(pwd,'+dspdemo'); if ~exist(dspdemoDir,'dir') mkdir(dspdemoDir); end copyfile(which('dspdemo.FreeverbReverberator'), dspdemoDir)
Compile the MATLAB Function Into a Standalone Application
You use the
mcc function to compile the
freeverbReverberationExampleApp into a standalone application. Specify the '-m' option to generate a standalone application, '-N' option to include only the directories specified using the '-p' option in the path. This step takes a few minutes to complete.
mcc('-mN', 'freeverbReverberationExampleApp', ... '-p', [matlabroot '/toolbox/dsp']);
Run the Deployed Application
You use the
system command to run the generated standalone application. The file HelperFreeverbRunCompiledEXEHelperFreeverbRunCompiledEXE contains the call to
system to run the standalone application that was generated in the previous section. Note that running the standalone application using the system command uses the current MATLAB environment and any library files needed from this installation of MATLAB. To deploy this application to end users refer to the 'Deployment Process' section in the users guide for MATLAB CompilerMATLAB Compiler product.
if ismac status = system(fullfile('freeverbReverberationExampleApp.app', ... 'Contents', 'MacOS', 'freeverbReverberationExampleApp')); else status = system(fullfile(pwd, 'freeverbReverberationExampleApp')); end
Similar to the MATLAB example 'Adding Reverberation to Audio Using Freeverb Algorithm''Adding Reverberation to Audio Using Freeverb Algorithm', running this deployed application also launches a user interface (UI) to interact with the Freeverb algorithm while the simulation is running. The UI allows you to tune parameters and the results are reflected in the simulation instantly. For example, moving the slider 'Room size' to the left while the simulation is running, will have an effect of decreasing the reflectivity of the walls of the room being simulated. You can use the buttons on the UI to pause or stop the simulation.
Clean up Generated Files