Borrar filtros
Borrar filtros

How to stop playback with soundsc() in MATLAB?

30 visualizaciones (últimos 30 días)
Matlab Student
Matlab Student el 16 de Mayo de 2016
Respondida: Image Analyst el 18 de Mayo de 2016
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?

Respuestas (2)

Walter Roberson
Walter Roberson el 16 de Mayo de 2016
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 comentarios
Matlab Student
Matlab Student el 17 de Mayo de 2016
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 el 18 de Mayo de 2016
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));

Iniciar sesión para comentar.


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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by