matlab 音频编辑器,在Matlab中使用App Designer可以进行实时音频处理吗?

谭成业
2023-12-01

我想用Matlab中的应用程序设计器编写一个简单的音频过滤应用程序。一个人应该能够加载音频文件,按播放和改变参数,如输入增益,截止频率等,而文件正在播放。

我只是不知道如何能够实时更改参数并更新相应的变量,以便人们能够听到过滤器是如何更改的。

这是我现在写的代码:

classdef EulerFilter < matlab.apps.AppBase

% Properties that correspond to app components

properties (Access = public)

UIFigure matlab.ui.Figure

CutoffKnobLabel matlab.ui.control.Label

CutoffKnob matlab.ui.control.Knob

PlayButton matlab.ui.control.StateButton

end

properties (Access = public)

inputGain % input Gain

CutoffHz % cutoff frequency in Hz

end

methods (Access = public)

function play(app)

% setup file stream

frameLength = 256;

fileReader = dsp.AudioFileReader(...

'Sun Behind CloudsDry.wav',...

'SamplesPerFrame',frameLength);

deviceWriter = audioDeviceWriter(...

'SampleRate',fileReader.SampleRate);

% code snippet

% porcessing of frames

while ~isDone(fileReader)

% code snippet

end

release(fileReader);

release(deviceWriter);

end

end

methods (Access = private)

% Code that executes after component creation

function startupFcn(app)

app.inputGain = 1;

app.CutoffHz = 22000;

end

% Value changed function: PlayButton

function PlayButtonValueChanged(app, event)

value = app.PlayButton.Value;

play(app);

end

% Value changing function: CutoffKnob

function CutoffKnobValueChanging(app, event)

%display(event)

changingValue = event.Value;

app.CutoffHz = changingValue;

end

end

% App initialization and construction

methods (Access = private)

% Create UIFigure and components

function createComponents(app)

% Create UIFigure

app.UIFigure = uifigure;

app.UIFigure.Position = [100 100 640 480];

app.UIFigure.Name = 'UI Figure';

% Create CutoffKnobLabel

app.CutoffKnobLabel = uilabel(app.UIFigure);

app.CutoffKnobLabel.HorizontalAlignment = 'center';

app.CutoffKnobLabel.Position = [159 322 37 22];

app.CutoffKnobLabel.Text = 'Cutoff';

% Create CutoffKnob

app.CutoffKnob = uiknob(app.UIFigure, 'continuous');

app.CutoffKnob.Limits = [10 22000];

app.CutoffKnob.MajorTicks = [10 1000 5000 22000];

app.CutoffKnob.ValueChangingFcn = createCallbackFcn(app, @CutoffKnobValueChanging, true);

app.CutoffKnob.Position = [155 367 45 45];

app.CutoffKnob.Value = 22000;

% Create PlayButton

app.PlayButton = uibutton(app.UIFigure, 'state');

app.PlayButton.ValueChangedFcn = createCallbackFcn(app, @PlayButtonValueChanged, true);

app.PlayButton.Text = 'Play';

app.PlayButton.Position = [60 40 100 22];

end

end

methods (Access = public)

% Construct app

function app = EulerFilter

% Create and configure components

createComponents(app)

% Register the app with App Designer

registerApp(app, app.UIFigure)

% Execute the startup function

runStartupFcn(app, @startupFcn)

if nargout == 0

clear app

end

end

% Code that executes before app deletion

function delete(app)

% Delete UIFigure when app is deleted

delete(app.UIFigure)

end

end

end

它主要是Matlab为图形用户界面生成的函数。我添加了一些属性,其中包含输入增益、截止值等的值,以及执行信号处理的play()函数。

我可以运行应用程序,按下播放按钮,听到正在播放的音频文件,但当我改变截止频率,例如,没有改变。我想这是因为当按下play按钮时,我在回调函数中执行play()函数,因此在另一个按钮完成之前,不能执行切断旋钮时的回调函数。

当我第一次更改参数,然后按播放,一切都是正确的,除了我不能改变参数时,文件正在播放。

我尝试过以下方法,但没有成功:

在play()函数的while循环中调用回调函数,但我不知道需要传递哪个参数

事件

(Matlab总是告诉我它不知道缺少命令或参数)或者这是否有用

在runStartupFcn()中执行play()函数,但此函数在显示图形用户界面之前执行,这当然是无用的

据我所知,我不能在其他地方添加函数

所以现在的问题是:我能让应用程序实时工作吗?

我期待着你的回答!

 类似资料: