Envelope

2003/8/23 平野拓一（東京工業大学）
2003/8/23 Takuichi Hirano (Tokyo Institute of Technology)

１周期の波形を作る

[入力パラメータ]
smprate: wave ファイルのサンプリングレート
freq: 音の周波数

smprate = 22050;
freq = (27.5*(2^3))*((((2^((1/12)))))^3);
t = (1/freq);
n1 = Floor[(t/1)*smprate]*1;
WaveFormSin2 = 
        Table[(2^15)*Sin[2*π*freq*(t/n1)*(i - 1)], {i, 1, 
            n1}];
TimeWaveFormSin = 
        Table[{i, WaveFormSin2[[i]]}, {i, 1, 
            n1}];
ListPlot[
      TimeWaveFormSin, 
ImageSize -> {160, 
          120}, 
PlotJoined -> 
        True, 
PlotStyle -> {AbsoluteThickness[2], 
          RGBColor[1, 0, 0]}, 
PlotRange -> 
        All, 
Ticks -> 
        None, 
Frame -> 
        True, 
FrameTicks -> 
        None, 
FrameLabel -> {"Time", "Amplitude\
", "", ""}]

１周期をいくつも並べて周期波形を作り、音を聴いてみる

freq = 440*((((2^((1/12)))))^3);
t = (1/freq)*1;
dur = 1.0;
n2 = Ceiling[dur/t];
WaveFormSin3 = 
        Flatten[Table[
            WaveFormSin2, {i, 1, n2}]];
ListPlay[WaveFormSin3, SampleRate -> 22050, 
        PlayRange -> {-(2^16), (2^16)}];

波形を選ぶ

WaveForm3 = WaveFormSin3;

エンベロープを作る

[Reference]
Roland SC-88 VL, 取扱説明書, p.21

AttackTime = 0.2*dur;
DecayTime = 
        0.2*dur;
RelaseTime = 
        0.2*dur;
AttackLevel = 
        1;
SustainLevel = 0.7;

decayFunc[n_, a_, t1_, t_] := 
            (a/(((Cos[t1] - 1))^n))*(((Cos[t] - 1))^n);      

envelope[t_] := 
        (AttackLevel/AttackTime)*t  /;  
          0 ≤ t < AttackTime;
envelope[
          t_] := decayFunc[2, AttackLevel - SustainLevel, 1, 
              (1/DecayTime)*(t - (AttackTime + DecayTime))] + 
            SustainLevel  /;  
          AttackTime ≤ 
            t < (AttackTime + 
                DecayTime);
envelope[t_] := 
        SustainLevel  /;  (AttackTime + DecayTime) ≤ 
            t < (dur - RelaseTime);
envelope[
          t_] := decayFunc[2, SustainLevel, 1, 
            (1/RelaseTime)*(t - dur)]  /;  (dur - 
                RelaseTime) ≤ t < dur;
envelope[t_] := 0;

EnvelopeForm3 = 
            Table[envelope[(1/(n1*n2))*(i - 1)], {i, 1, n1*n2}];;

\(Plot[
        envelope[t], {t, 0, 
          dur}, 
ImageSize -> {160, 
            120}, 
PlotRange -> {0, 
            1.5*Max[AttackLevel, 
                SustainLevel]}, 
PlotStyle -> {RGBColor[1, 0, 1], 
            AbsoluteThickness[
              2]}, 
Epilog -> {{Dashing[{0.02, 0.02}], 
              Line[{{AttackTime, 0}, {AttackTime, 
                    AttackLevel}}]}, 
{Dashing[{0.02, 
                  0.02}], 
              Line[{{AttackTime + DecayTime, 0}, {AttackTime + DecayTime, 
                    SustainLevel}}]}, 
{Dashing[{0.02, 
                  0.02}], 
              Line[{{dur - RelaseTime, 0}, {dur - RelaseTime, 
                    SustainLevel}}]}, 
{Dashing[{0.02, 
                  0.02}], 
              Line[{{0, SustainLevel}, {AttackTime + DecayTime, 
                    SustainLevel}}]}, 
{Dashing[{0.02, 
                  0.02}], 
              Line[{{0, AttackLevel}, {AttackTime, 
                    AttackLevel}}]}}, 
Frame -> 
          True, 
FrameTicks -> {{{0, "Note On"}, {1, "Note Off"}}, {}, {}, {}}, 
FrameLabel -> {"Time", "Envelope", "", ""}
];\)
ListPlot[
      EnvelopeForm3, 
ImageSize -> {160, 
          120}, 
PlotJoined -> 
        True, 
PlotStyle -> {AbsoluteThickness[2], 
          RGBColor[1, 0, 0]}, 
PlotRange -> 
        All, 
Ticks -> 
        None, 
Frame -> 
        True, 
FrameTicks -> 
        None, 
FrameLabel -> {"Time", "Amplitude\
", "", ""}]

エンベロープをかける

WaveForm4 = EnvelopeForm3*WaveForm3;

ListPlay[WaveForm4, SampleRate -> 22050, 
        PlayRange -> {-(2^16), (2^16)}];

\(ListPlot[
      WaveForm4, 
ImageSize -> {160, 
          120}, 
PlotRange -> {\(-2^16\), 
          2^16}, 
PlotJoined -> 
        True, 
PlotStyle -> {RGBColor[1, 0, 1], 
          AbsoluteThickness[2]}, 
Ticks -> 
        None, 
Frame -> 
        True, 
FrameTicks -> {Table[{Round[
                Length[WaveForm4]*i], i}, {i, 0, 1, 
              0.2}], {}, {}, {}}, 
FrameLabel -> {"Relative time", "Relative amplitude", "", ""}]\)