Multiple sounds played simultaneously

조회 수: 5 (최근 30일)
Erika Dubajova
Erika Dubajova 2020년 3월 16일
댓글: Erika Dubajova 2020년 3월 16일
I have 2 or 3 sounds played in GUI by button. When I push it for the first time sounds aren´t simultaneous.
But when I push the same button for the second time(without closing the app), sounds play at once.
Can anybody tell me why and help me to fix it? I want them to be played at once from the first push.
This is part of my code.. may help.
function HraButton_3Pushed(app, event)
load gong.mat;
fs = 8000;
dt = 1/fs;
t = (0:dt:1);
y1 = sin(2*pi*b1*t);
y2 = sin(2*pi*b2*t);
y3 = sin(2*pi*b3*t); %b1,b2,b3 are some selected frequencies
sound(y1,fs)
sound(y2,fs)
sound(y3,fs)
end
Thank youuuu!

채택된 답변

Walter Roberson
Walter Roberson 2020년 3월 16일
sound() never guarantees synchronization.
The first time in a session that you use sound(), it takes time to initialize and start playing. The second time, some of the initialization is already done.
You should be using a single sound() call with the mean() of all of the tones you want to play at the same time.

추가 답변 (0개)

카테고리

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