Azzera filtri
Azzera filtri

how can i play sounds in specific order with specific durations

24 visualizzazioni (ultimi 30 giorni)
i need to let matlab play the happy birthday song. i already downloaded all the notes as wav files and i also put them in order in a list with the order of the duration.
duration=[0.5, 0.5, 1, 1, 1, 2, 0.5, 0.5, 1, 1, 1, 2, 0.5, 0.5, 1, 1, 1, 1, 3, 0.5, 0.5, 1, 1, 1, 2];
song=[si,si,do,si,mi,re,si,si,do,si,fa,mi,si,si,si,sol,mi,re,do,la,la,sol,mi,fa];
for exemple i need to play the note (si) first with a duration of (0.5 sec).
can anyone help?

Risposte (1)

Spectro
Spectro il 30 Nov 2021
Modificato: Spectro il 30 Nov 2021
Use a forcycle to run through all the notes with the appropriate durations using audioread. Also adjust each sound vector in dependence on the duration. See the idea below:
for i = 1:length(song)
% Load the note
[y, fs] = audioread('yourNote.wav');
% Example of y2 for halft the duration (0.5)
n = length(y);
y2 = y(1:fix(n*0.5), :);
% Play it
soundsc(y2, fs);
end
  3 Commenti
Giovanni Azar
Giovanni Azar il 30 Nov 2021
the duration should change each time according to the note that is playing from the list
Spectro
Spectro il 1 Dic 2021
The code was just a clue to lead you on. In that loop, you have to load the specific note in each iteration and adjust its playing duration. It's playing with the indexes. You already have an example for 0.5.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by