How to stop playback with soundsc() in MATLAB?

63 次查看(过去 30 天)
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);

标签

Community Treasure Hunt

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

Start Hunting!

Translated by