Multiple sounds played simultaneously
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Erika Dubajova
le 16 Mar 2020
Commenté : Erika Dubajova
le 16 Mar 2020
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!
0 commentaires
Réponse acceptée
Walter Roberson
le 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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Audio and Video Data dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!