Main Content

使用MATLAB编译器部署音频应用程序

此示例显示了如何使用MATLAB Compiler™从MATLAB函数创建独立应用程序。该功能实现音频处理算法并通过音频输出设备播放结果。

Introduction

在此示例中,您生成并运行可执行的应用程序,该应用程序将人工混响应用于音频信号,并通过所选的音频设备播放。此类应用程序的好处是它们可以在不需要安装MATLAB的机器上运行。您只需要安装MATLAB运行时即可部署本示例中创建的应用程序。

混响算法

混响算法是使用系统对象实现的混响者。它使您可以为单声道或立体声通道音频输入添加混响效果。该对象提供了控制混响性质的六个属性。在模拟运行时,可以调整它们每个人。

MATLABSimulation

The functionaudioReverberationCompilerExampleAppis a wrapper around混响者。验证行为audioReverberationCompilerExampleApp,在MATLAB中运行该功能。它需要一个可选的输入,这是您想要播放音频的时间。默认值为60。

audioReverberationCompilerExampleApp

The functionaudioReverberationCompilerExampleApp使用getAudioDevices的方法AudioDeviceWriter要列出当前计算机上可用的音频输出设备,以便您可以通过选择的声卡播放混响的音频。这对部署的应用程序特别有用,因为功能作者很少知道目标机上将连接哪个设备。

audioReverberationCompilerExampleApp还映射可调属性混响者到UI,以便您可以在模拟运行并立即观察其效果时轻松调整它们。例如,在模拟运行时,将滑块“扩散”移至右侧。您会听到反射密度增加的影响。您可以使用UI上的按钮暂停或停止模拟。

创建一个临时目录以进行编译

验证MATLAB模拟后,您可以编译该功能。在编译之前,创建一个临时目录,其中您的编写权限。将主MATLAB功能和关联的助手文件复制到此临时目录中。

compilerdir = fullfile(tempdir,'compilerDir');临时目录的%名称如果~exist(compilerDir,'dir')mkdir(compilerdir);% Create temporary directory结尾curdir = cd(CompilerDir);copyfile(哪个(“audioReverberationCompilerExampleApp”);copyfile(哪个('HelperAudioReverberation');copyfile(哪个('FunkyDrums-44p1-stereo-25secs.mp3')copyfile(哪个('HelperCreateParamTuningUI');copyfile(哪个('HelperUnpackUIData');

Compile the MATLAB Function into a Standalone Application

使用mcc(MATLAB编译器)function from MATLAB Compiler to compileaudioReverberationCompilerExampleApp进入独立应用程序。这将保存在当前目录中。指定生成独立应用程序的“ -m”选项,即“ -n”选项,以仅在使用'-p'选项指定的路径中包含目录。

MCC('-mn',,,,“audioReverberationCompilerExampleApp”,,,,...'-p',,,,fullfile(matlabroot,'toolbox',,,,'dsp'),...'-p',,,,fullfile(matlabroot,'toolbox',,,,'声音的');

此步骤需要几分钟才能完成。

运行生成的应用程序

使用系统命令运行生成的独立应用程序。请注意,使用系统命令运行独立应用程序,使用当前的MATLAB环境和MATLAB安装所需的任何库文件。要在未安装MATLAB的计算机上部署此应用程序,请参阅About the MATLAB Runtime(MATLAB编译器)

如果ISMAC状态=系统(FullFile(fullfile)('audioReverberationCompilerExampleApp.app',,,,...'Contents',,,,'MacOS',,,,“audioReverberationCompilerExampleApp”);别的状态=系统(fullfile(pwd,“audioReverberationCompilerExampleApp”);结尾

Similar to the MATLAB simulation, running this deployed application will first ask you to choose the audio device that you want to use to play audio. Then, it launches the user interface (UI) to interact with the reverberation algorithm while the simulation is running.

清理生成的文件

生成和部署可执行文件后,您可以通过在MATLAB命令提示中运行以下内容来清理临时目录:

cd(curDir); rmdir(compilerDir,');