Multiple sounds played simultaneously

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

Community Treasure Hunt

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

Start Hunting!

Translated by