Doremi (等差数列)

Takuichi Hirano

周波数を求める関数

[Input]
オクターブ
音 (c,c#,d,d#,e,f,f#,g,g#,a,a#,b)

FreqDoReMi[Octave_, ABCTone_] := 
        Module[{d}, 
NumTone = 
            Which[
ABCTone == "A"  ||  
                ABCTone == "a", 
              0, 
ABCTone == "A#"  ||  
                ABCTone == "a#", 
              1, 
ABCTone == "B"  ||  
                ABCTone == "b", 
              2, 
ABCTone == "C"  ||  
                ABCTone == "c", 
              3, 
ABCTone == "C#"  ||  
                ABCTone == "c#", 
              4, 
ABCTone == "D"  ||  
                ABCTone == "d", 
              5, 
ABCTone == "D#"  ||  
                ABCTone == "d#", 
              6, 
ABCTone == "E"  ||  
                ABCTone == "e", 
              7, 
ABCTone == "F"  ||  
                ABCTone == "f", 
              8, 
ABCTone == "F#"  ||  
                ABCTone == "f#", 
              9, 
ABCTone == "G"  ||  
                ABCTone == "g", 
              10, 
ABCTone == "G#"  ||  
                ABCTone == "g#", 
              11]; 
d = (27.5*(2^Octave))/
              12; 
(27.5*(2^Octave)) + d*NumTone  // 
            N
];

dt = 0.5;
Pulse[t1_, dt_, t_] := 
        UnitStep[t - t1] - 
          UnitStep[t - (t1 + dt)];
ω[1] = 
        2*π*FreqDoReMi[4, "c"];
ω[2] = 
        2*π*FreqDoReMi[4, "d"];
ω[3] = 
        2*π*FreqDoReMi[4, "e"];
ω[4] = 
        2*π*FreqDoReMi[4, "f"];
ω[5] = 
        2*π*FreqDoReMi[4, "g"];
ω[6] = 
        2*π*FreqDoReMi[5, "a"];
ω[7] = 
        2*π*FreqDoReMi[5, "b"];
ω[8] = 
        2*π*FreqDoReMi[5, "c"];
wave[t_] := 
        Sum[Sin[ω[i]*t]*Pulse[dt*(i - 1), dt, t], {i, 1, 
            8}];
Play[
      wave[t], {t, 0, dt*8}, 
SampleRate -> 
        44100, 
SampleDepth -> 
        16, 
PlayRange -> {-2, 2}]