matlab 音频编辑器,在Matlab中使用App Designer可以进行实时音频处理吗?
我想用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為圖形用戶界面生成的函數。我添加了一些屬性,其中包含輸入增益、截止值等的值,以及執(zhí)行信號處理的play()函數。
我可以運行應用程序,按下播放按鈕,聽到正在播放的音頻文件,但當我改變截止頻率,例如,沒有改變。我想這是因為當按下play按鈕時,我在回調函數中執(zhí)行play()函數,因此在另一個按鈕完成之前,不能執(zhí)行切斷旋鈕時的回調函數。
當我第一次更改參數,然后按播放,一切都是正確的,除了我不能改變參數時,文件正在播放。
我嘗試過以下方法,但沒有成功:
在play()函數的while循環(huán)中調用回調函數,但我不知道需要傳遞哪個參數
事件
(Matlab總是告訴我它不知道缺少命令或參數)或者這是否有用
在runStartupFcn()中執(zhí)行play()函數,但此函數在顯示圖形用戶界面之前執(zhí)行,這當然是無用的
據我所知,我不能在其他地方添加函數
所以現在的問題是:我能讓應用程序實時工作嗎?
我期待著你的回答!
總結
以上是生活随笔為你收集整理的matlab 音频编辑器,在Matlab中使用App Designer可以进行实时音频处理吗?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PQIBrowser.exe是什么进程
- 下一篇: PQIMountSvc.exe是什么进程