Multiple sounds played simultaneously

9 views (last 30 days)
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!

Accepted Answer

Walter Roberson
Walter Roberson on 16 Mar 2020
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.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!