Csound Csound-dev Csound-tekno Search About

Real time keyboard instrument

Date2006-02-19 18:48
FromTobiah
SubjectReal time keyboard instrument
Attachmentssinewave.zip  
Altering the direction of my quest for cpu choking complexity
of sound, I've been having fun lately playing this sinewave
instrument at the keyboard.  The purity is enticing.  Play the
main theme from 'Close Encounters' first!  

This instrument should also be a useful harness for beginners to 
modify in order to experiment with playing csound at the keyboard.

I'm attaching a zip file because email clients tend to
mangle csound orchestras in one way or another.

***** COMMAND *****
csound -b128 -B256 -M0 -odac orc sco

***** SCORE *****
;sine for oscillator
f1 0 65536 10 1.0

;try other waveforms
;f1 0 65536 10 1.0 .3 .1
;f1 0 65536 10 1.0 .0 .3 .0 .2

;exponential ramp for pitch roll off muting
f2 0 65536 5 1 65535 .1

;keep score alive
i99 0 6000

***** ORCHESTRA *****
sr      = 44100
ksmps   = 1
nchnls  = 2

gasigr  init 0
gasigl  init 0

gimvol          init            1.0

instr 1

        ;***** INITIALIZE *****

        ibegin          init            p2
        idur            init            8
        ivol            ampmidi         10000
        ipitch          cpsmidi
        irelease        init            .2
        imaxpitch       init            2500

        ichorus         init            rnd(1.2)
        ireverb         init            .1

        ; *Constants for envelope
        ifront          init            .01
        iback           init            idur - ifront

        ; *Taper volume as pitch increases
        ipmute          table           65536 * (ipitch / imaxpitch), 2

        ; *Spread keyboard accross speakers
        ilownote        init            36
        ihighnote       init            96
        inoterange      init            ihighnote - ilownote
        inote_number    notnum
        ipan            init            (inote_number - ilownote) / inoterange

        ;***** INSTRUMENT *****
        asigr           oscili          ivol, ipitch + ichorus, 1
        asigl           oscili          ivol, ipitch, 1

        ; *Pan, envelope and volume control
        aenv            linsegr         .00001, ifront, 1, iback, .00001, irelease, 0
        asigr           =               asigr * aenv * gimvol * ipmute * (1 - ipan)
        asigl           =               asigl * aenv * gimvol * ipmute * ipan

        ; *Send to reverb instrument
        gasigr          =               gasigr + asigr * ireverb
        gasigl          =               gasigl + asigl * ireverb

                        outs            asigl, asigr

endin

instr 99

        irevamt         init            1
        ihidec          init            .2
        irevtime        init            2

        ; * slight difference in hope of better stereo
        arevr           reverb2         gasigr, irevtime + .2, ihidec * .95
        arevl           reverb2         gasigl, irevtime, ihidec

        ; * Raise dry as wet decreases
        asigr           =               gasigr * (1 - irevamt) + arevr * irevamt
        asigl           =               gasigl * (1 - irevamt) + arevl * irevamt

                        outs            asigr * gimvol, asigl * gimvol

                        ; *clear effects bus
                        gasigr          = 0
                        gasigl          = 0
endin