Play, Stop, Pause, Resume and Volume control in Real-Time with Audio System Toolbox
17 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
0 commentaires
Réponses (1)
Voir également
Catégories
En savoir plus sur Audio and Video Data dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!