How can I sound two signals without them overlapping?

조회 수: 12 (최근 30일)
Ima Bootface
Ima Bootface 2015년 5월 3일
답변: Dante Ruiz 2020년 6월 15일
Basically I've got two signals I want to sound using the sound(x,Fs) function. Is there any way that I can have the second sound() wait until the first one has finished before playing?

답변 (3개)

Dante Ruiz
Dante Ruiz 2020년 6월 15일
y=audioplayer(S1,Fs);
playblocking(y); % Same as play, but does not return control until playback completes.
sound(S2,Fs); % Play Second Sound

Star Strider
Star Strider 2015년 5월 3일
See if this illustration does what you want:
Fs = 8192; % Sampling Frequency
Len = 2.5; % Length Of Sound (s)
t = linspace(0, 100*pi, fix(Len*Fs)); % Length = 2.5s
S1 = sin(t) + sin(5*t) + sin(15*t);
S2 = sin(15*t) + sin(21*t) + sin(31*t);
soundsc(S1,Fs) % Play First Sound
pause(2.5) % Wait For First Sound To Finish
soundsc(S2,Fs) % Play Second Sound

Chad Greene
Chad Greene 2015년 5월 3일
You can call sound twice or you can combine the signals. Here's both methods:
tr = load('train');
la = load('laughter');
% play train:
sound(tr.y,tr.Fs)
% then play laughter:
sound(la.y,la.Fs)
% Or, combine arrays:
combined = [tr.y;la.y];
% wait 1.2 seconds:
pause(1.2)
sound(combined,la.Fs)
The pause command is optional--it insets time after the sound before it finishes playing.
  댓글 수: 1
Matt Allen
Matt Allen 2020년 1월 31일
The first example actually does not work in Matlab 2019b. The sounds are played at the same time (at least they are on my system in Windows 10). Good idea about just combining the vectors though. Seems like there should be another way, for example using pause or something, but I haven't been able to do it.

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

카테고리

Help CenterFile Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by