필터 지우기
필터 지우기

How to stop playback with soundsc() in MATLAB?

조회 수: 31 (최근 30일)
Matlab Student
Matlab Student 2016년 5월 16일
답변: Image Analyst 2016년 5월 18일
I am currently working on an equalizer, and I want playback to stop at the click of a button.I have experimented with the audiorecorder method, but unlike soundsc, audiorecorder objects do not play at the maximum possible amplitude (without distortion).How can I either stop playback initiated from a soundsc() command or use audiorecorder in a way similar to soundsc?

답변 (2개)

Walter Roberson
Walter Roberson 2016년 5월 16일
soundsc() cannot be stopped.
To play a sound at the maximum possible amplitude like soundsc does, you should use
centered_x = x - repmat(mean(x), size(x,1), 1);
maxx = max(abs(centered_x(:));
scaled_centered_x = centered_x ./ maxx;
Now you can use audioplayer's play() method on scaled_centered_x .
Note that when you are building an equalizer, you do not want your sound to be continually readjusting its volume. Suppose, for example that one of the performers is tuning their guitar: you do not want the tuning plucks to be automatically full volume. You should only be doing this kind of automatic scaling on completed sounds that have the entire dynamic range represented.
  댓글 수: 2
Matlab Student
Matlab Student 2016년 5월 17일
Works like a charm! Could you please explain how this works? Especially the
centered_x = x - repmat(mean(x), size(x,1), 1);
Walter Roberson
Walter Roberson 2016년 5월 18일
That code is just subtracting off the mean to center around 0, to match the behaviour of soundsc which does that. It is complicated because I did not assume that there is only one channel. Another approach would have been
centered_x = bsxfun(@minus, x, mean(x));

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


Image Analyst
Image Analyst 2016년 5월 18일
Don't use soundssc(). To it this way:
player = audioplayer(yShort, Fs);
play(player);
The, to stop it:
stop(player);

카테고리

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