Wednesday, 7 May 2014

The Code Behind The Case

Here is a simple dump of the code which produced 'The Chase'


import random
import math
#sf.SetSampleRate(192000)

# Single threaded for debug
#def sf_do(toDo):
#   return toDo()

def granularReverb(signal,ratio,delay,density):

    def granularReverbInner():
        out=[]
        for grain in sf.Granulate(signal,50,10):
            (signal_i,at)=grain
            signal_i=sf.DirectRelength(signal_i,ratio-0.01+(0.02*random.random()))
            for x in range(0,density):
                out.append(
                    (
                        +signal_i,
                        at + (random.random()+random.random())*delay
                    )
                )
            -signal_i
        return sf.Clean(sf.Normalise(sf.MixAt(out)))
    return sf_do(granularReverbInner)


def reverbInner(signal,convol,grainLength):
    def reverbInnerDo():
        mag=sf.Magnitude(+signal)
        if mag>0:
            signal_=sf.Concatenate(signal,sf.Silence(grainLength))
            signal_=sf.FrequencyDomain(signal_)
            signal_=sf.CrossMultiply(convol,signal_)
            signal_=sf.TimeDomain(signal_)
            newMag=sf.Magnitude(+signal_)
            signal_=sf.NumericVolume(signal_,mag/newMag)        
            # tail out clicks due to amplitude at end of signal 
            return signal_
        else:
            -convol
            return signal
            
    return sf_do(reverbInnerDo)

def reverberate(signal,convol):
    def reverberateDo():
        grainLength = sf.Length(+convol)
        convol_=sf.FrequencyDomain(sf.Concatenate(convol,sf.Silence(grainLength)))
        signal_=sf.Concatenate(signal,sf.Silence(grainLength))
        out=[]
        for grain in sf.Granulate(signal_,grainLength):
            (signal_i,at)=grain
            out.append((reverbInner(signal_i,+convol_,grainLength),at))
        -convol_
        return sf.Realise(sf.Normalise(sf.MixAt(out)))
    return sf_do(reverberateDo)

# Get IRs
violinIRs = sf.ViolinBodyIRs(())
#violaIRs  = sf.ViolaBodyIRs(())
celloIRs  = sf.CelloBodyIRs(())
bassIRs   = sf.BassBodyIRs(())

def createSawTooth(length,pitch):
    signals=[]
    v=1
    opitch=pitch
    it=1.0
    phase=random.random()
    while pitch<18000:
        signals.append(sf.NumericVolume(sf.PhasedSineWave(length,pitch,phase),1.0/it))
        pitch+=opitch
        it+=1
    sig=sf.Mix(signals)
    sig=sf.Realise(sig)
    sig=sf.FixSize(sig)
    return sf.Clean(sig)

def rawString(length,pitch):
    def rawStringA(l,p):
        def rawStringAIn():
            return createSawTooth(l,p)
        return sf_do(rawStringAIn)
    pitch=float(pitch)
    #pitch=pitch+pitch*random.random()*0.0001
    s1=rawStringA(length,pitch)
    s2=rawStringA(length,pitch*2.0)
    s3=rawStringA(length,pitch*4.0)
    s4=sf.WhiteNoise(length)
    signal=sf.Normalise(
        sf.Mix(
            sf.Pcnt20(s4),
            sf.Pcnt50(s1),
            sf.Pcnt20(s2),
            sf.Pcnt10(s3)
        )
    )
    signal=sf.Clean(sf.ResonantFilter(signal,0.95,0.15,sf.Period(pitch)))
    multi=sf.Normalise(
        sf.DirectRelength(
            sf.ButterworthLowPass(sf.WhiteNoise(length/500.0),2500,6),
            0.001
        )
    )
    multi=sf.Cut(0,sf.Length(+signal),multi)
    signal=sf.Resample(
        sf.DirectMix(1,sf.NumericVolume(multi,0.001)),
        signal
    )
    return sf.Realise(sf.Normalise(sf.Clean(signal)))


def playStringClean(a,length,pitch,whiteAmount):
    def rsd():
        return rawString(length,pitch)
    
    signal=0
    if(pitch>500):
        signal=sf.Normalise(sf.Mix(sf_do(rsd),sf_do(rsd),sf_do(rsd)))
    else:
        signal=sf.Normalise(sf.Mix(sf_do(rsd),sf_do(rsd)))
    if(pitch>440):    
        signal=sf.ButterworthHighPass(signal,pitch*0.5,6)
        signal=sf.ButterworthHighPass(signal,2000,1)
        signal=sf.ButterworthLowPass(signal,8000,1)
    if(pitch<128):
        signal=sf.ButterworthHighPass(signal,pitch*0.5,1)
        signal=sf.ButterworthHighPass(signal,500,1)
        signal=sf.ButterworthLowPass(signal,2000,1)
    else:
        signal=sf.ButterworthHighPass(signal,pitch*0.5,3)
        signal=sf.ButterworthHighPass(signal,1500,1)
        signal=sf.ButterworthLowPass(signal,4000,1)

    signal=sf.ButterworthLowPass(signal,pitch*10.0,1)
    signal=sf.Mix(
        sf.Pcnt25(+signal),
        sf.Pcnt75(sf.RBJNotch(signal,pitch,0.5))
    )    
    white=sf.WhiteNoise(length)
    white=sf.ButterworthHighPass(white,pitch*2.0,2)
    white=sf.ButterworthLowPass(white,pitch*6.0,1)
    white=sf.Normalise(white)
    white=sf.Multiply(white,+signal)
    white=sf.NumericVolume(white,whiteAmount)
    signal=sf.NumericVolume(signal,1.0-whiteAmount)
    signal=sf.Normalise(sf.Mix(signal,white))

    sq=sf.Mix(
        sf.PhasedSineWave(length,pitch*0.95,random.random()),
        sf.PhasedSineWave(length,pitch*1.05,random.random())
    )
    envb=sf.NumericShape((0,0.25),(a,0),(length,0))
    sq=sf.Multiply(envb,sf.FixSize(sq))

    enva=sf.NumericShape((0,0.75),(a,1),(length,1))
    signal=sf.Multiply(enva,signal)

    signal=sf.Mix(sq,sf.FixSize(signal))
    sigs=[]
    bodies=[]
    if(pitch<128):
        bodies=bassIRs
    elif(pitch<440):
        bodies=celloIRs
    else:
        bodies=violinIRs
    
    for body in violinIRs:
        sigs.append(reverberate(+signal,+body))  
    -signal
    signal=sf.Normalise(sf.Mix(sigs))
    return signal

def playString(pitch,e,a,d,dat,s,sat,r,whiteAmount,vibStart,vibMiddle,vibAmount,vibRate=2.0):
    print (
        "Performing Note: ",pitch,
        " E:",  e,
        " A:",  a,
        " D:",  d,
        " Dat:",dat,
        " S:",  s,
        " Sat:",sat,
        " R:",  r,
        " WA:", whiteAmount,
        " VS:", vibStart,
        " VM:", vibMiddle,
        " VA:", vibAmount,
        " VR:", vibRate
    )
    def playStringInner():
        envA=sf.SimpleShape(
            (0,-60),
            (e,0),
            (d,0),
            (s,0),
            (r,0)
        )
        envB=sf.NumericShape(
            (0,0),
            (a,1),
            (d,dat),
            (s,sat),
            (r,0)
        )
        env=sf.Multiply(envA,envB)
        sigs=[]
        for x in range(0,5):
            sigs.append(playStringClean(a,r,pitch,whiteAmount))
        signal=sf.Normalise(sf.Mix(sigs))
        signal=sf.Multiply(signal,env)
        if(vibAmount>0):
            l=sf.Length(+signal)
            env=sf.NumericShape((0,0),(vibStart,0),(vibMiddle,1),(r,0.75),(l,0))
            env=sf.NumericVolume(env,vibAmount)
            trem=sf.SineWave(l,2.0+random.random())
            trem=sf.Multiply(env,trem)
            vib=+trem
            trem=sf.DirectMix(1,sf.Pcnt50(trem))
            signal=sf.Multiply(trem,signal)
            vib=sf.DirectMix(1,sf.NumericVolume(vib,0.01))
            signal=sf.Resample(vib,signal)
        
        if(pitch>128):
            signal=sf.ButterworthHighPass(signal,pitch*0.75,3)
            signal=sf.BesselLowPass(signal,pitch,1)
        else:
            signal=sf.ButterworthHighPass(signal,pitch*0.75,3)
            
        return sf.Realise(sf.Normalise(sf.Clean(signal)))
    return sf_do(playStringInner)

