Midi sampler

From: Tobiah (toby@rcsreg.com)
Date: Sun Jul 16 2000 - 17:17:51 EDT


Here is an orchestra that I made that makes it easy to
turn your midi keyboard into a sample player. You have
to load it with AIFF samples that have base frequencies
and loop points, or set them explicitly with the ft opcodes.
I thought someone might have fun with it. Also I was hoping
for suggestions on how to do it more cleanly, and perhaps
cut down on latency.

Btw, I seems curious that 'loscil' would default to looping
the entire sample when the loop points are not defined. This
makes it inconvenient at best to get single play samples (guitar
marimba etc. ) to play just once. 'doscil' doesn't correct pitch,
so that won't do. If there was a case (I can't think of one) where
the entire sample should loop, then it would be easy to set the
loop points in that sample to 0 and ftlen(t). I guess that I
could set my loop points to ftlen(t), ftlen(t), but I am afraid
that my sample may not end on a zero sample, and then I would
introduce DC offset, and I think that the other behavior makes
more sense anyway.

Thanks,

Tobiah

//***************************

ksig relenv;
asig bus;

//***** LOAD 9 AIFF SAMPLES WITH BASEFS *****//
table e(sample, -1, "e.aiff");
table a(sample, -1, "a.aiff");
table d(sample, -1, "d.aiff");
table g(sample, -1, "g.aiff");
table b(sample, -1, "b.aiff");
table e2(sample, -1, "e2.aiff");
table a2(sample, -1, "a2.aiff");
table e3(sample, -1, "e3.aiff");
table b2(sample, -1, "b2.aiff");

tablemap guitar(e, a, d, g, b, e2, a2, e3, b2);

        pitch = cpsmidi(pitch);
        best = 100000;

        //***** FIND BEST SAMPLE TO REPRESENT CURRENT PITCH *****//
        //***** IS THERE A CLEANER WAY TO DO THIS? **************//
        while(x < 9){
                
                difference = abs( ftbasecps(guitar[x]) - pitch);
                if(difference < best){
                        best = difference;
                        which = x;
                }
                x = x + 1;
        }

        bus = loscil( guitar[which], pitch );
        bus = bus * (vel / 128);

        //***** USER WRITTEN DECAY OPCODE *****//
        relenv = releasor();

        output( bus * relenv);
}
instr mixer(){
asig wet, dry, out;
ivar rev_amt;

        rev_amt = .3;
        
        wet = reverb(input, 10, 5, 1000, 5, 5000, 1) * rev_amt;
        dry = input * (1 - rev_amt);

        out = wet + dry;

        out = out + chorus(out, .6, 5) * .3;

        output(out);
}

kopcode releasor(){
ksig finished, relenv;

        if(!finished && released){
                finished = 1;
                extend(.5);
        }

        if(finished){
                relenv = kline(1, .3, 0);
        } else {
                relenv = 1;
        }

        return(relenv);
}



This archive was generated by hypermail 2b29 : Mon Jan 28 2002 - 11:46:40 EST