wav-波形データ 1.音に限らず全ての波はある位置に於いて、時刻tと波の変位yの2次元で表せる。1.1 wav(正確にはriffのこと)は時刻t=0,冲,2冲,3冲,・・・におけるyの記録。 1.2 8bitのwavに於いては変位yは128を基準(無音)として0〜255の範囲とする。 txt2wavではこのyを","(半角カンマ)で区切って入力してwavを作成することができる。(但しIEでは動かない) 2.入力する数値yを求める。 testHTMLにおいて以下のスクリプトを実行をさせる。
<body> <script> document.open(); for(t=0;t<Math.PI*80;t+=0.1){ document.write(Math.floor(128+127*Math.sin(t)),","); } document.close(); </script>
先のページの上の四角枠にコピペしてマウスで右クリックをすると、 下に入力すべきyの記録が表示される。 このコードではt=0, 0.1, 0.2,・・・, Math.PI*80 (Math.PIは円周率) について128+127*Math.sin(t)を計算し(Math.sinは正弦関数)、","を添えて出力している。 3.正弦波 3.1 先の2.での例のyは一定の周期の波であるから1つの音のみが出る。 3.2 複数の正弦波を足し合わせると複雑な音がでる。<body> <script> document.open(); for(t=0;t<Math.PI*80;t+=0.1){ document.write(Math.floor(128+127*(Math.sin(t)+Math.sin(2*t)+Math.sin(3*t))/3),","); } document.close(); </script>
これはsin(t)+sin(2t)+sin(3t)であるが、和音となる。 3.3 うなり 3.31 3.2も広く言えばうなりであるが、もっと近い正弦波を足し合わせてみる。 例)sin(50t)+sin(51t)<body> <script> document.open(); for(t=0;t<Math.PI*80;t+=0.1){ document.write(Math.floor(128+127*(Math.sin(50*t)+Math.sin(51*t))/2),","); } document.close(); </script>
また、加法定理を用いれば sin(50t)+sin(51t)=2sin(50.5t)・cos(0.5t) 3.4 徐々に変化させる(サイレンとか警報とかのそれに近い)。<body> <script> document.open(); for(z=0.1;z<5;z+=0.1){ for(t=0;t<Math.PI*10;t+=0.1){ document.write(Math.floor(128+127*(Math.sin(z*t))),","); } } document.close(); </script>
3.5 減衰(フェードアウト)させる。なんかバネっぽい。<body> <script> document.open(); for(z=0;z<10;z+=0.1){ for(t=0;t<Math.PI*6;t+=0.1){ document.write(Math.floor(128+127*Math.sin(2*t)*Math.exp(-z)),","); } } document.close(); </script>
Math.expはeのべき乗関数である。 Math.exp(-z)はzが0から大きくなるにつれて、1から0に近づく。 これを通常の正弦波に掛け合わせ再現する。