def playStringInitial(pitch,length,volume):
    def playStringInitialInner():
        sig=playString(
            pitch,
            64,                 # e
            128,                # a
            length*0.5,         # d
            0.75,               # d at
            length*0.75,        # s
            1.0,                # s at
            length,             # r
            0.75,               # white amount  
            length*0.75,        # vib start
            length*0.75,        # vib middle
            0.5                 # vib amount
        )
        envH=sf.NumericShape((0,1),(length*0.25,0.25),(length,0.25))
        envL=sf.NumericShape((0,0),(length*0.25,0.75),(length,0.75))
        sig=sig.get()
        sigLow=sf.ButterworthLowPass(+sig,pitch*2.0,2)
        sigHi =sf.ButterworthHighPass(sig ,pitch*2.0,2)
        sigLow=sf.Multiply(sigLow,envL)
        sigHi =sf.Multiply(sigHi ,envH)
        env   =sf.NumericShape((0,0),(length*0.25,0.25),(length*0.5,1),(length,1))
        sig   =sf.Mix(sigLow,sigHi)
        sig   =sf.FixSize(sf.Multiply(env,sig))
        return sf.Clean(sf.NumericVolume(sig,volume))
    return sf_do(playStringInitialInner)
    
def playStringSuperSoft(pitch,length,volume):
    def playStringSoftSuperInner():
        if(pitch<256):
            w=0.75
        else:
            if(pitch<720):
                w=0.33
            else:
                w=0.25
        sig = sf.NumericVolume(
            playString(
                pitch,
                64,                 # e
                length*0.25,        # a
                length*0.50,        # d
                1.0,                # d at
                length*0.75,        # s
                1.0,                # s at
                length,             # r
                w,                  # white amount  
                length*0.50,        # vib start
                length*0.75,        # vib middle
                0.5                 # vib amount
            ),
            volume
        )
        env   = sf.NumericShape((0,0),(length*0.25,1),(length,1))
        return sf.Clean(sf.FixSize(sf.Multiply(env,sig)))
    return sf_do(playStringSoftSuperInner)

def playStringSoftShort(pitch,length,volume):
    def playStringSoftShortInner():
        if(pitch<256):
            w=0.5
        else:
            if(pitch<720):
                w=0.25
            else:
                w=0.15
        return sf.Clean(sf.NumericVolume(
            playString(
                pitch,
                32,                 # e
                64,                 # a
                length*0.15,        # d
                1.0,                # d at
                length*0.5,         # s
                0.5,                # s at
                length,             # r
                w,                  # white amount  
                length*0.50,        # vib start
                length*0.75,        # vib middle
                0.5                 # vib amount
            ),
            volume
        ))
    return sf_do(playStringSoftShortInner)

def playStringHardLong(pitch,length,volume):
    def playStringHardLong():
        if(pitch<256):
            w=0.1
        else:
            if(pitch<720):
                w=0.1
            else:
                w=0.05
        return sf.Clean(sf.NumericVolume(
            playString(
                pitch,
                32,                 # e
                64,                 # a
                length*0.25,        # d
                1.0,                # d at
                length*0.75,        # s
                0.75,               # s at
                length,             # r
                w,                  # white amount  
                length*0.25,        # vib start
                length*0.75,        # vib middle
                0.5                 # vib amount - no vib in this case
            ),
            volume
        ))
    return sf_do(playStringHardLong)

def playStringHardShort(pitch,length,volume):
    def playStringHardShortInner():
        if(pitch<256):
            w=0.1
        else:
            if(pitch<720):
                w=0.1
            else:
                w=0.05
        return sf.Clean(sf.NumericVolume(
            playString(
                pitch,
                32,                 # e
                64,                 # a
                length*0.125,       # d
                1.0,                # d at
                length*0.75,         # s
                0.75,               # s at
                length,             # r
                w,                  # white amount  
                length*0.25,        # vib start
                length*0.75,        # vib middle
                0                   # vib amount - no vib in this case
            ),
            volume
        ))
    return sf_do(playStringHardShortInner)

def playStringPluck(pitch,length,volume):
    def playStringPluckInner():
        sig=playString(
                pitch,
                8,                  # e
                16,                 # a
                32,                 # d
                0.5,                # d at
                length*0.75,        # s
                0.25,               # s at
                length,             # r
                0,                  # white amount  
                length*0.50,        # vib start
                length*0.90,        # vib middle
                1                   # vib amount - no vib in this case
            )
        envH=sf.NumericShape((0,0),(32,1),(length,0))
        envL=sf.NumericShape((0,1),(32,0),(length,1))
        sig=sig.get()
        sigL=sf.ButterworthLowPass(+sig,pitch,1)
        sigL=sf.ButterworthLowPass(sigL,pitch*3,1)
        sigH=sf.Multiply(sig,envH)
        sigL=sf.Multiply(sigL,envL)
        sig=sf.Mix(sigL,sigH)
        sig=sf.NumericVolume(sig,volume)
        return sig
        
    return sf_do(playStringPluckInner)

def makeClick(formant):
    clickA=sf.Multiply(
        sf.SimpleShape((0,0),(500,-30),(512,-60)),
        sf.NumericShape((0,0),(100,1),(-300,-1),(400,0)),
        sf.FixSize(sf.Power(sf.WhiteNoise(512),8))
    )
    clickA=sf.BesselLowPass(clickA,440,1)
    clickA=formant(clickA)

    for i in range(0,4):
        clickB=sf.BesselLowPass(+clickA,440,1)
        clickB=formant(clickB)
        clickA=sf.MixAt(
            (clickA,0),
            (clickB,beat/16)
        )
    return sf.Normalise(clickA)

def doFormant(sig,f1,f2,f3):
    def doFormantInner(a,b,c,d):
        def doFII():
            return sf.RBJPeaking(a,b,c,d)
        return sf_do(doFII)
    sig1=doFormantInner(+sig,f1,1,40)
    sig2=doFormantInner(+sig,f2,2,20)
    sig3=doFormantInner( sig,f3,1,40)
    x=sf.Mix(sig1,sig2,sig3)
    x=sf.Normalise(x)
    return sf.Realise(x)

#beat
def sayBeat(sig):
    return doFormant(sig,300,2800,3300)

#bit
def sayBit(sig):
    return doFormant(sig,430,2500,3100)

#bet
def sayBet(sig):
    return doFormant(sig,600,2350,3000)

#bat
def sayBat(sig):
    return doFormant(sig,860,2050,2850)

#part
def sayPart(sig):
    return doFormant(sig,850,1200,2800)

#pot 
def sayPot(sig):
    return doFormant(sig,590,900,2700)

#boat
def sayBoat(sig):
    return doFormant(sig,470,1150,2700)

#book
def sayBook(sig):
    return doFormant(sig,370,950,2650)

#but
def sayBut(sig):
    return doFormant(sig,760,1400,2800)

#pert
def sayPert(sig):
    return doFormant(sig,500,1650,1950)

# oddness
def sayStrange(sig):
    return doFormant(sig,550,1800,2050)

# Very slow indeed
beat = 1024

def phrase1():
    print "Phrase 1"
    at   = 0
    sigl = []
    sigr = []

    pitch=sf.Note("D3")
    length=beat*2.0
    sigl=playStringSuperSoft(pitch,length,0.5)
    sigr=playStringSuperSoft(pitch,length,0.5)
    wleft  = granularReverb(sigl,0.5,beat*2,512)
    wright = granularReverb(sigr,0.5,beat*2,512)
    wleft  = sf.FixSize(wleft)
    wright = sf.FixSize(wright)
    left  = sf.FixSize(sayPot(wleft))
    right = sf.FixSize(sayPot(wright))
            
    sf.WriteFile32([left,right],"temp/phrase-1.wav")

def phrase2():
    print "Phrase 2"
    at   = 0
    sigl = []
    sigr = []

    pitch=sf.Note("D3")
    length=beat*2.0
    sigl=playStringSuperSoft(pitch,length,0.5)
    sigr=playStringSuperSoft(pitch,length,0.5)
    wleft1  = sf.Pcnt15(granularReverb(+sigl,0.5 ,beat*2,128))
    wright1 = sf.Pcnt35(granularReverb(+sigr,0.75,beat*2,128))
    wleft2  = sf.Pcnt43(granularReverb(+sigl,0.75,beat*2,128))
    wright2 = sf.Pcnt23(granularReverb(+sigr,0.5 ,beat*2,128))
    wleft3  =           granularReverb( sigl,0.125,beat*2,128)
    wright3 =           granularReverb( sigr,0.125,beat*2,128)
    left  = sf.FixSize(sayBoat(sf.Mix(wleft1,wleft2,wleft3)))
    right = sf.FixSize(sayBoat(sf.Mix(wright1,wright2,wright3)))
        
    sf.WriteFile32([left,right],"temp/phrase-2.wav")


def phrase3():
    print "Phrase 3"
    at   = 0
    sigl = []
    sigr = []

    # 1
    pitch=sf.Note("D4")
    length=beat*0.5
    sigl.append((playStringPluck(pitch,length,0.5),at))
    sigr.append((playStringPluck(pitch,length,0.5),at))
    
    # 1.5
    at+=beat*0.5
    pitch=sf.Note("D4#")
    sigl.append((playStringPluck(pitch,length,0.5),at))
    sigr.append((playStringPluck(pitch,length,0.5),at))
    
    # 2
    at+=beat*0.5
    pitch=sf.Note("D4")
    sigl.append((playStringPluck(pitch,length,0.5),at))
    sigr.append((playStringPluck(pitch,length,0.5),at))

    2.5
    at+=beat*0.5
    pitch=sf.Note("C4#")
    sigl.append((playStringPluck(pitch,length,0.33),at))
    sigr.append((playStringPluck(pitch,length,0.33),at))

    # 3
    at+=beat*0.5
    pitch=sf.Note("D4")
    sigl.append((playStringPluck(pitch,length,0.5),at))
    sigr.append((playStringPluck(pitch,length,0.5),at))

    # 3.5
    at+=beat*0.5
    length=beat*0.4
    pitch=sf.Note("B3")
    sigl.append((playStringPluck(pitch,length,0.33),at))
    sigr.append((playStringPluck(pitch,length,0.33),at))

    # 4
    at+=beat*0.5
    length=beat*0.5
    pitch=sf.Note("A3")
    sigl.append((playStringPluck(pitch,length,0.5),at))
    sigr.append((playStringPluck(pitch,length,0.5),at))
    
    # 4.5
    at+=beat*0.5
    length=beat*0.4
    pitch=sf.Note("B3")
    sigl.append((playStringPluck(pitch,length,0.25),at))
    sigr.append((playStringPluck(pitch,length,0.25),at))
       
    print "Compiling Phrase3"
    left=sf.FixSize(sf.MixAt(sigl))
    right=sf.FixSize(sf.MixAt(sigr))
    wleft  = sf.Mix(
        granularReverb(+left, 1.0,beat*0.4,250),
        granularReverb(+left, 0.5,beat*0.8,250)
    )        
    wright = sf.Mix(
        granularReverb(+right,1.0,beat*0.4,250),
        granularReverb(+right,0.5,beat*0.8,250)
    )

    left2  = sf.Mix(sf.Pcnt20(+wleft), +left)
    right2 = sf.Mix(sf.Pcnt20(+wright),+right)
    left  = sf.Mix(sf.Pcnt50(wleft) ,sf.Pcnt50(left))
    right = sf.Mix(sf.Pcnt50(wright),sf.Pcnt50(right))
    left = sf.FixSize(left)
    right= sf.FixSize(right)

    sf.WriteFile32([+left,+right],"temp/phrase-3.wav")

    print "Compiling Phrase4"
    
    pitch=sf.Note("D4")
    length=beat*2.0
    sigl=playStringSuperSoft(pitch,length,0.5)
    sigr=playStringSuperSoft(pitch,length,0.5)
    wleft  = granularReverb(sigl,0.5,beat,128)
    wright = granularReverb(sigr,0.5,beat,128)
    wleft  = sayPart(wleft)
    wright = sayPart(wright)
    
    left=sf.Normalise(sf.MixAt(
        (sf.Pcnt35(wleft),0),
        (sf.Pcnt65(left2),0)
    ))
    
    right=sf.Normalise(sf.MixAt(
        (sf.Pcnt45(wright),0),
        (sf.Pcnt55(right2),0)
    ))
        
    sf.WriteFile32([left,right],"temp/phrase-4.wav")

def phrase5():
    print "Phrase 5"
    at   = 0
    sigl = []
    sigr = []

    def double():
        sigl.append((playStringHardShort(pitch,length,0.5),at))
        sigr.append((playStringHardShort(pitch,length,0.5),at))
        sigl.append((playStringHardShort(pitch,length,0.5),at+0.25*beat))
        sigr.append((playStringHardShort(pitch,length,0.5),at+0.25*beat))
        sigl.append((playStringHardShort(pitch*2.01,length,0.5),at))
        sigr.append((playStringHardShort(pitch*1.99,length,0.5),at))
        sigl.append((playStringHardShort(pitch*1.99,length,0.5),at+0.25*beat))
        sigr.append((playStringHardShort(pitch*2.01,length,0.5),at+0.25*beat))    

    # 1
    pitch=sf.Note("D4")
    length=beat*0.5
    double()
    
    # 1.5
    at+=beat*0.5
    pitch=sf.Note("D4#")
    double()
    
    # 2
    at+=beat*0.5
    pitch=sf.Note("D4")
    double()

    2.5
    at+=beat*0.5
    pitch=sf.Note("C4#")
    double()

    # 3
    at+=beat*0.5
    pitch=sf.Note("D4")
    double()

    # 3.5
    at+=beat*0.5
    length=beat*0.4
    pitch=sf.Note("B3")
    double()

    # 4
    at+=beat*0.5
    length=beat*0.5
    pitch=sf.Note("A3")
    double()
    
    # 4.5
    at+=beat*0.5
    length=beat*0.4
    pitch=sf.Note("B3")
    double()
       
    left=sf.FixSize(sf.MixAt(sigl))
    right=sf.FixSize(sf.MixAt(sigr))
    wleft  = sf.Mix(
        granularReverb(+left, 1.0,beat*0.4,250),
        granularReverb(+left, 0.5,beat*0.8,250)
    )        
    wright = sf.Mix(
        granularReverb(+right,1.0,beat*0.4,250),
        granularReverb(+right,0.5,beat*0.8,250)
    )

    left2  = sf.Mix(sf.Pcnt20(+wleft), +left)
    right2 = sf.Mix(sf.Pcnt20(+wright),+right)

    print "Compiling Phrase5"
    
    pitch=sf.Note("G4")
    length=beat*2.0
    sigl=playStringSuperSoft(pitch,length,0.5)
    sigr=playStringSuperSoft(pitch,length,0.5)
    wleft  = sf.Mix(
        granularReverb(+sigl,0.50,beat,128),
        granularReverb( sigl,0.75,beat,128)
    )
    wright = sf.Mix(
        granularReverb(+sigr,0.50,beat,128),
        granularReverb( sigr,0.75,beat,128)
    )
    wleft  = sayBoat(wleft)
    wright = sayBoat(wright)
    
    left=sf.Normalise(sf.MixAt(
        (sf.Pcnt35(wleft),0),
        (sf.Pcnt65(left2),0)
    ))
    
    right=sf.Normalise(sf.MixAt(
        (sf.Pcnt45(wright),0),
        (sf.Pcnt55(right2),0)
    ))
        
    sf.WriteFile32([left,right],"temp/phrase-5.wav")

def phrase6():
    print "Phrase 6"
    at   = 0
    sigl = []
    sigr = []

    def double():
        sigl.append((playStringHardShort(pitch,length,0.5),at))
        sigr.append((playStringHardShort(pitch,length,0.5),at))
        sigl.append((playStringHardShort(pitch,length,0.5),at+0.25*beat))
        sigr.append((playStringHardShort(pitch,length,0.5),at+0.25*beat))
        sigl.append((playStringHardShort(pitch*2.01,length,0.5),at))
        sigr.append((playStringHardShort(pitch*1.99,length,0.5),at))
        sigl.append((playStringHardShort(pitch*1.99,length,0.5),at+0.25*beat))
        sigr.append((playStringHardShort(pitch*2.01,length,0.5),at+0.25*beat))    

    # 1
    pitch=sf.Note("D4")
    length=beat*0.5
    double()
    
    # 1.5
    at+=beat*0.5
    pitch=sf.Note("D4#")
    double()
    
    # 2
    at+=beat*0.5
    pitch=sf.Note("D4")
    double()

    2.5
    at+=beat*0.5
    pitch=sf.Note("C4#")
    double()

    # 3
    at+=beat*0.5
    pitch=sf.Note("D4")
    double()

    # 3.5
    at+=beat*0.5
    length=beat*0.4
    pitch=sf.Note("B3")
    double()

    # 4
    at+=beat*0.5
    length=beat*0.5
    pitch=sf.Note("A3")
    double()
    
    # 4.5
    at+=beat*0.5
    length=beat*0.4
    pitch=sf.Note("B3")
    double()
       
    left=sf.FixSize(sf.MixAt(sigl))
    right=sf.FixSize(sf.MixAt(sigr))
    wleft  = sf.Mix(
        granularReverb(+left, 2.0,beat*0.2,250),
        granularReverb(+left, 1.0,beat*0.4,250),
        granularReverb(+left, 0.5,beat*0.8,250)
    )        
    wright = sf.Mix(
        granularReverb(+right,1.0,beat*0.2,250),
        granularReverb(+right,2.0,beat*0.4,250),
        granularReverb(+right,0.5,beat*0.8,250)
    )

    left2  = sf.Mix(sf.Pcnt20(+wleft), +left)
    right2 = sf.Mix(sf.Pcnt20(+wright),+right)

    print "Compiling Phrase6"
    
    pitch=sf.Note("G4")
    length=beat*2.0
    sigl=playStringSuperSoft(pitch,length,0.5)
    sigr=playStringSuperSoft(pitch,length,0.5)
    wleft  = sf.Mix(
        granularReverb(+sigl,0.50,beat,128),
        granularReverb( sigl,0.75,beat,128)
    )
    wright = sf.Mix(
        granularReverb(+sigr,0.50,beat,128),
        granularReverb( sigr,0.75,beat,128)
    )
    wleft  = sayPart(wleft)
    wright = sayPart(wright)
    
    left=sf.Normalise(sf.MixAt(
        (sf.Pcnt35(wleft),0),
        (sf.Pcnt65(left2),0)
    ))
    
    right=sf.Normalise(sf.MixAt(
        (sf.Pcnt45(wright),0),
        (sf.Pcnt55(right2),0)
    ))
        
    sf.WriteFile32([left,right],"temp/phrase-6.wav")

def phrase7():
    print "Phrase 7"
    at   = 0
    sigl = []
    sigr = []

    def double():
        sigl.append((playStringHardShort(pitch*0.5,length*2.0,0.5),at))
        sigr.append((playStringHardShort(pitch*0.5,length*2.0,0.5),at))
        sigl.append((playStringHardShort(pitch,length,0.5),at))
        sigr.append((playStringHardShort(pitch,length,0.5),at))
        sigl.append((playStringHardShort(pitch,length,0.5),at+0.25*beat))
        sigr.append((playStringHardShort(pitch,length,0.5),at+0.25*beat))
        sigl.append((playStringHardShort(pitch*2.01,length,0.5),at))
        sigr.append((playStringHardShort(pitch*1.99,length,0.5),at))
        sigl.append((playStringHardShort(pitch*1.99,length,0.5),at+0.25*beat))
        sigr.append((playStringHardShort(pitch*2.01,length,0.5),at+0.25*beat))    

    # 1
    pitch=sf.Note("D4")
    length=beat*0.5
    double()
    
    # 1.5
    at+=beat*0.5
    pitch=sf.Note("D4#")
    double()
    
    # 2
    at+=beat*0.5
    pitch=sf.Note("D4")
    double()

    2.5
    at+=beat*0.5
    pitch=sf.Note("C4#")
    double()

    # 3
    at+=beat*0.5
    pitch=sf.Note("D4")
    double()

    # 3.5
    at+=beat*0.5
    length=beat*0.4
    pitch=sf.Note("B3")
    double()

    # 4
    at+=beat*0.5
    length=beat*0.5
    pitch=sf.Note("A3")
    double()
    
    # 4.5
    at+=beat*0.5
    length=beat*0.4
    pitch=sf.Note("B3")
    double()
       
    left=sf.FixSize(sf.MixAt(sigl))
    right=sf.FixSize(sf.MixAt(sigr))
    wleft  = sf.Mix(
        granularReverb(+left, 2.0,beat*0.2,250),
        granularReverb(+left, 1.0,beat*0.4,250),
        granularReverb(+left, 0.5,beat*0.8,250)
    )        
    wright = sf.Mix(
        granularReverb(+right,1.0,beat*0.2,250),
        granularReverb(+right,2.0,beat*0.4,250),
        granularReverb(+right,0.5,beat*0.8,250)
    )

    left2  = sf.Mix(sf.Pcnt20(+wleft), +left)
    right2 = sf.Mix(sf.Pcnt20(+wright),+right)

    print "Compiling Phrase7"
    
    pitch=sf.Note("G4")
    length=beat*2.0
    sigl=playStringSuperSoft(pitch,length,0.5)
    sigr=playStringSuperSoft(pitch,length,0.5)
    wleft  = sf.Mix(
        granularReverb(+sigl,0.50,beat,128),
        granularReverb( sigl,0.75,beat,128)
    )
    wright = sf.Mix(
        granularReverb(+sigr,0.50,beat,128),
        granularReverb( sigr,0.75,beat,128)
    )
    wleft  = sayBit(wleft)
    wright = sayBit(wright)
    
    left=sf.Normalise(sf.MixAt(
        (sf.Pcnt35(wleft),0),
        (sf.Pcnt65(left2),0)
    ))
    
    right=sf.Normalise(sf.MixAt(
        (sf.Pcnt45(wright),0),
        (sf.Pcnt55(right2),0)
    ))
        
    sf.WriteFile32([left,right],"temp/phrase-7.wav")

def phrase8():
    print "Phrase 8"
    at   = 0
    sigl = []
    sigr = []

    def double():
        sigl.append((playStringHardLong(pitch*0.25,length*2.0,0.5),at))
        sigr.append((playStringHardLong(pitch*0.25,length*2.0,0.5),at))
        sigl.append((playStringHardShort(pitch*0.5,length*2.0,0.5),at))
        sigr.append((playStringHardShort(pitch*0.5,length*2.0,0.5),at))
        sigl.append((playStringHardShort(pitch,length,0.5),at))
        sigr.append((playStringHardShort(pitch,length,0.5),at))
        sigl.append((playStringHardShort(pitch,length,0.5),at+0.25*beat))
        sigr.append((playStringHardShort(pitch,length,0.5),at+0.25*beat))
        sigl.append((playStringPluck(pitch*2.01,length,0.5),at))
        sigr.append((playStringPluck(pitch*1.99,length,0.5),at))
        sigl.append((playStringPluck(pitch*1.99,length,0.5),at+0.25*beat))
        sigr.append((playStringPluck(pitch*2.01,length,0.5),at+0.25*beat))    

    # 1
    pitch=sf.Note("D4")
    length=beat*0.5
    double()
    
    # 1.5
    at+=beat*0.5
    pitch=sf.Note("D4#")
    double()
    
    # 2
    at+=beat*0.5
    pitch=sf.Note("D4")
    double()

    2.5
    at+=beat*0.5
    pitch=sf.Note("C4#")
    double()

    # 3
    at+=beat*0.5
    pitch=sf.Note("D4")
    double()

    # 3.5
    at+=beat*0.5
    length=beat*0.4
    pitch=sf.Note("B3")
    double()

    # 4
    at+=beat*0.5
    length=beat*0.5
    pitch=sf.Note("A3")
    double()
    
    # 4.5
    at+=beat*0.5
    length=beat*0.4
    pitch=sf.Note("B3")
    double()
       
    left=sf.FixSize(sf.MixAt(sigl))
    right=sf.FixSize(sf.MixAt(sigr))
    wleft  = sf.Mix(
        granularReverb(+left, 2.0,beat*0.2,250),
        granularReverb(+left, 1.0,beat*0.4,250),
        granularReverb(+left, 0.5,beat*0.8,250)
    )        
    wright = sf.Mix(
        granularReverb(+right,1.0,beat*0.2,250),
        granularReverb(+right,2.0,beat*0.4,250),
        granularReverb(+right,0.5,beat*0.8,250)
    )

    left2  = sf.Mix(sf.Pcnt40(+wleft), +left)
    right2 = sf.Mix(sf.Pcnt40(+wright),+right)

    print "Compiling Phrase8"
    
    pitch=sf.Note("G4")
    length=beat*2.0
    sigl=playStringSuperSoft(pitch,length,0.5)
    sigr=playStringSuperSoft(pitch,length,0.5)
    wleft  = sf.Mix(
        granularReverb(+sigl,0.50,beat,128),
        granularReverb( sigl,0.75,beat,128)
    )
    wright = sf.Mix(
        granularReverb(+sigr,0.50,beat,128),
        granularReverb( sigr,0.75,beat,128)
    )
    wleft  = sayBoat(wleft)
    wright = sayBoat(wright)
    
    left=sf.Normalise(sf.MixAt(
        (sf.Pcnt35(wleft),0),
        (sf.Pcnt65(left2),0)
    ))
    
    right=sf.Normalise(sf.MixAt(
        (sf.Pcnt45(wright),0),
        (sf.Pcnt55(right2),0)
    ))
        
    sf.WriteFile32([left,right],"temp/phrase-8.wav")

def phrase9():
    print "Phrase 9"
    at   = 0
    sigl = []
    sigr = []

    def double():
        sigl.append((playStringHardLong(pitch*0.25,length*2.0,0.5),at))
        sigr.append((playStringHardLong(pitch*0.25,length*2.0,0.5),at))
        sigl.append((playStringHardShort(pitch*0.5,length*2.0,0.5),at))
        sigr.append((playStringHardShort(pitch*0.5,length*2.0,0.5),at))
        sigl.append((playStringHardShort(pitch,length,0.5),at))
        sigr.append((playStringHardShort(pitch,length,0.5),at))
        sigl.append((playStringHardShort(pitch,length,0.5),at+0.25*beat))
        sigr.append((playStringHardShort(pitch,length,0.5),at+0.25*beat))
        sigl.append((playStringPluck(pitch*2.01,length,0.5),at))
        sigr.append((playStringPluck(pitch*1.99,length,0.5),at))
        sigl.append((playStringPluck(pitch*1.99,length,0.5),at+0.25*beat))
        sigr.append((playStringPluck(pitch*2.01,length,0.5),at+0.25*beat))    

    # 1
    pitch=sf.Note("D4")
    length=beat*0.5
    double()
    
    # 1.5
    at+=beat*0.5
    pitch=sf.Note("D4#")
    double()
    
    # 2
    at+=beat*0.5
    pitch=sf.Note("E4")
    double()

    2.5
    at+=beat*0.5
    pitch=sf.Note("C4#")
    double()

    # 3
    at+=beat*0.5
    pitch=sf.Note("D4")
    double()

    # 3.5
    at+=beat*0.5
    length=beat*0.4
    pitch=sf.Note("B3")
    double()

    # 4
    at+=beat*0.5
    length=beat*0.5
    pitch=sf.Note("A3")
    double()
    
    # 4.5
    at+=beat*0.5
    length=beat*0.4
    pitch=sf.Note("G3#")
    double()
       
    left=sf.FixSize(sf.MixAt(sigl))
    right=sf.FixSize(sf.MixAt(sigr))
    wleft  = sf.Mix(
        granularReverb(+left, 2.0,beat*0.2,250),
        granularReverb(+left, 1.0,beat*0.4,250),
        granularReverb(+left, 0.5,beat*0.8,250)
    )        
    wright = sf.Mix(
        granularReverb(+right,1.0,beat*0.2,250),
        granularReverb(+right,2.0,beat*0.4,250),
        granularReverb(+right,0.5,beat*0.8,250)
    )

    left2  = sf.Mix(sf.Pcnt40(+wleft), +left)
    right2 = sf.Mix(sf.Pcnt40(+wright),+right)

    print "Compiling Phrase8"
    
    pitch=sf.Note("F4")
    length=beat*2.0
    sigl=playStringSuperSoft(pitch,length,0.5)
    sigr=playStringSuperSoft(pitch,length,0.5)
    wleft  = sf.Mix(
        granularReverb(+sigl,0.50,beat,128),
        granularReverb( sigl,0.75,beat,128)
    )
    wright = sf.Mix(
        granularReverb(+sigr,0.50,beat,128),
        granularReverb( sigr,0.75,beat,128)
    )
    wleft  = sayBook(wleft)
    wright = sayBook(wright)
    
    left=sf.Normalise(sf.MixAt(
        (sf.Pcnt35(wleft),0),
        (sf.Pcnt65(left2),0)
    ))
    
    right=sf.Normalise(sf.MixAt(
        (sf.Pcnt45(wright),0),
        (sf.Pcnt55(right2),0)
    ))
        
    sf.WriteFile32([left,right],"temp/phrase-9.wav")
    
def phrase10():
    print "Phrase 10"
    at   = 0
    sigl = []
    sigr = []

    def double():
        sigl.append((playStringHardLong(pitch*0.25,length*2.0,0.5),at))
        sigr.append((playStringHardLong(pitch*0.25,length*2.0,0.5),at))
        sigl.append((playStringHardShort(pitch*0.5,length*2.0,0.5),at))
        sigr.append((playStringHardShort(pitch*0.5,length*2.0,0.5),at))
        sigl.append((playStringHardShort(pitch,length,0.5),at))
        sigr.append((playStringHardShort(pitch,length,0.5),at))
        sigl.append((playStringHardShort(pitch,length,0.5),at+0.25*beat))
        sigr.append((playStringHardShort(pitch,length,0.5),at+0.25*beat))
        sigl.append((playStringPluck(pitch*2.01,length,0.5),at))
        sigr.append((playStringPluck(pitch*1.99,length,0.5),at))
        sigl.append((playStringPluck(pitch*1.99,length,0.5),at+0.25*beat))
        sigr.append((playStringPluck(pitch*2.01,length,0.5),at+0.25*beat))    

    def vipvip():
        sigl.append((playStringPluck(pitch,length,0.5),at))
        sigr.append((playStringPluck(pitch,length,0.5),at))
        

    # 1
    pitch=sf.Note("D4")
    length=beat*0.5
    double()
    
    pitch=sf.Note("G6")
    vipvip()
    
    # 1.5
    at+=beat*0.5
    pitch=sf.Note("D4#")
    double()

    pitch=sf.Note("G6#")
    vipvip()
    
    # 2
    at+=beat*0.5
    pitch=sf.Note("E4")
    double()

    pitch=sf.Note("A6")
    vipvip()

    2.5
    at+=beat*0.5
    pitch=sf.Note("C4#")
    double()

    pitch=sf.Note("G6#")
    vipvip()

    # 3
    at+=beat*0.5
    pitch=sf.Note("D4")
    double()

    pitch=sf.Note("G6")
    vipvip()

    # 3.5
    at+=beat*0.5
    length=beat*0.4
    pitch=sf.Note("B3")
    double()

    pitch=sf.Note("G6#")
    vipvip()

    # 4
    at+=beat*0.5
    length=beat*0.5
    pitch=sf.Note("A3")
    double()

    pitch=sf.Note("F6")
    vipvip()
    
    # 4.5
    at+=beat*0.5
    length=beat*0.4
    pitch=sf.Note("G3#")
    double()

    pitch=sf.Note("F6#")
    vipvip()
       
    left=sf.FixSize(sf.MixAt(sigl))
    right=sf.FixSize(sf.MixAt(sigr))
    wleft  = sf.Mix(
        granularReverb(+left, 2.0,beat*0.2,250),
        granularReverb(+left, 1.0,beat*0.4,250),
        granularReverb(+left, 0.5,beat*0.8,250)
    )        
    wright = sf.Mix(
        granularReverb(+right,1.0,beat*0.2,250),
        granularReverb(+right,2.0,beat*0.4,250),
        granularReverb(+right,0.5,beat*0.8,250)
    )

    left2  = sf.Mix(sf.Pcnt40(+wleft), +left)
    right2 = sf.Mix(sf.Pcnt40(+wright),+right)

    print "Compiling Phrase10"
    
    pitch=sf.Note("A4")
    length=beat*2.0
    sigl=playStringSuperSoft(pitch,length,0.5)
    sigr=playStringSuperSoft(pitch,length,0.5)
    wleft  = sf.Mix(
        granularReverb(+sigl,0.50,beat,128),
        granularReverb( sigl,0.75,beat,128)
    )
    wright = sf.Mix(
        granularReverb(+sigr,0.50,beat,128),
        granularReverb( sigr,0.75,beat,128)
    )
    wleft  = sayBit(wleft)
    wright = sayBit(wright)
    
    left=sf.Normalise(sf.MixAt(
        (sf.Pcnt35(wleft),0),
        (sf.Pcnt65(left2),0)
    ))
    
    right=sf.Normalise(sf.MixAt(
        (sf.Pcnt45(wright),0),
        (sf.Pcnt55(right2),0)
    ))
        
    sf.WriteFile32([left,right],"temp/phrase-10.wav")
 
def phrase11():
    print "Phrase 11"
    at   = 0
    sigl = []
    sigr = []

    # pitch up minor third
    def double():
        lpitch=pitch*sf.Semitone(())**3.0
        sigl.append((playStringHardLong(lpitch*0.25,length*2.0,0.5),at))
        sigr.append((playStringHardLong(lpitch*0.25,length*2.0,0.5),at))
        sigl.append((playStringHardShort(lpitch*0.5,length*2.0,0.5),at))
        sigr.append((playStringHardShort(lpitch*0.5,length*2.0,0.5),at))
        sigl.append((playStringHardShort(lpitch,length,0.5),at))
        sigr.append((playStringHardShort(lpitch,length,0.5),at))
        sigl.append((playStringHardShort(lpitch,length,0.5),at+0.25*beat))
        sigr.append((playStringHardShort(lpitch,length,0.5),at+0.25*beat))
        sigl.append((playStringPluck(lpitch*2.01,length,0.5),at))
        sigr.append((playStringPluck(lpitch*1.99,length,0.5),at))
        sigl.append((playStringPluck(lpitch*1.99,length,0.5),at+0.25*beat))
        sigr.append((playStringPluck(lpitch*2.01,length,0.5),at+0.25*beat))    

    def vipvip():
        lpitch=pitch*sf.Semitone(())**3.0
        sigl.append((playStringPluck(lpitch,length,0.5),at))
        sigr.append((playStringPluck(lpitch,length,0.5),at))
        

    # 1
    pitch=sf.Note("D4")
    length=beat*0.5
    double()
    
    pitch=sf.Note("G6")
    vipvip()
    
    # 1.5
    at+=beat*0.5
    pitch=sf.Note("D4#")
    double()

    pitch=sf.Note("G6#")
    vipvip()
    
    # 2
    at+=beat*0.5
    pitch=sf.Note("E4")
    double()

    pitch=sf.Note("A6")
    vipvip()

    2.5
    at+=beat*0.5
    pitch=sf.Note("C4#")
    double()

    pitch=sf.Note("G6#")
    vipvip()

    # 3
    at+=beat*0.5
    pitch=sf.Note("D4")
    double()

    pitch=sf.Note("G6")
    vipvip()

    # 3.5
    at+=beat*0.5
    length=beat*0.4
    pitch=sf.Note("B3")
    double()

    pitch=sf.Note("G6#")
    vipvip()

    # 4
    at+=beat*0.5
    length=beat*0.5
    pitch=sf.Note("A3")
    double()

    pitch=sf.Note("F6")
    vipvip()
    
    # 4.5
    at+=beat*0.5
    length=beat*0.4
    pitch=sf.Note("G3#")
    double()

    pitch=sf.Note("F6#")
    vipvip()
       
    left=sf.FixSize(sf.MixAt(sigl))
    right=sf.FixSize(sf.MixAt(sigr))
    wleft  = sf.Mix(
        granularReverb(+left, 2.0,beat*0.2,250),
        granularReverb(+left, 1.0,beat*0.4,250),
        granularReverb(+left, 0.5,beat*0.8,250)
    )        
    wright = sf.Mix(
        granularReverb(+right,1.0,beat*0.2,250),
        granularReverb(+right,2.0,beat*0.4,250),
        granularReverb(+right,0.5,beat*0.8,250)
    )

    left2  = sf.Mix(sf.Pcnt40(+wleft), +left)
    right2 = sf.Mix(sf.Pcnt40(+wright),+right)

    print "Compiling Phrase10"
    
    pitch=sf.Note("A3")
    length=beat*2.0
    sigl=playStringHardLong(pitch,length,0.5)
    sigr=playStringHardLong(pitch,length,0.5)
    wleft  = sf.Mix(
        granularReverb(+sigl,0.50,beat,128),
        granularReverb( sigl,0.75,beat,128)
    )
    wright = sf.Mix(
        granularReverb(+sigr,0.50,beat,128),
        granularReverb( sigr,0.75,beat,128)
    )
    wleft  = sayBat(wleft)
    wright = sayBat(wright)
    
    left=sf.Normalise(sf.MixAt(
        (sf.Pcnt35(wleft),0),
        (sf.Pcnt65(left2),0)
    ))
    
    right=sf.Normalise(sf.MixAt(
        (sf.Pcnt45(wright),0),
        (sf.Pcnt55(right2),0)
    ))
        
    sf.WriteFile32([left,right],"temp/phrase-11.wav") 

def phrase12():
    print "Phrase 12"
    at   = 0
    sigl = []
    sigr = []

    # pitch up a fifth
    def double():
        lpitch=pitch*sf.Semitone(())**7.0
        sigl.append((playStringHardLong(lpitch*0.25,length*2.0,0.75),at))
        sigr.append((playStringHardLong(lpitch*0.25,length*2.0,0.25),at))
        sigl.append((playStringHardShort(lpitch*0.5,length*2.0,0.75),at))
        sigr.append((playStringHardShort(lpitch*0.5,length*2.0,0.25),at))
        sigl.append((playStringHardShort(lpitch,length,0.5),at))
        sigr.append((playStringHardShort(lpitch,length,0.5),at))
        sigl.append((playStringHardShort(lpitch,length,0.5),at+0.25*beat))
        sigr.append((playStringHardShort(lpitch,length,0.5),at+0.25*beat))
        sigl.append((playStringPluck(lpitch*2.01,length,0.6),at))
        sigr.append((playStringPluck(lpitch*1.99,length,0.4),at))
        sigl.append((playStringPluck(lpitch*1.99,length,0.6),at+0.25*beat))
        sigr.append((playStringPluck(lpitch*2.01,length,0.4),at+0.25*beat))    

    def vipvip():
        lpitch=pitch*sf.Semitone(())**7.0
        sigl.append((playStringPluck(lpitch,length,0.25),at))
        sigr.append((playStringPluck(lpitch,length,0.75),at))
        

    # 1
    pitch=sf.Note("D4")
    length=beat*0.5
    double()
    
    pitch=sf.Note("G6")
    vipvip()
    
    # 1.5
    at+=beat*0.5
    pitch=sf.Note("D4#")
    double()

    pitch=sf.Note("G6#")
    vipvip()
    
    # 2
    at+=beat*0.5
    pitch=sf.Note("E4")
    double()

    pitch=sf.Note("A6")
    vipvip()

    2.5
    at+=beat*0.5
    pitch=sf.Note("C4#")
    double()

    pitch=sf.Note("G6#")
    vipvip()

    # 3
    at+=beat*0.5
    pitch=sf.Note("D4")
    double()

    pitch=sf.Note("G6")
    vipvip()

    # 3.5
    at+=beat*0.5
    length=beat*0.4
    pitch=sf.Note("B3")
    double()

    pitch=sf.Note("G6#")
    vipvip()

    # 4
    at+=beat*0.5
    length=beat*0.5
    pitch=sf.Note("A3")
    double()

    pitch=sf.Note("F6")
    vipvip()
    
    # 4.5
    at+=beat*0.5
    length=beat*0.4
    pitch=sf.Note("B3")
    double()

    pitch=sf.Note("F6#")
    vipvip()
       
    left=sf.FixSize(sf.MixAt(sigl))
    right=sf.FixSize(sf.MixAt(sigr))
    wleft  = sf.Mix(
        granularReverb(+left, 2.00,beat*0.2,250),
        granularReverb(+left, 1.00,beat*0.4,250),
        granularReverb(+left, 0.50,beat*0.8,250),
        granularReverb(+left, 0.25,beat*0.8,250)
    )        
    wright = sf.Mix(
        granularReverb(+right,1.00,beat*0.2,250),
        granularReverb(+right,2.00,beat*0.4,250),
        granularReverb(+right,0.50,beat*0.8,250),
        granularReverb(+right,0.25,beat*0.8,250)
    )

    left2  = sf.Mix(sf.Pcnt40(+wleft), +left)
    right2 = sf.Mix(sf.Pcnt40(+wright),+right)

    print "Compiling Phrase11"
    
    pitch=sf.Note("A3")
    length=beat*2.0
    sigl=playStringHardLong(pitch,length,0.5)
    sigr=playStringHardLong(pitch,length,0.5)
    wleft  = sf.Mix(
        granularReverb(+sigl,0.50,beat,128),
        granularReverb( sigl,0.75,beat,128)
    )
    wright = sf.Mix(
        granularReverb(+sigr,0.50,beat,128),
        granularReverb( sigr,0.75,beat,128)
    )
    wleft  = sayBeat(wleft)
    wright = sayBeat(wright)
    
    left=sf.Normalise(sf.MixAt(
        (sf.Pcnt50(wleft),0),
        (sf.Pcnt50(left2),0)
    ))
    
    right=sf.Normalise(sf.MixAt(
        (sf.Pcnt50(wright),0),
        (sf.Pcnt50(right2),0)
    ))
        
    sf.WriteFile32([left,right],"temp/phrase-12.wav") 

def phrase14():
    print "Phrase 14"
    at   = 0
    sigl = []
    sigr = []

    # pitch up a fifth
    def double():
        lpitch=pitch*sf.Semitone(())**7.0
        sigl.append((playStringHardLong(lpitch*0.25,length*2.0,0.75),at))
        sigr.append((playStringHardLong(lpitch*0.25,length*2.0,0.25),at))
        sigl.append((playStringHardShort(lpitch*0.5,length*2.0,0.75),at))
        sigr.append((playStringHardShort(lpitch*0.5,length*2.0,0.25),at))
        sigl.append((playStringHardShort(lpitch,length,0.5),at))
        sigr.append((playStringHardShort(lpitch,length,0.5),at))
        sigl.append((playStringHardShort(lpitch,length,0.5),at+0.25*beat))
        sigr.append((playStringHardShort(lpitch,length,0.5),at+0.25*beat))
        sigl.append((playStringPluck(lpitch*2.01,length,0.6),at))
        sigr.append((playStringPluck(lpitch*1.99,length,0.4),at))
        sigl.append((playStringPluck(lpitch*1.99,length,0.6),at+0.25*beat))
        sigr.append((playStringPluck(lpitch*2.01,length,0.4),at+0.25*beat))    

    def vipvip():
        lpitch=pitch*sf.Semitone(())**7.0
        sigl.append((playStringPluck(lpitch,length,0.25),at))
        sigr.append((playStringPluck(lpitch,length,0.75),at))
        

    # 1
    pitch=sf.Note("D4")
    length=beat*0.5
    double()
    
    pitch=sf.Note("G6")
    vipvip()
    
    # 1.5
    at+=beat*0.5
    pitch=sf.Note("D4#")
    double()

    pitch=sf.Note("G6#")
    vipvip()
    
    # 2
    at+=beat*0.5
    pitch=sf.Note("E4")
    double()

    pitch=sf.Note("A6")
    vipvip()

    2.5
    at+=beat*0.5
    pitch=sf.Note("F4")
    double()

    pitch=sf.Note("G6#")
    vipvip()

    # 3
    at+=beat*0.5
    pitch=sf.Note("D4")
    double()

    pitch=sf.Note("G6")
    vipvip()

    # 3.5
    at+=beat*0.5
    length=beat*0.4
    pitch=sf.Note("D4#")
    double()

    pitch=sf.Note("G6#")
    vipvip()

    # 4
    at+=beat*0.5
    length=beat*0.5
    pitch=sf.Note("E4")
    double()

    pitch=sf.Note("F6")
    vipvip()
    
    # 4.5
    at+=beat*0.5
    length=beat*0.4
    pitch=sf.Note("F4")
    double()

    pitch=sf.Note("F6#")
    vipvip()
       
    left=sf.FixSize(sf.MixAt(sigl))
    right=sf.FixSize(sf.MixAt(sigr))
    wleft  = sf.Mix(
        granularReverb(+left, 4.00 ,beat*0.2,250),
        granularReverb(+left, 2.00 ,beat*0.4,250),
        granularReverb(+left, 0.25 ,beat*0.8,250),
        granularReverb(+left, 0.125,beat*0.8,512)
    )        
    wright = sf.Mix(
        granularReverb(+right,4.00 ,beat*0.2,250),
        granularReverb(+right,2.00 ,beat*0.4,250),
        granularReverb(+right,0.25 ,beat*0.8,250),
        granularReverb(+right,0.125,beat*0.8,512)
    )

    left2  = sf.Mix(sf.Pcnt50(+wleft), sf.Pcnt50(+left))
    right2 = sf.Mix(sf.Pcnt50(+wright),sf.Pcnt50(+right))

    print "Compiling Phrase14"
    
    pitch=sf.Note("B3")
    length=beat*2.0
    sigl=playStringHardLong(pitch,length,0.5)
    sigr=playStringHardLong(pitch,length,0.5)
    wleft  = sf.Mix(
        granularReverb(+sigl,0.50,beat,128),
        granularReverb( sigl,0.75,beat,128)
    )
    wright = sf.Mix(
        granularReverb(+sigr,0.50,beat,128),
        granularReverb( sigr,0.75,beat,128)
    )
    wleft  = sayBit(wleft)
    wright = sayBit(wright)
    
    left=sf.Normalise(sf.MixAt(
        (sf.Pcnt50(wleft),0),
        (sf.Pcnt50(left2),0)
    ))
    
    right=sf.Normalise(sf.MixAt(
        (sf.Pcnt50(wright),0),
        (sf.Pcnt50(right2),0)
    ))
        
    sf.WriteFile32([left,right],"temp/phrase-14.wav") 

def phrase15():
    print "Phrase 15"
    at   = 0
    sigl = []
    sigr = []

    # pitch up a octave and semitone
    def double():
        lpitch=pitch*sf.Semitone(())**13.0
        sigl.append((playStringHardLong(lpitch*0.25,length*2.0,0.75),at))
        sigr.append((playStringHardLong(lpitch*0.25,length*2.0,0.25),at))
        sigl.append((playStringHardShort(lpitch*0.5,length*2.0,0.75),at))
        sigr.append((playStringHardShort(lpitch*0.5,length*2.0,0.25),at))
        sigl.append((playStringHardShort(lpitch,length,0.5),at))
        sigr.append((playStringHardShort(lpitch,length,0.5),at))
        sigl.append((playStringHardShort(lpitch,length,0.5),at+0.25*beat))
        sigr.append((playStringHardShort(lpitch,length,0.5),at+0.25*beat))
        sigl.append((playStringPluck(lpitch*2.01,length,0.6),at))
        sigr.append((playStringPluck(lpitch*1.99,length,0.4),at))
        sigl.append((playStringPluck(lpitch*1.99,length,0.6),at+0.25*beat))
        sigr.append((playStringPluck(lpitch*2.01,length,0.4),at+0.25*beat))    

    def vipvip():
        lpitch=pitch*sf.Semitone(())**13.0
        sigl.append((playStringPluck(lpitch,length,0.25),at))
        sigr.append((playStringPluck(lpitch,length,0.75),at))
        

    # 1
    pitch=sf.Note("D4")
    length=beat*0.5
    double()
    
    pitch=sf.Note("G6")
    vipvip()
    
    # 1.5
    at+=beat*0.5
    pitch=sf.Note("D4#")
    double()

    pitch=sf.Note("G6#")
    vipvip()
    
    # 2
    at+=beat*0.5
    pitch=sf.Note("E4")
    double()

    pitch=sf.Note("A6")
    vipvip()

    2.5
    at+=beat*0.5
    pitch=sf.Note("F4")
    double()

    pitch=sf.Note("G6#")
    vipvip()

    # 3
    at+=beat*0.5
    pitch=sf.Note("D4")
    double()

    pitch=sf.Note("G6")
    vipvip()

    # 3.5
    at+=beat*0.5
    length=beat*0.4
    pitch=sf.Note("D4#")
    double()

    pitch=sf.Note("G6#")
    vipvip()

    # 4
    at+=beat*0.5
    length=beat*0.5
    pitch=sf.Note("E4")
    double()

    pitch=sf.Note("F6")
    vipvip()
    
    # 4.5
    at+=beat*0.5
    length=beat*0.4
    pitch=sf.Note("F4")
    double()

    pitch=sf.Note("F6#")
    vipvip()
       
    left=sf.FixSize(sf.MixAt(sigl))
    right=sf.FixSize(sf.MixAt(sigr))
    wleft  = sf.Mix(
        granularReverb(+left, 4.00 ,beat*0.2,250),
        granularReverb(+left, 2.00 ,beat*0.4,250),
        granularReverb(+left, 0.25 ,beat*0.8,250),
        granularReverb(+left, 0.125,beat*0.8,512)
    )        
    wright = sf.Mix(
        granularReverb(+right,4.00 ,beat*0.2,250),
        granularReverb(+right,2.00 ,beat*0.4,250),
        granularReverb(+right,0.25 ,beat*0.8,250),
        granularReverb(+right,0.125,beat*0.8,512)
    )

    left2  = sf.Mix(sf.Pcnt50(+wleft), sf.Pcnt50(+left))
    right2 = sf.Mix(sf.Pcnt50(+wright),sf.Pcnt50(+right))

    print "Compiling Phrase15"
    
    pitch=sf.Note("B3")
    length=beat*2.0
    sigl=playStringHardLong(pitch,length,0.5)
    sigr=playStringHardLong(pitch,length,0.5)
    wleft  = sf.Mix(
        granularReverb(+sigl,0.50,beat,128),
        granularReverb( sigl,0.75,beat,128)
    )
    wright = sf.Mix(
        granularReverb(+sigr,0.50,beat,128),
        granularReverb( sigr,0.75,beat,128)
    )
    wleft  = sayBoat(wleft)
    wright = sayBoat(wright)
    
    left=sf.Normalise(sf.MixAt(
        (sf.Pcnt50(wleft),0),
        (sf.Pcnt50(left2),0)
    ))
    
    right=sf.Normalise(sf.MixAt(
        (sf.Pcnt50(wright),0),
        (sf.Pcnt50(right2),0)
    ))
        
    sf.WriteFile32([left,right],"temp/phrase-15.wav") 

#phrase1()
#phrase2()
#phrase3()
#phrase4()
#phrase5()
#phrase6()
#phrase7()
#phrase8()
#phrase9()
#phrase10()
#phrase11()
#phrase12()
#phrase14()
#phrase15()

(left1,right1)=sf.ReadFile("temp/phrase-1.wav")
left1  = sf.Swap(left1)
right1 = sf.Swap(right1)

(left2,right2)=sf.ReadFile("temp/phrase-2.wav")
left2  = sf.Swap(left2)
right2 = sf.Swap(right2)


(left3,right3)=sf.ReadFile("temp/phrase-3.wav")
left3  = sf.Swap(left3)
right3 = sf.Swap(right3)

(left4,right4)=sf.ReadFile("temp/phrase-4.wav")
left4  = sf.Swap(left4)
right4 = sf.Swap(right4)

(left5,right5)=sf.ReadFile("temp/phrase-5.wav")
left5  = sf.Swap(left5)
right5 = sf.Swap(right5)

(left6,right6)=sf.ReadFile("temp/phrase-6.wav")
left6  = sf.Swap(left6)
right6 = sf.Swap(right6)

(left7,right7)=sf.ReadFile("temp/phrase-7.wav")
left7  = sf.Swap(left7)
right7 = sf.Swap(right7)

(left8,right8)=sf.ReadFile("temp/phrase-8.wav")
left8  = sf.Swap(left8)
right8 = sf.Swap(right8)

(left9,right9)=sf.ReadFile("temp/phrase-9.wav")
left9  = sf.Swap(left9)
right9 = sf.Swap(right9)

(left10,right10)=sf.ReadFile("temp/phrase-10.wav")
left10  = sf.Swap(left10)
right10 = sf.Swap(right10)

(left11,right11)=sf.ReadFile("temp/phrase-11.wav")
left11  = sf.Swap(left11)
right11 = sf.Swap(right11)

(left12,right12)=sf.ReadFile("temp/phrase-12.wav")
left12  = sf.Swap(left12)
right12 = sf.Swap(right12)

(left14,right14)=sf.ReadFile("temp/phrase-14.wav")
left14  = sf.Swap(left14)
right14 = sf.Swap(right14)

(left15,right15)=sf.ReadFile("temp/phrase-15.wav")
left15  = sf.Swap(left15)
right15 = sf.Swap(right15)

(left16,right16)=sf.ReadFile("temp/phrase-16.wav")
left16  = sf.Swap(left16)
right16 = sf.Swap(right16)

convoll=sf.Multiply(sf.WhiteNoise(beat*4.0),sf.NumericShape((0,0),(beat*0.5,1),(beat,0.1),(beat*4,0)))
convolr=sf.Multiply(sf.WhiteNoise(beat*4.0),sf.NumericShape((0,0),(beat*0.5,1),(beat,0.1),(beat*4,0)))
left13 =reverberate(+left12,convoll)
right13=reverberate(+right12,convolr)


left = sf.FixSize(
    sf.MixAt(
        ( sf.Pcnt30(                  +left1)      ,1000),
       
        ( sf.Pcnt40(                   left2)      ,1000+beat*4),

        ( sf.Pcnt20(sf.BesselHighPass(+left3,32,1)),1000+beat*8),

        ( sf.Pcnt40(sf.BesselHighPass( left4,32,1)),1000+beat*12),

        ( sf.Pcnt50(                   left5)      ,1000+beat*16),

        ( sf.Pcnt50(                   left6)      ,1000+beat*20),

        ( sf.Pcnt50(                   left7)      ,1000+beat*24),

        ( sf.Pcnt50(                  +left8)      ,1000+beat*28),
        ( sf.Pcnt50(                  +left8)      ,1000+beat*32),
        ( sf.Pcnt50(                  +left8)      ,1000+beat*36),

        ( sf.Pcnt50(                  +left9)      ,1000+beat*40),
        ( sf.Pcnt50(                  +left9)      ,1000+beat*44),
        ( sf.Pcnt50(                   left9)      ,1000+beat*48),
        
        ( sf.Pcnt50(                  +left10)     ,1000+beat*52),
        ( sf.Pcnt50(                  +left10)     ,1000+beat*56),
        ( sf.Pcnt50(                  +left10)     ,1000+beat*60),
     
        ( sf.Pcnt50(                  +left11)     ,1000+beat*64),
        ( sf.Pcnt50(                  +left11)     ,1000+beat*68),
        ( sf.Pcnt50(                  +left11)     ,1000+beat*72),
     
        ( sf.Pcnt50(                  +left12)     ,1000+beat*76),
        ( sf.Pcnt50(                  +left12)     ,1000+beat*80),
        ( sf.Pcnt50(                  +left12)     ,1000+beat*84),

        ( sf.Pcnt10(                  +left13)     ,1000+beat*88),
        ( sf.Pcnt10(                   left13)     ,1000+beat*92),

        ( sf.Pcnt20(sf.ButterworthHighPass(+left3,400,2)),1000+beat*96),
        ( sf.Pcnt20(sf.BesselHighPass(      left3,32 ,1)),1000+beat*100),
        
        ( sf.Pcnt50(                  +left8)      ,1000+beat*104),
        ( sf.Pcnt50(                  +left8)      ,1000+beat*108),
        ( sf.Pcnt50(                   left8)      ,1000+beat*112),

        ( sf.Pcnt50(                  +left10)     ,1000+beat*116),
        ( sf.Pcnt50(                  +left10)     ,1000+beat*120),
        ( sf.Pcnt50(                   left10)     ,1000+beat*124),
     
        ( sf.Pcnt50(                  +left11)     ,1000+beat*128),
        ( sf.Pcnt50(                  +left11)     ,1000+beat*132),
        ( sf.Pcnt50(                   left11)     ,1000+beat*136),
     
        ( sf.Pcnt50(                  +left12)     ,1000+beat*140),
        ( sf.Pcnt50(                  +left12)     ,1000+beat*144),
        ( sf.Pcnt50(                   left12)     ,1000+beat*148),

        ( sf.Pcnt50(                  +left14)     ,1000+beat*152),
        ( sf.Pcnt50(                  +left14)     ,1000+beat*156),
        ( sf.Pcnt50(                   left14)     ,1000+beat*160),

        ( sf.Pcnt50(                  +left15)     ,1000+beat*164),
        ( sf.Pcnt50(                  +left15)     ,1000+beat*168),
        ( sf.Pcnt50(                   left15)     ,1000+beat*172),

        ( sf.Pcnt50(                   left16)     ,1000+beat*178)
    )
)

right = sf.FixSize(
    sf.MixAt(
        ( sf.Pcnt20(                  +right1)      ,1000),
        
        ( sf.Pcnt60(                   right2)      ,1000+beat*4),
        
        ( sf.Pcnt30(sf.BesselHighPass(+right3,32,1)),1000+beat*8),
        
        ( sf.Pcnt60(sf.BesselHighPass( right4,32,1)),1000+beat*12),

        ( sf.Pcnt50(                   right5)      ,1000+beat*16),

        ( sf.Pcnt50(                   right6)      ,1000+beat*20),

        ( sf.Pcnt50(                   right7)      ,1000+beat*24),

        ( sf.Pcnt50(                  +right8)      ,1000+beat*28),
        ( sf.Pcnt50(                  +right8)      ,1000+beat*32),
        ( sf.Pcnt50(                  +right8)      ,1000+beat*36),

        ( sf.Pcnt50(                  +right9)      ,1000+beat*40),
        ( sf.Pcnt50(                  +right9)      ,1000+beat*44),
        ( sf.Pcnt50(                   right9)      ,1000+beat*48),
        
        ( sf.Pcnt50(                  +right10)     ,1000+beat*52),
        ( sf.Pcnt50(                  +right10)     ,1000+beat*56),
        ( sf.Pcnt50(                  +right10)     ,1000+beat*60),

        ( sf.Pcnt50(                  +right11)     ,1000+beat*64),
        ( sf.Pcnt50(                  +right11)     ,1000+beat*68),
        ( sf.Pcnt50(                  +right11)     ,1000+beat*72),

        ( sf.Pcnt50(                  +right12)     ,1000+beat*76),
        ( sf.Pcnt50(                  +right12)     ,1000+beat*80),
        ( sf.Pcnt50(                  +right12)     ,1000+beat*84),

        ( sf.Pcnt10(                  +right13)     ,1000+beat*88),
        ( sf.Pcnt10(                   right13)     ,1000+beat*92),
        
        ( sf.Pcnt20(sf.ButterworthHighPass(+right3,400,2)),1000+beat*96),
        ( sf.Pcnt20(sf.BesselHighPass(      right3,32,1)), 1000+beat*100),
        
        ( sf.Pcnt50(                  +right8)      ,1000+beat*104),
        ( sf.Pcnt50(                  +right8)      ,1000+beat*108),
        ( sf.Pcnt50(                   right8)      ,1000+beat*112),      

        ( sf.Pcnt50(                  +right10)     ,1000+beat*116),
        ( sf.Pcnt50(                  +right10)     ,1000+beat*120),
        ( sf.Pcnt50(                   right10)     ,1000+beat*124),

        ( sf.Pcnt50(                  +right11)     ,1000+beat*128),
        ( sf.Pcnt50(                  +right11)     ,1000+beat*132),
        ( sf.Pcnt50(                   right11)     ,1000+beat*136),

        ( sf.Pcnt50(                  +right12)     ,1000+beat*140),
        ( sf.Pcnt50(                  +right12)     ,1000+beat*144),
        ( sf.Pcnt50(                   right12)     ,1000+beat*148),
 
        ( sf.Pcnt50(                  +right14)     ,1000+beat*152),
        ( sf.Pcnt50(                  +right14)     ,1000+beat*156),
        ( sf.Pcnt50(                   right14)     ,1000+beat*160),

        ( sf.Pcnt50(                  +right15)     ,1000+beat*164),
        ( sf.Pcnt50(                  +right15)     ,1000+beat*168),
        ( sf.Pcnt50(                   right15)     ,1000+beat*172),

        ( sf.Pcnt50(                   right16)     ,1000+beat*178)       
    )
)

sf.WriteFile32((+left,+right),"temp/temp.wav")

(convoll,convolr)=sf.ReadFile("temp/TheChase-Revb.wav")

wleft =reverberate(+left,convoll)
wright=reverberate(+right,convolr)

left_out=sf.Normalise(sf.MixAt(
    (sf.Pcnt20(wleft),0),
    (sf.Pcnt80(left),00)
))

right_out=sf.Normalise(sf.MixAt(
    (sf.Pcnt20(wright),0),
    (sf.Pcnt80(right),0)
))

sf.WriteFile32((left_out,right_out),"temp/temp_postb.wav")


No comments:

Post a Comment