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?
0 个评论
回答(2 个)
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 个评论
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
2016-5-18
Don't use soundssc(). To it this way:
player = audioplayer(yShort, Fs);
play(player);
The, to stop it:
stop(player);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio and Video Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!