Skip to content

Instantly share code, notes, and snippets.

@mrfarhadir
Created March 4, 2019 21:06
Show Gist options
  • Save mrfarhadir/4deba658aa11092fc13a2efac22135e4 to your computer and use it in GitHub Desktop.
Save mrfarhadir/4deba658aa11092fc13a2efac22135e4 to your computer and use it in GitHub Desktop.
Soltan Qalbha song with matlab
% play piano with matlab
% "soltan qalba" ha song
% author: Farhad Mehryari
notecreate = @(frq,dur,v) sin(2*pi* [1:dur]/v * (440*2.^((frq-1)/12)));
notename = {'A' 'A#' 'B' 'C' 'C#' 'D' 'D#' 'E' 'F' 'F#' 'G' 'G#'};
song = {'A' 'B' 'C' 'E' 'F' 'E' 'F' 'E' 'F' 'E' 'D' 'E' 'D' 'E' 'D' 'E' 'D' 'C' 'D' 'C' 'D' 'C' 'B' 'A' 'A' 'B'};
durations = [1 1 1 3 1 2 1 2 1 1 1 1 2 1 2 1 1 1 1 2 1 2 1 2 1 0.5 1]
for k1 = 1:length(song)
if (string(song(k1)) == '0')
songidx(k1) = 0
continue
end
idx = strcmp(song(k1), notename);
songidx(k1) = find(idx);
end
dur = 0.4*8192;
songnote = [];
for k1 = 1:length(songidx)
songidx(k1);
songnote = [songnote; [notecreate(songidx(k1),dur*durations(k1),8192) zeros(1,75)]'];
end
for k1 = 1:length(songidx)
songidx(k1);
songnote = [songnote; [notecreate(songidx(k1),dur*durations(k1),5028) zeros(1,75)]'];
end
soundsc(songnote, 8192)
% author: Farhad Mehryari
% web: blog.mrfarhad.ir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment