一応アルゴリズムの課題完成

これでとりあえず終了。

・完成品
http://oku.edu.mie-u.ac.jp/~e204350/source/out.wav

import java.io.*;

class MakeWave {
    BufferedOutputStream out;
    void putShort(short x) throws IOException {
        out.write(x);  out.write(x >>> 8);
    }
    void putInt(int x) throws IOException {
        out.write(x);  out.write(x >>> 8);  
        out.write(x >>> 16);  out.write(x >>> 24);
    }
    public MakeWave(String filename, short wav) throws IOException {
        out = new BufferedOutputStream
              (new FileOutputStream(filename));
        out.write('R');  out.write('I');  
        out.write('F');  out.write('F');
        putInt(wav.length * 2 + 44 - 8);  // filesize - 8
        out.write('W');  out.write('A');  
        out.write('V');  out.write('E');
        out.write('f');  out.write('m');  
        out.write('t');  out.write(' ');
        putInt(16);          // always 16
        putShort((short)1);  // PCM:1
        putShort((short)1);  // channels (1 or 2)
        putInt(44100);       // sampling freq
        putInt(44100 * 2);   // sampling freq * 2 * channels
        putShort((short)2);  // channels * 2
        putShort((short)16); // bits/sample
        out.write('d');  out.write('a');
        out.write('t');  out.write('a');
        putInt(wav.length * 2);  // data size
        for (int i = 0; i < wav.length; i++)
            putShort(wav[i]);
        out.close();
    }        
    public static void main(String args) throws IOException{
        double k = 2 * Math.PI / 44100;
        double c = 440 * Math.pow(2, 3.0/12.0); // 「ド」の音
        double e, g, h, j, l;

        /* 音の定義 */
            e = c * Math.pow(2, 2.5/12.0); // 「レ」の音
            g = c * Math.pow(2, 4.0/12.0); // 「ミ」の音
            h = c * Math.pow(2, 5.5/12.0); // 「ファ」の音
            j = c * Math.pow(2, 7.0/12.0); // 「ソ」の音
            l = c * Math.pow(2, 8.5/12.0); // 「ラ」の音
        /* 音の定義終わり */

        short[] wav = new short[44100*2];
        for (int i = 0; i < 44100/6 ; i++)
            wav[i] = (short)(10000 * Math.sin(k * c * i));
        for (int i = 44100/6; i < 2 * 44100/6; i++)
            wav[i] = (short)(10000 * Math.sin(k * e * i));
        for (int i = 2 * 44100/6; i < 3 * 44100/6; i++)
            wav[i] = (short)(10000 * Math.sin(k * g * i));
        for (int i = 3 * 44100/6; i < 4 * 44100/6; i++)
            wav[i] = (short)(10000 * Math.sin(k * h * i));
        for (int i = 4 * 44100/6; i < 44100; i++)
            wav[i] = (short)(10000 * Math.sin(k * j * i));
        for (int i = 44100; i < 44100 + 44100/6; i++)
            wav[i] = (short)(10000 * Math.sin(k * l * i));
        for (int i = 44100 + 44100/6; i < 44100 + 2 *44100/6; i++)
            wav[i] = (short)(10000 * Math.sin(k * h * i));
        for (int i = 44100 + 2 * 44100/6; i < 44100 + 25725; i++)
            wav[i] = (short)(10000 * Math.sin(k * g * i));
        for (int i = 44100 + 25725; i < 44100 + 5 * 44100/6; i++)
            wav[i] = (short)(10000 * Math.sin(k * e * i));
        for (int i = 45100 + 5 * 44100/6; i < 2 * 44100; i++)
            wav[i] = (short)(10000 * Math.sin(k * c * i));
        new MakeWave("out.wav", wav);
    }
}

音のところもっと短縮できるはず。
当然部分点狙い。