필터 지우기
필터 지우기

How to reset or close sound() player?

조회 수: 2 (최근 30일)
J. McCabe
J. McCabe 2017년 1월 18일
답변: J. McCabe 2017년 1월 20일
I have a script with two calls to the soundsc() function in Matlab. The first plays an array of samples, the second plays a modified array for comparison. However, only the first is played. I assume I need to close or reset the soundsc() player between subsequent calls, but can't find anything on how to do that. I tried
clear playsnd
clear sound
but neither works.
Anyone know what I'm doing wrong? Thanks.
  댓글 수: 1
Jan
Jan 2017년 1월 18일
편집: Jan 2017년 1월 18일
Please post the relevant code. There is no need to "clear" a builtin command. There must be another reason for the observed behavior.

댓글을 달려면 로그인하십시오.

채택된 답변

J. McCabe
J. McCabe 2017년 1월 20일
After some research I figured the answer to the question. Apparently,subsequent calls to 'sound' or 'soundsc' are executed asynchronously, which means if you have
sound(x)
sound(y)
in your script, both will be executed virtually simultaneously. One way to get around that is to insert a 'pause()' after the first call, and set the pause value at > the time it takes to play the first 'sound()':
sound(x)
pause(5)
sound(y)

추가 답변 (1개)

Jan
Jan 2017년 1월 18일
Perhaps the modern audioplayer can help you.
  댓글 수: 1
J. McCabe
J. McCabe 2017년 1월 18일
Thanks, I appreciate the help. The reason I like the soundsc() function over the audioplayer is it automatically scales the magnitude between -1 to +1, and also it seems (IMO at least) a bit more messy to have to instantiate an audioplayer if I'm just playing some sine waves. What I ended up doing is just
z = horzcat(x,y);
soundsc(z,3600);
That seems to work fine. BTW, I did try to set up two audioplayers for the signals and play sequentially, but it still only played one signal. The horzcat played both. Wierd...

댓글을 달려면 로그인하십시오.

카테고리

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