Play, Stop, Pause, Resume and Volume control in Real-Time with Audio System Toolbox

조회 수: 26 (최근 30일)
So I am designing a GUI for an equalizer and have just made the buttons and sliders mentioned in the title. The thing is that I tried to make this with audioplayer's objects. The problem is that with the code that I am attaching this doesn't work in real-time. I read about Audio System Toolbox for this matter and I think I can play and stop audio without any problem, but I really can't think of a way to pause and resume and to chnge the volume with a slider in real-time. I hope soeone could guide me about this matter. I attach the code I used. Play, Stop, Puse, Resume:
properties (Access = private)
Property % Description
fileName
player
end
methods (Access = private)
% Value changed function: PauseButton
function PauseButtonValueChanged(app, event)
value = app.PauseButton.Value;
pause(app.player);
end
% Value changed function: PlayButton
function PlayButtonValueChanged(app, event)
value = app.PlayButton.Value;
try
[y, Fs] = audioread(app.fileName);
app.player=audioplayer(app.Volume.Value*y,Fs);
% Play audio
play(app.player)
catch ME
uiwait(msgbox('Could not open that file with Audioread'));
end
end
% Value changed function: ResumeButton
function ResumeButtonValueChanged(app, event)
value = app.ResumeButton.Value;
try
resume(app.player);
catch ME
uiwait(msgbox('Could not open that file with Audioread'));
end
end
% Value changed function: StopButton
function StopButtonValueChanged(app, event)
value = app.StopButton.Value;
try
stop(app.player);
catch ME
uiwait(msgbox('Could not open that file with Audioread'));
end
end
And for the volume:
function VolumeValueChanged(app, event)
valueVol = app.Volume.Value;
pause(app.player);
NewStart=get(app.player,'CurrentSample')+1;
stop(app.player);
[x, Fs] = audioread(app.fileName);
x=x(NewStart:end,:);
app.player=audioplayer(x*valueVol,Fs);
play(app.player);
I didn't include the code for the browser because it just opens the path of the file.

답변 (1개)

Ayush Bansal
Ayush Bansal 2020년 9월 1일
A function to control audio volume directly is not available in MATLAB .
Workaround would be controlling system volume in the callback function.

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by