Created
March 4, 2019 21:06
-
-
Save mrfarhadir/4deba658aa11092fc13a2efac22135e4 to your computer and use it in GitHub Desktop.
Soltan Qalbha song with matlab
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 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