sound is coming after the picture has disappeared

1 view (last 30 days)
Hi
The sound is still coming up though the picture has disappeared. I want the sound to be there as long as the picture is displayed. How can I manage that? :)
function welcome()
img=imread('Borehole_collapse_ny.png');
image(img);
x=0;
y=0;
width=1.0 ;% measured relative to the figure width
height=1.0; % measured relative to figure height
set(gca, 'units', 'normalized','position',[x y width height])
n=5;
x=rand(1,7000);
sound(x,8000);
pause(n);
close
end
  2 Comments
KSSV
KSSV on 11 Mar 2022
You can clear the signal used in sound to stop it.
Muazma Ali
Muazma Ali on 11 Mar 2022
I didnt understand it; clear by writing what and where..?

Sign in to comment.

Answers (1)

Jan
Jan on 11 Mar 2022
Edited: Jan on 11 Mar 2022
x = (rand(1, 70000) - 0.5) * 0.1;
sound(x, 8000);
pause(1)
clear('sound'); % Undocumented
The sound() command calls the modern audioplayer internally. So it is cleaner to use it directly:
a = audioplayer(x, 8000, 16);
play(a)
pause(1);
stop(a)

Community Treasure Hunt

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

Start Hunting!