miniAudicleを使った習作。

http://sites.google.com/site/kn1kn1pages/Home/20090320.mp3?attredirects=0

=>演算子が楽しい。ファイルの相対パスの記述のやり方がまだ分からず…

1::minute / 120 => dur DUR_4BEAT;
DUR_4BEAT * 4 => dur DUR_BAR;
DUR_BAR - (now % DUR_BAR) => now;
DUR_4BEAT / 4 => dur DUR_16BEAT;

Gain g => dac;
//Gain g => WvOut w => blackhole;
//"20090320.wav" => w.wavFilename;
.8 => g.gain;
SndBuf k => g;
"/Applications/miniAudicle/documentation/examples/data/kick.wav"
 => k.read;
SndBuf h => g;
"/Applications/miniAudicle/documentation/examples/data/hihat.wav"
 => h.read;
SinOsc s => ADSR e => JCRev r => g;
(0::ms, 100::ms, .5, 20::ms) => e.set;
.1 => r.mix;
[0, 3, 7, 10] @=> int NOTES[];

float freq[];
int sine[];
int hat[];
int kick[];

// time loop
for (0 => int count;;1 +=> count) {
    count % 16 => int i;
    if ((count / 16) == 16) {
        break;
    }
    if ((count / 16) % 4 == 0) {
        (16, NOTES) => notes2freqs @=> freq;
        (16, 0, 1) => rands @=> sine;
        (16, 0, 1) => rands @=> hat;
        (16, 0, 1) => rands @=> kick;
    }
    freq[i] => s.freq;
    sine[i] * .4 => s.gain;
    0 => h.pos;
    hat[i] * .3 => h.gain;
    0 => k.pos;
    kick[i] * .4 => k.gain;
    if (i == 0) {
        .8 => k.gain;
    }
    if (i == 3) {
        .8 => k.gain;
    }
    e.keyOn();
    DUR_16BEAT => now;
}
//w.closeFile();

fun float[] notes2freqs(int size, int notes[]) {
    float freqs[size];
    for (0 => int i; i < size; i++) {
        (Std.rand2(0, 1) * 11 + 60
        + notes[Std.rand2(0, notes.cap() - 1)])
        => Std.mtof => freqs[i];
    }
    return freqs;
}

fun int[] rands(int size, int from, int to) {
    int rands[size];
    for (0 => int i; i < size; i++) {
        Std.rand2(from, to) => rands[i];
    }
    return rands;
}