how can i play sounds in specific order with specific durations

24 ビュー (過去 30 日間)
Giovanni Azar
Giovanni Azar 2021 年 11 月 30 日
コメント済み: Spectro 2021 年 12 月 1 日
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?

回答 (1 件)

Spectro
Spectro 2021 年 11 月 30 日
編集済み: Spectro 2021 年 11 月 30 日
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 件のコメント
Giovanni Azar
Giovanni Azar 2021 年 11 月 30 日
the duration should change each time according to the note that is playing from the list
Spectro
Spectro 2021 年 12 月 1 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAudio and Video Data についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by