14 may. 2009

Pulses

// PULSES

// By: Jorge Rangel - http://blog.jrangel.net - jarg1985[at]gmail[dot]com - Main code

// Licence
// Creative Commons NC-BY-SA 3.0

[48, 50, 52, 55, 57, 60, 62, 64, 67, 69] @=> int melodynotes[];
[24, 26, 28, 31, 33, 36, 38, 40, 43, 45] @=> int bassnotes[];

// Mono channel stuff...

SinOsc a;
SinOsc b;
JCRev rev;
ADSR adsr;

adsr.set (250::ms, 50::ms, 1, 100::ms);

rev.mix (0.4);
rev.gain (0.2);

a.gain (0.3);
b.gain (0.5);

a => adsr => rev => dac;
b => dac;

fun void notes()
{
    if ( Std.rand2f(0,1) < 0.6 )
    {
        adsr.keyOff();
        Std.mtof(melodynotes[Std.rand2(0,melodynotes.cap()-1)]) => a.freq;
        adsr.keyOn();
    }
}

fun void bass()
{
    if ( Std.rand2f(0,1) < 0.6 )
    {
        Std.mtof(bassnotes[Std.rand2(0,bassnotes.cap()-1)]) => b.freq;
    }
}

fun void melodyloop()
{
    while (true)
    {
        notes();
        250::ms => now;
    }
}

fun void bassloop()
{
    while (true)
    {
        bass();
        500::ms => now;
    }
}

// Left channel stuff...

SinOsc aleft;
SinOsc bleft;
JCRev revleft;
ADSR adsrleft;

adsrleft.set (500::ms, 50::ms, 1, 250::ms);

revleft.mix (0.3);
revleft.gain (0.2);

aleft.gain (0.7);
bleft.gain (0.1);

aleft => adsrleft => revleft => dac.left;
bleft => dac.left;

fun void notesleft()
{
    if ( Std.rand2f(0,1) < 0.6 )
    {
        adsrleft.keyOff();
        Std.mtof(melodynotes[Std.rand2(0,melodynotes.cap()-1)]) => aleft.freq;
        adsrleft.keyOn();
    }
}

fun void bassleft()
{
    if ( Std.rand2f(0,1) < 0.6 )
    {
        Std.mtof(bassnotes[Std.rand2(0,bassnotes.cap()-1)]) => bleft.freq;
    }
}

fun void melodyloopleft()
{
    while (true)
    {
        notesleft();
        500::ms => now;
    }
}

fun void bassloopleft()
{
    while (true)
    {
        bassleft();
        1000::ms => now;
    }
}

// Right channel stuff

SinOsc aright;
SinOsc bright;
JCRev revright;
ADSR adsrright;

adsrright.set (500::ms, 50::ms, 1, 250::ms);

revright.mix (0.3);
revright.gain (0.2);

aright.gain (0.7);
bright.gain (0.1);

aright => adsrright => revright => dac.right;
bright => dac.right;

fun void notesright()
{
    if ( Std.rand2f(0,1) < 0.6 )
    {
        adsrright.keyOff();
        Std.mtof(melodynotes[Std.rand2(0,melodynotes.cap()-1)]) => aright.freq;
        adsrright.keyOn();
    }
}

fun void bassright()
{
    if ( Std.rand2f(0,1) < 0.6 )
    {
        Std.mtof(bassnotes[Std.rand2(0,bassnotes.cap()-1)]) => bright.freq;
    }
}

fun void melodyloopright()
{
    while (true)
    {
        notesright();
        500::ms => now;
    }
}

fun void bassloopright()
{
    while (true)
    {
        bassright();
        1000::ms => now;
    }
}

spork ~ melodyloop();
spork ~ bassloop();
spork ~ melodyloopleft();
spork ~ bassloopleft();
spork ~ melodyloopright();
spork ~ bassloopright();

while (true) 60::second => now;

// Pretty cool soundz, uh?

No hay comentarios:

Publicar un comentario