Showing posts with label generative. Show all posts
Showing posts with label generative. Show all posts

Sunday, 2 March 2014

Python: Creating Oscillators In Python

What is an Oscillator and how can we great one using a generator in Python?

An oscillator is something which naturally passes back and forth through some fixed or semi-fixed pattern. A simple but effective transistor based oscillator is a phase delay (or phase shift) circuit:
Wiki Commons - see here
http://en.wikipedia.org/wiki/File:RC_phase_shift_oscillator.svg 

The output is delayed and fed back into the input. The output is the inverse of the input. This means that without the delay the circuit would do nothing at all. However, because there is a delay it oscillates making a sine wave. We can make a Python generator do very much the same thing:

from com.nerdscentral.audio import SFData

def oscillator(damping):
    damping = float(damping)
    weight  =  0.1
    value   =  0.0
    middle  = value
    
    yield 0,0
        
    while(1):
        if(value>middle):
            weight-=damping
        else:
            weight+=damping

        value+=weight
                
        yield value,weight

It almost looks too simple to work but it does. The phase shift delay is not caused by 'recording' a sequence of output values and feeding them into the input (inverted). It is done by making the feedback cumulative. The variable weight is slowly shifted to oppose the variable value. If we plot the two variables as waves we get this:

Waveforms of weight and value.
value top.
weight bottom.
These are not plotted to amplitude scale.
The max value of wave is  ca 50 and the
max value of weight is ca .01
We can see from the above that weight is 90 degrees out of phase with value. We have made a phase delay oscillator. This approach makes a passible sine wave: However, the amplitude is not controlled at all that the produced wave for is not a very good sine wave. 

The spectrum of our oscillator output. The large number and
magnitude of harmonics shows it not to be a very pure
sine wave.
We can improve the stability and quality a lot with a simple addition:

def oscillator(damping):
    damping = float(damping)
    lower   = -1.0
    upper   =  1.0
    weight  =  0.1
    value   =  0.0
    middle  = value
    
    yield 0,0
        
    while(1):
        if(value>middle):
            weight-=damping
        else:
            weight+=damping

        value+=weight
                
        yield out,weight
        if(out<lower):
            value=prev
        elif(out>upper):
            value=prev

This addition locks the oscillator between +-1 and improves the sine wave quite a bit. The new spectrum looks like this (it is higher frequency for the given damping):

Slightly enhanced oscillator spectrum

Let's Make Some Sounds

Making oscillators is fun, but now we have an analogue style oscillator in Python, we really have a moral responsibility to make sounds with it! Will the computational equivalent of analogue make more complex and interesting signals and traditional digital stuff? Here is a much more interesting version of the oscillator:

def oscilator(damping,asym=1.0,mixer=0):
    damping = float(damping)
    lower   = -1.0
    upper   =  1.0
    weight  =  0.1
    value   =  0.0
    middle  = value
    gain    = 1.0
    prev    = 0.0
    cross   = 0.0
    pos     = 0.0
    gainV   = 0.9999
    xcount  = 0
    asym    = float(asym)
    
    yield 0,0,0
        
    while(1):
        if(value>middle):
            weight-=damping*asym
        else:
            weight+=damping

        if(mixer != 0):
            value+=mixer.next()
            
        value+=weight
        
        out=value*gain
        
        yield out,weight,xcount

        if(out<lower):
            value=prev
            gain*=gainV
        elif(out>upper):
            value=prev
            gain*=gainV
        elif(prev>0 and value<0):
            gain/=gainV
            xcount+=1
         
        pos+=1
        prev=value

def wobble(damping):
    wosc=oscilator(damping,1.0)
    while(1):
        s,t,xs=wosc.next()
        yield s*0.00001

The above uses recursive generators to make one oscillator inject instability into a second. We pass an instance of wobble into the mixer parameter of oscillator to get the effect. I have also added the ability to inject asymmetry into the oscillator to add harmonics. In have highlighted the bits of code which do these things.

We can put the output of our oscillator into a Sonic Field SFData object and then process it like any other sound:

from com.nerdscentral.audio import SFData
...
            data=SFData.build(len)
            for x in range(0,length):
                s,t,xs=osc.next()
                data.setSample(x,s)

Yes - it really is that simple to create an auto signal from a Python generator using Sython.

Warning - read the label carefully:

If you are  familiar with the determinism of working with normal digital signals, this approach will come as a bit of a shock. What you end up with is unstable and pretty much unpredictable. Though the output signal is deterministic (you run it twice you get the same numbers) it is also highly unstable. That really nice sine wave I showed above is a 'attractor' for the equation. It is a well behaved oscillating attractor. What you get with the more complex recursive version is a 'strange attractor'; the signal does not repeat it self. It might not even be a real attractor but just a semi-stable state from which, after enough cycles, the system will escape. Also, forget normal tuning, the output frequency is not linearly dependant on the input one. To get any sort of accurate pitch I would suggest counting the crossovers and then changing the sample rate to lock the pitch to that required.

First Creation:


Above is the first creation I have made with this new technique. It is not music at all. I wanted to create a sound into which the listener is placed which conveys the menace of WWII era piston engine aircraft. The very rich and ever changing 'analogue' nature of the oscillators does this in a way much more convincing that I think I could have managed using the normal sine wave generator and post processing approach of digital synthesis (or at least, not as easily).

Here is the patch which created the piece:


import math
import random
from com.nerdscentral.audio import SFData
    
def fixSize(signal):
    mag=sf.MaxValue(signal)
    return sf.NumericVolume(signal,1.0/mag)

def nullMixer():
    while(1):
        yield 0

def oscilator(damping,asym=1.0,mixer=0):
    damping = float(damping)
    lower   = -1.0
    upper   =  1.0
    weight  =  0.1
    value   =  0.0
    middle  = value
    gain    = 1.0
    prev    = 0.0
    cross   = 0.0
    pos     = 0.0
    gainV   = 0.9999
    xcount  = 0
    asym    = float(asym)
    
    yield 0,0,0
        
    while(1):
        if(value>middle):
            weight-=damping*asym
        else:
            weight+=damping

        if(mixer != 0):
            value+=mixer.next()
            
        value+=weight
        
        out=value*gain
        
        yield out,weight,xcount

        if(out<lower):
            value=prev
            gain*=gainV
        elif(out>upper):
            value=prev
            gain*=gainV
        elif(prev>0 and value<0):
            gain/=gainV
            xcount+=1
         
        pos+=1
        prev=value

def wobble(damping):
    wosc=oscilator(damping,1.0)
    while(1):
        s,t,xs=wosc.next()
        #print s
        yield s*0.00001

def invasion(d1,d2,seconds): 
    osc1=oscilator(d1,2,wobble(0.000020))
    osc2=oscilator(d1,2,wobble(0.000015))
    osc3=oscilator(d1,2,wobble(0.000010))
    osc4=oscilator(d1,2,wobble(0.000005))
    
    osc5=oscilator(d2,1.5,wobble(0.000020))
    osc6=oscilator(d2,1.5,wobble(0.000015))
    osc7=oscilator(d2,1.5,wobble(0.000010))
    osc8=oscilator(d2,1.5,wobble(0.000005))
        
    length=96000*seconds
    
    xs=0
    def drone(osc,len):
        def doDrone():
            data=SFData.build(len)
            print "Doing Drone"
            for x in range(0,length):
                s,t,xs=osc.next()
                data.setSample(x,s)
            # Go to a lot of effort to remove
            # clicks due to DC offset of the start and end
            l=sf.Length(data)
            data=sf.ButterworthHighPass(sf.Normalise(data),10,2)
            data=sf.Multiply(
                data,
                sf.NumericShape((0,0),(256,0),(l/2,1),(l-256,0),(l,0))
            )
            data=sf.Multiply(
                sf.Saturate(data),
                sf.NumericShape((0,0),(256,1),(l-256,1),(l,0))
            )
            return sf.Realise(data)
        return sf_do(doDrone)
    
    data1=drone(osc1,length)
    data2=drone(osc2,length)
    data3=drone(osc3,length)
    data4=drone(osc4,length)
    data5=drone(osc5,length)
    data6=drone(osc6,length)
    data7=drone(osc7,length)
    data8=drone(osc8,length)
    
    def mix1():
        return sf.Realise(
            fixSize(
                sf.MixAt(
                    (sf.Pcnt10(data2),30),
                    (sf.Pcnt20(data3),20),
                    (data1,0),
                    (data4,0),
                    (sf.Pcnt10(data6),30),
                    (sf.Pcnt20(data7),20),
                    (data5,0),
                    (data8,0)
                )
            )
        )
    
    def mix2():
        return sf.Realise(
            fixSize(
                sf.MixAt(
                    (sf.Pcnt10(data1),30),
                    (sf.Pcnt20(data4),20),
                    (data2,0),
                    (data3,0),
                    (sf.Pcnt10(data6),30),
                    (sf.Pcnt20(data7),20),
                    (data5,0),
                    (data8,0)
                    
                )
            )
        )
        
    dataL=sf_do(mix1)
    dataR=sf_do(mix2)
    return (dataL,dataR)

dataL1,dataR1=invasion(0.000025,0.000015,45)
dataL2,dataR2=invasion(0.000020,0.000007,45)
dataL3,dataR3=invasion(0.000011,0.000010,45)
dataL4,dataR4=invasion(0.000010,0.000012,45)
dataL=sf.Normalise(
    sf.MixAt(
        (dataL1, 0),
        (dataL2, 30000),
        (dataL3, 60000),
        (dataL1, 90000),
        (dataL4,120000),
        (dataL1,150000),
        (dataL4,160000)
    )
)

dataR=sf.Normalise(
    sf.MixAt(
        (dataR1,     0),
        (dataR2, 30000),
        (dataR3, 60000),
        (dataR1, 90000),
        (dataR4,120000),
        (dataR1,150000),
        (dataR4,160000)
    )
)
sf.WriteFile32((dataL,dataR),"temp/temp.wav")
dataL=0
dataR=0

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 
            l=sf.Length(signal_)
            sf.Multiply(
                sf.NumericShape(
                    (0,1),
                    (l-100,1),
                    (1,0)
                ),
                signal_
            )
            return signal_
        else:
            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_,at)=grain
            out.append((reverbInner(signal_,convol_,grainLength),at))
        return sf.Normalise(sf.MixAt(out))
    return sf_do(reverberateDo)
 
(left,right)=sf.ReadFile("temp/temp.wav")

(convoll,convolr)=sf.ReadFile("temp/revb.wav")
wleft =reverberate(left,convoll)
wright=reverberate(right,convolr)

left=sf.Normalise(sf.MixAt(
    (sf.Pcnt40(wleft),10),
    (sf.Pcnt5(wright),40),
    (sf.Pcnt5(wleft),120),
    (sf.Pcnt45(left),0),
    (sf.Pcnt5(right),110)
))

right=sf.Normalise(sf.MixAt(
    (sf.Pcnt40(wright),10),
    (sf.Pcnt5(wleft),40),
    (sf.Pcnt5(wright),130),
    (sf.Pcnt45(right),0),
    (sf.Pcnt5(left),105)
))

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


Friday, 21 February 2014

The Code Behind Valley Of The Sythons

The entire patch and some description of how it works beneath that:

The key to understanding what comes next is that Sonic Field now works as a big extension to Python (Jython actually - Python running on the Java Vertual Machine). A Sonic Field patch is created using Python statements. However, the data being passed around is not Python Data it is hidden from the view of Python inside opaque Java objects. 

Valley Of The Sythons

The original idea was that Sonic Field sounds were 'signals' which were passed between 'processors'. Control of processing was also done via signals. The metaphor continues into Sython (Sonic Field Python). The syntax of Python makes the approach less obvious but it is still there.

sf.Multiply(sf.NumericShape((0,0),(len,1)),trem)

For example the above creates a signal which starts at 0 and works up to 1 at length len in milliseconds. The signal is then multiplied with another signal held in variable trem.  All Sonic Field processors are exposed to Python as methods on the sf object.

One last example before the code dump:

sf.Monitor(sf.SineWave(1000,440))

The above is a very simple Sython patch. It just makes an A4 tone for one second. However, the tone will have clicks at each end because it has no attack or release. So:

sf.Monitor(
    sf.Multiply(
        sf.SimpleShape((0,-90),(100,0),(900,0),(1000,-90)),
        sf.SineWave(1000,440)
    )
)

Now that does have an attack and release so it will sound much more like the beep one might expect.

Valley Of The Sythons:

import math
import random

execfile("patches/python/concurrent.py")

def randWalk(value,size,uBound):
    value  = float(value)
    size   = float(size)
    uBound = float(uBound)
    r=random.random()
    r=math.floor(r*size)-math.floor((size/2.0))    
    value+=r
    if value<1:
        value=2
    elif value>uBound:
        value=uBound-2
    return value

def randWalk3(value,uBound):
    return randWalk(value,3,uBound)

def fixSize(signal):
    mag=sf.MaxValue(signal)
    return sf.NumericVolume(signal,1.0/mag)
 
def fixSizeSat(signal):
     return fixSize(sf.Saturate(fixSize(signal)))
    
def saturatedNode(beat,pPitch,pitch,a,d,s,r,v):
    def saturateNode_():
        l=a+d+s+r
        if l>beat*2:
            iPitch=(pitch+pPitch)/2.0
            pos=beat/8
            signal1=sf.Slide((0,iPitch),(pos,pitch),(l,pitch))
            signal2=sf.Slide((0,iPitch),(pos,pitch*2),(l,pitch*2.02))
            signal3=sf.Slide((0,iPitch),(pos,pitch*3),(l,pitch*3.03))
        else:
            signal1=sf.SineWave(l,pitch)
            signal2=sf.SineWave(l,2*pitch*1.003)
            signal3=sf.SineWave(l,3*pitch*1.005)
            
        envelope= sf.NumericShape(
                 (0,0),
                 (a,1),
                 (a+d,0.75),
                 (a+d+s,0.25),
                 (a+d+s+r,0)
        )
        
        sat=(20-pitch/1000)
        if sat<1:
            sat=1
                        
        def doSat(sigIn):
            temp=sf.NumericVolume(sf.Multiply(sigIn,envelope),sat)
            return sf.Normalise(sf.Clean(sf.Saturate(temp)))

        signal=sf.Mix(
            doSat(signal1),
            sf.DB_6(doSat(signal2)),
            sf.DB_15(doSat(signal3))
        )
        
        envelope= sf.NumericShape(
                 (0,0),
                 (a,0.1),
                 (a+d,0),
                 (a+d+s,0.1),
                 (a+d+s+r,0)
        )
        
        signal=sf.Mix(
            sf.Multiply(
                sf.ButterworthLowPass(sf.WhiteNoise(l),pitch*5,1),
                envelope),
            signal
        )
        
        signal=fixSize(signal)
        
        hf=sf.Clip(sf.NumericVolume(signal,3))
    
        r1=fixSizeSat(sf.RBJPeaking(hf,pitch*1.3,0.5,85))
        r2=fixSizeSat(sf.RBJPeaking(hf,pitch*2.1,0.5,85))
        r3=fixSizeSat(sf.RBJPeaking(hf,pitch*2.9,0.5,85))
    
        signal=sf.Mix(
            sf.DB_6(signal),
            sf.DB_1(r1),
            sf.DB_4(r2),
            sf.DB_6(r3)
        )
        
        signal=sf.Clean(sf.NumericVolume(signal,v))

        signal=sf.BesselLowPass(signal,pitch*2,4)

        envelope= sf.NumericShape(
                 (0,1),
                 (a+d+s+r-125,1),
                 (a+d+s+r,0)
        )
        signal=sf.Multiply(envelope,signal)
        
        trem=sf.Slide((0,6*random.random()),(l,0.5*random.random()))
        trem=sf.Multiply(sf.NumericShape((0,0),(l,1)),trem)
        trem=sf.Mix(
            sf.NumericShape((0,1),(l,1)),
            trem
        )
        return sf.Multiply(signal,trem)
        
    return sf_do(saturateNode_)

def run(pitch,beat,minutes,startP,initial,overV):
    notesL=[]
    notesR=[]
    oPitch=float(pitch)
    pitchScaleDenom = 1.0
    pitchScaleNume  = float(startP)
    lengthScale     = 4.0
    volumeScale     = 4.0
    oVolume         = 4.0
    at=beat*float(initial)
    pPitch=float(pitch)

    while at/60000 < minutes:
        pitchScale = pitchScaleNume/pitchScaleDenom
        rvs        = 1.0/volumeScale
        volume     = rvs*oVolume
        pitch      = pitchScale*oPitch
        length     = lengthScale*beat

        
        # Create a consistent envelope
        a          = length*0.25
        d          = length*0.5
        s          = length*1.0
        r          = length*2.0
        if a<50:
            a=50
        if d<50:
            d=50
        if a>d-50:
           a=d/2
        
        r=r-s-d-a
        s=s-d-a
        d=d-a       
        
        vCorrection = 1/pitchScale
        
        # Do not over correct very & v high low frequencies 
        #  or very quiet notes. This aim it to stop loud highs
        #  dominating (psycho-acoustics)
        if rvs<0.2:
            if vCorrection<1:
                vCorrection=1
        
        if vCorrection>4:
            vCorrection=4
                                  
        print (
            at,
            "PitchNume: ",  pitchScaleNume,
            "PitchDenom: ", pitchScaleDenom,
            "Volume: ",     volumeScale,
            "Pitch: ",      pitch,
            "Length: ",     length,
            "Rvs: ",        rvs,
            "VCorr: ",      vCorrection
        ).__str__()    
            
        signal = saturatedNode(
            beat,
            pPitch,
            pitch,
            a,
            d,
            s,
            r,
            volume * vCorrection
        )

        lr=random.random()
        rl=1.0-lr
        notesL.append([sf.NumericVolume(signal,lr),at+30*rl])
        notesR.append([sf.NumericVolume(signal,rl),at+30*lr])

        at+=length
        
        pitchScaleDenom = randWalk3(pitchScaleDenom,10)

        pitchScaleNume  = randWalk3(pitchScaleNume,16)
        
        lengthScale     = randWalk3(lengthScale,8)

        volumeScale     = randWalk3(volumeScale,8)
        
        pPitch          = pitch

    return (
        sf.NumericVolume(sf.Normalise(sf.Clean(sf.MixAt(notesL))),overV),
        sf.NumericVolume(sf.Normalise(sf.Clean(sf.MixAt(notesR))),overV)
    )

def compressInner(signal,amount):
    def compressInnerDo():
        if sf.MaxValue(signal)<0.001:
            return signal
        signal_=sf.Normalise(signal)
        stf=sf.Normalise(sf.ButterworthLowPass(signal_,128,2))
    
        offset=1.0-amount    
        sr=sf.Reverse(sf.Follow(sf.Reverse(stf),1,1024))
        sw=sf.Follow(stf,1,1024)
        shape=sf.Mix(sr,sw)
        div=1.0/sf.MaxValue(shape)
        shape=sf.NumericVolume(shape,div)
        shape=sf.DirectMix(offset,sf.NumericVolume(shape,amount))
        return sf.Normalise(sf.Divide(signal_,shape))
    return sf_do(compressInnerDo)

def compress(signal,amount):
    def compressDo():
        cpo=amount
        signalM=sf.BesselBandPass(signal,200,2000,4)
        signalH=sf.BesselHighPass(signal    ,2000,4)
        signalL=sf.BesselLowPass( signal    , 200,4)
        amount_=cpo*cpo 
        
        signalM=compressInner(signalM, amount_)
        signalH=compressInner(signalH, amount_)
        signalL=compressInner(signalL, amount_)
    
        return sf.Normalise(sf.MixAt(
            (sf.Pcnt40(signalL),3.5),
            (sf.Pcnt20(signalM),0.0),
            (sf.Pcnt40(signalH),0.0)
        ))
    return sf_do(compressDo)
    

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 
            l=sf.Length(signal_)
            sf.Multiply(
                sf.NumericShape(
                    (0,1),
                    (l-100,1),
                    (1,0)
                ),
                signal_
            )
            return signal_
        else:
            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_,at)=grain
            out.append((reverbInner(signal_,convol_,grainLength),at))
        return sf.Normalise(sf.MixAt(out))
    return sf_do(reverberateDo)

def doRun1():
   return run(128,1024          ,6,1,0,1.0)
def doRun2():
   return run(128.0*4.0/3.0,1024,6,2,1,1.0)
def doRun3():
   return run(256.0*3.0/2.0,1024,6,1,5,0.5)
def doRun4():
   return run(512.0*5.0/4.0,1024,6,1,9,0.25)

random.seed(0.128)

x1=sf_do(doRun1)
x2=sf_do(doRun2)
(left1,right1) = x1.get()
sf.WriteSignal(left1,"temp/l1")
sf.WriteSignal(right1,"temp/r1")

(left2,right2) = x2.get()
sf.WriteSignal(left2,"temp/l2")
sf.WriteSignal(right2,"temp/r2")

x3=sf_do(doRun3)
x4=sf_do(doRun4)

(left3,right3) = x3.get()
sf.WriteSignal(left3,"temp/l3")
sf.WriteSignal(right3,"temp/r3")

(left4,right4) = x4.get()
sf.WriteSignal(left4,"temp/l4")
sf.WriteSignal(right4,"temp/r4")


left1=sf.ReadSignal("temp/l1")
left2=sf.ReadSignal("temp/l2")
left3=sf.ReadSignal("temp/l3")
left4=sf.ReadSignal("temp/l4")
left  = sf.Normalise(sf.Clean(fixSize(sf.Mix(left1,left2,left3,left4))))
left  = compress(left,0.33)
sf.WriteSignal(left,"temp/l")
left=""

right1=sf.ReadSignal("temp/r1")
right2=sf.ReadSignal("temp/r2")
right3=sf.ReadSignal("temp/r3")
right4=sf.ReadSignal("temp/r4")
right = sf.Normalise(sf.Clean(fixSize(sf.Mix(right1,right2,right3,right4))))

right = compress(right,0.33)
sf.WriteSignal(right,"temp/r")
right=""

sf.WriteFile32((sf.ReadSignal("temp/l"),sf.ReadSignal("temp/r")),"temp/temp.wav")

(left,right)=sf.ReadFile("temp/temp.wav")

(convoll,convolr)=sf.ReadFile("temp/terrys_warehouse_stereo_short.wav")
convoll=sf.Mix(
    convoll,
    sf.Pcnt15(sf.DirectRelength(convoll,0.2)),
    sf.Pcnt15(sf.Raise(sf.DirectRelength(convolr,0.2),2))
)
convolr=sf.Mix(
    convolr,
    sf.Pcnt15(sf.DirectRelength(convolr,0.2)),
    sf.Pcnt15(sf.Raise(sf.DirectRelength(convolr,0.2),2))
)
convoll=sf.Normalise(sf.Saturate(sf.Normalise(convoll)))
convolr=sf.Normalise(sf.Saturate(sf.Normalise(convolr)))

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

left=sf.Normalise(sf.MixAt(
    (sf.Pcnt70(wleft),10),
    (sf.Pcnt10(wright),40),
    (sf.Pcnt20(left),0)
))

right=sf.Normalise(sf.MixAt(
    (sf.Pcnt70(wright),10),
    (sf.Pcnt10(wleft),40),
    (sf.Pcnt20(right),0)
))

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

(left,right)=sf.ReadFile("temp/temp_post.wav")

left  = compress(left,0.95)
right = compress(right,0.95)

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

shutdownConcurrnt()

First the dirty! Why 'execfile("patches/python/concurrent.py")' The answer is that I could not be bothered to set up sys.path or the class path correctly - me bad :( [I have fixed it in later patches]

Now for the Random Walk code:


def randWalk(value,size,uBound):
    value  = float(value)
    size   = float(size)
    uBound = float(uBound)
    r=random.random()
    r=math.floor(r*size)-math.floor((size/2.0))    
    value+=r
    if value<1:
        value=2
    elif value>uBound:
        value=uBound-2
    return value

def randWalk3(value,uBound):
    return randWalk(value,3,uBound)

The core concept behind the piece is constraining randomness to give patters which shift around slowly forming shape and movement in the piece. Here we see a few key points. Working with Random numbers requires a close interaction between integer and non integer numbers. randWalk take an number (assumed to be an integer) and moves it randomly up or down. However, the maximum distance it can move is fixed by the size parameter. The maximum value it can reach is fixed by the uBound parameter and the minimum is 1. This causes the 'random walk' effect that the music is based upon. randWalk3 is simply a helper function (I prefer this to default parameters in some cases as it is more explicit).

        if l>beat*2:
            iPitch=(pitch+pPitch)/2.0
            pos=beat/8
            signal1=sf.Slide((0,iPitch),(pos,pitch),(l,pitch))
            signal2=sf.Slide((0,iPitch),(pos,pitch*2),(l,pitch*2.02))
            signal3=sf.Slide((0,iPitch),(pos,pitch*3),(l,pitch*3.03))
        else:
            signal1=sf.SineWave(l,pitch)
            signal2=sf.SineWave(l,2*pitch*1.003)
            signal3=sf.SineWave(l,3*pitch*1.005)

The above piece of code is interesting as it alters note articulation based on note length. Short notes will have the same pitch throughout. However, longer notes will have a short 'slur' or 'slide' between them by bending the start of the next note to the average to the two.

We can also see here that each note it made from 3 tones. However, what we hear in Valley is very much more harmonically rich than that.

        envelope= sf.NumericShape(
                 (0,0),
                 (a,1),
                 (a+d,0.75),
                 (a+d+s,0.25),
                 (a+d+s+r,0)
        )
        
        sat=(20-pitch/1000)
        if sat<1:
            sat=1
                        
        def doSat(sigIn):
            temp=sf.NumericVolume(sf.Multiply(sigIn,envelope),sat)
            return sf.Normalise(sf.Clean(sf.Saturate(temp)))

        signal=sf.Mix(
            doSat(signal1),
            sf.DB_6(doSat(signal2)),
            sf.DB_15(doSat(signal3))
        )

The addition of harmonic complexity is done with the above code. First we create a standard ADSR envelope. Then we work out an number related to pitch which will be used to control the amount of harmonic richness to add. The reason to base it on pitch is that physical instruments tend to have more harmonic in their lower registers and so mimicking this mathematically produces sounds which are more interesting to listen to. 

        @Override
        public double getSample(int index)
        {
            double x = getInputSample(index);
            double y = x >= 0 ? x / (x + 1) : x / (1 - x);
            return y;

        }

The above is the Java (remember that audio processing heavy work in Sonic Field is done in Java not Python). It is a rather magical formula because it is so simple and yet so effective. It simply forces any value in the incoming signal to fit between 1 and -1. It does this by asymptotically crushing the signal as it approaches 1 or -1.
X and X/(X+1)
I came up with the idea of using this as a audio processor (strictly a wave shaper) one evening whilst working in Cambridge a couple of years ago. It is so simple and yet so effective, I could not believe my luck in thinking of it (I was dreaming of complex polynomials and logs and things). We can see that to begin with (X near 0) X and X(X+1) are similar but as X grows the processed wave bends over to approach 1 (and -1 for the X/(1-X) version for negative numbers). As a result, the wave form is distorted to become closer to a square wave. This add odd harmonics. The larger the amplitude of the incoming wave the more the distortion and the greater the addition of harmonics. A sine wave a large magnitude entering the wave shaper will come out as a rounded square wave.

The effect of greater amplitude -> greater harmonic content also mimics natural instruments. By using the saturate processor after the application of an envelope we make the harmonic content follow the envelope just as it does with - for example - a Sax where the louder the note the 'brighter' it sounds. 

The link between pitch and harmonic content is performed the same way:

        def doSat(sigIn):
            temp=sf.NumericVolume(sf.Multiply(sigIn,envelope),sat)
            return sf.Normalise(sf.Clean(sf.Saturate(temp)))

We use the saturation processor on the output result of setting the over all volume (amplitude) of the signal by the variable sat. sat is bigger for lower notes and so amplitude will be bigger and so the harmonic content larger.

Note:

  1. sf.Clean removes higher frequencies using a special finite impulse response filter to avoid build up of those frequencies. This prevents further processing causing harmonics of high frequencies getting so high the alias.
  2. sf.Normalise removes any DC from the signal and sets the maximum excursion to 1 by scaling the whole signal. By DC I mean, the sum of all the samples in the signal is the DC component. Build up of DC is a constant problem in digital processing which does not happen in analogue as the capacitors used to link circuits automatically remove all DC.

Finally for this section: why three signals? I leave that up to you to think about.

Next - resonance and body sounds


        hf=sf.Clip(sf.NumericVolume(signal,3))
    
        r1=fixSizeSat(sf.RBJPeaking(hf,pitch*1.3,0.5,85))
        r2=fixSizeSat(sf.RBJPeaking(hf,pitch*2.1,0.5,85))
        r3=fixSizeSat(sf.RBJPeaking(hf,pitch*2.9,0.5,85))

When a real instrument is played it shakes. For strings the shanking in part of the projecting of the sound. For brass, it produces a percussive timbre on top of the fundamental sound of the instrument. In the patch fragment above, I am attempting to mimc the effect of such shaking. This is done by passing the signal into infinite impulse response filters which are set to near resonance. Any signal passed into them which contains frequencies near to their resonant frequency will cause them to ring.

The 'near to their resonant frequency' is important. They will not resonate if signal is passed in which does not contain the required references. We can see here that I have not set their resonant frequencies to those of the notes so how will they resonate? The trick is in the sf.Clip. This hard limits signals so that if a sample goes above 1 it is set to 1 and if it goes below -1 it is set to -1. That hard limiting sprays frequencies all over the spectrum (think electric guitar fuzz). The resonators can pick up some of that sprayed frequency and resonate form it. Because the clipping will be dependant of amplitude of the signal the resonance will as well, which again, is the way physical instruments tend to work.

In my next post I will discuss compression, reverberation and well the Sonic Field - that for which Sonic Field was first created.

Sunday, 21 October 2012

Caverns Of Ganymede

Based upon the same generative framework as Oceans Of Europa, this is a very much more complex composition. It is only 10 minutes long because beyond that, without some considerable enhancements to Sonic Field, my computer runs out of memory!

The generative framework is slow enough in this piece to create a single theme which moves through the entire composition as a single piece. The sounds are a combination of string type effects, bells (using FM synthesis - see Bells Of Time) and simple oscillator effects. It is the use of resonance synthesis which gives the sounds complexity.

This piece employs some of the multi-dimensional stereo effects I first had real success with in Parted. Not only does it use left/center/right and Haas method to give left/right position and width but it uses carefully placed early reflections and long running reverberation to open out the sound stage infront and behind the listener.

Tuesday, 16 October 2012

Jam In A Junk Yard Beginning


Pump up the volume!
Copyright: Dr Alexander J Turner All Rights Reserved
To try out the new and shiny (well - newly working) shaped band pass filter I have started to work on a series of ideas I call "Jam In A Junk Yard". The idea being to synthesise highly metallic sounds which are close to but not quite notes and use them to drive rhythms.

Check out music on sonic-field:
Jam In A Junk Yard Beginning

I am a big believer in creativity being derived form limitation. Given the near infinite pallet of sound creating techniques which a blank Sonic Field patch offers I just sit and think 'what should I do'. To create Jam In A Junk Yard Beginning I gave myself one sound generating patch and said 'you can only make sounds with this by altering its controls, stereo placement or resampling'. That much more restrictive environment lead to the creation of an interesting set of very metallic sounds (I hope).

To see and hear the piece on Youtube go here. Please listen/view in HD for get good quality. Also note that this piece uses some seriously low notes so laptop speakers will not play it properly.



So - what is this sub-patch from hell? It is a simple enough additive  subtractive, FM thing with some feedback delay. Really, it is not that complex so lets have a look at it:

(
        (?length,?pitch)SinWave MakeTriangle dbs+6,
        (?length,(?pitch,2)/)SinWave MakeTriangle dbs-6,
        (?length,(?pitch,4)/)SinWave MakeTriangle dbs-6,
        (?length,(?pitch,8)/)SinWave MakeTriangle
    )Mix Normalise !signal
    
This is the source of the sound; it is a simple addition of triangle waves which are in unusual magnitudes. Effectively, it contains sub-harmonics because the lower signals we much weaker then the high. Triangle waves only have odd harmonic overtones and I added even sub-harmonics; this thickens out the sound without creating any even harmonics from overlaying. The result in a big fat sound which is just right for subtraction and frequency modulation.

Some of those sub-harmonics become infra-sound for low notes so I filter out that then apply a band pass filter which is shaped. This means the lower and upper shoulders of the filter vary over time using two envolopes. I apply the filter three times to make it really sharp. This is numerically more stable than trying to apply a very steep filter in one go.

(&gt;signal,15,2)DirectHighPass !signal
    
    (&gt;signal,?low-shape,?high-shape,?order)ShapedBandPass Normalise !signal
    (&gt;signal,?low-shape,?high-shape,?order)ShapedBandPass Normalise !signal
    (&gt;signal,&gt;low-shape,&gt;high-shape,?order)ShapedBandPass Normalise !signal

Now we have a sound the timbre of which varies over time. The envelope (shape) for these filters is generated thus:

(?pitch,8)/ !bass
    ((0,?bass),(?wide-point,?bass),(?narrow-point,(?pitch,?narrow-amount)*),(?length,(?pitch,0.95)*))NumericShape !low-shape
    ((0,1000) ,(?wide-point,1000) ,(?narrow-point,(?pitch,?narrow-amount)/),(?length,(?pitch,0.95)*))NumericShape !high-shape

So the sound starts with very little filtering and then narrows to one width and then narrows again to a very tight filter. That is at least the way I use it; the patch is complex enough to allow the filter to widen towards the end if that effect was desired. The width and positioning of these points are parameters for the patch.

Next I hit it with frequency modulation and overdrive. This makes it sound like a mike over loading listening to a piece of metal being hit - which is where the junk yard sound comes from:

(
        &gt;signal,
        (
            (
                ?length,
                (?pitch,1.2)*
            )SinWave,
            ?modulation-index
        )Volume
    )FrequencyModulate !signal 
    ((
        (?a,?b,?c,?d,?e)NumericShape,
        &gt;signal
    )Multiply Normalise,?over-drive)Volume Saturate Normalise !signal

Finally some feed back delay (like guitarists use but with more layers) is applied to give resonance to the sound and some post filtering to help control the brilliance (to give dull thuds and sharper clangs) and cut low rumble is added.

(?length,2000)/ !res-scale
    (
        (?signal,4000 Silence)Concatenate,
        (
            (-14,((160,?pitch Period)+,?res-scale)* Prime),
            (-15,((190,?pitch Period)+,?res-scale)* Prime),
            (-14,((320,?pitch Period)+,?res-scale)* Prime),
            (-15,((355,?pitch Period)+,?res-scale)* Prime),
            (-17,((380,?pitch Period)+,?res-scale)* Prime)
        )
    ) DirectResonate Normalise !wet
    (
        &gt;wet,
        ?signal Invert
    )Mix !wet
    (
        &gt;signal,
        &gt;wet Normalise
    )Mix Normalise !signal
    
    (&gt;signal,?post-cut-low,3 )DirectLowPass Normalise !signal
    (&gt;signal,?post-cut-high,2)DirectHighPass Normalise !signal
    &gt;signal ClipToSafe

All this processing can result in the zero point of the signal moving away from true zero. ClipToSafe removes any annoying clicks which this would produce in the mix.

The result of the patch creates sounds to make a rhythm. With some suggestions form my wonderful wife, this version of Jam In A Junk Yard messes with that rhythm. The piece is generated twice with very slightly different beats. One is at 750 milliseconds and the other at 760. The stereo mix is inverted in the two versions. It is the result of this which is passed into a simple and slightly claustrophobic reverb' effect. My messing with the rhythm timing this way, the two generations move through one another. Listening to the sounds produces (in me) the interesting effect that just as I think I am getting used to it the rhythms move enough to create a noticeably different pattern and I am drawn back into the piece. I would not say it captures my attention for all 21 minutes (hardly!) but as something in the background which reaches forward into the foreground every so often - it is quite surprising. The most obvious place to hear this effect is around 15 minutes in where the two rhythms line up and the Haas effect makes the sounds appear wide instead of distinct left and right channels; then, over the next minute or so the rhythms slowly separate.

I hope to make a release of Sonic Field which has the newly working filter in it later this week.


Note that this patch and the music its creates is Copyright Dr Alexander J Turner 2012 and I license it under theCreative Commons Attribution 3.0 license. To use the patch or any music derived from it etc, please attribute Sonic Field, myself and this original work.

{
    (?pitch,8)/ !bass
    ((0,?bass),(?wide-point,?bass),(?narrow-point,(?pitch,?narrow-amount)*),(?length,(?pitch,0.95)*))NumericShape !low-shape
    ((0,1000) ,(?wide-point,1000) ,(?narrow-point,(?pitch,?narrow-amount)/),(?length,(?pitch,0.95)*))NumericShape !high-shape
    (
        (?length,?pitch)SinWave MakeTriangle dbs+6,
        (?length,(?pitch,2)/)SinWave MakeTriangle dbs-6,
        (?length,(?pitch,4)/)SinWave MakeTriangle dbs-6,
        (?length,(?pitch,8)/)SinWave MakeTriangle
    )Mix Normalise !signal
    
    (&gt;signal,15,2)DirectHighPass !signal
    
    (&gt;signal,?low-shape,?high-shape,?order)ShapedBandPass Normalise !signal
    (&gt;signal,?low-shape,?high-shape,?order)ShapedBandPass Normalise !signal
    (&gt;signal,&gt;low-shape,&gt;high-shape,?order)ShapedBandPass Normalise !signal
    
    (
        &gt;signal,
        (
            (
                ?length,
                (?pitch,1.2)*
            )SinWave,
            ?modulation-index
        )Volume
    )FrequencyModulate !signal 
    ((
        (?a,?b,?c,?d,?e)NumericShape,
        &gt;signal
    )Multiply Normalise,?over-drive)Volume Saturate Normalise !signal
    (?length,2000)/ !res-scale
    (
        (?signal,4000 Silence)Concatenate,
        (
            (-14,((160,?pitch Period)+,?res-scale)* Prime),
            (-15,((190,?pitch Period)+,?res-scale)* Prime),
            (-14,((320,?pitch Period)+,?res-scale)* Prime),
            (-15,((355,?pitch Period)+,?res-scale)* Prime),
            (-17,((380,?pitch Period)+,?res-scale)* Prime)
        )
    ) DirectResonate Normalise !wet
    (
        &gt;wet,
        ?signal Invert
    )Mix !wet
    (
        &gt;signal,
        &gt;wet Normalise
    )Mix Normalise !signal
    
    (&gt;signal,?post-cut-low,3 )DirectLowPass Normalise !signal
    (&gt;signal,?post-cut-high,2)DirectHighPass Normalise !signal
    &gt;signal ClipToSafe
} !clang

{
    0   !time
    2000        !length
    2           !order
    "e0b" note  !pitch
     200        !wide-point
     600        !narrow-point
    0.7         !narrow-amount
    (1.0,0)     !a
    (1,500)     !b
    (1000,0.5)  !c
    (1850,0.25) !d
    (?length,0) !e
    "e4b" Note  !post-cut-low
    15          !post-cut-high
    0           !modulation-index 
    
    24          !over-drive
    ?clang Do   !1
    
    36          !over-drive
    "e1b" note  !pitch
    0.99        !narrow-amount
    ?clang Do   !2
    ?clang Do   !3
    
    0.9         !narrow-amount
    "b1b" note  !pitch
    12          !modulation-index 
    ?clang Do   !4
    (
        (&gt;1 Done dbs+6 !1,?time),
        (&gt;2 Done !2,(?beat,&gt;time)+ !time), 
        (&gt;3 Done !3,(?beat,&gt;time)+ !time), 
        (&gt;4 Done !4,(?beat,&gt;time)+ !time)
    )MixAt !low-rhyth
    
    (
        1,400,
        {
            (
                (&gt;low-rhyth,0),
                (?1,(?beat,&gt;time)+ !time),
                (?2,(?beat,&gt;time)+ !time), 
                (?3,(?beat,&gt;time)+ !time), 
                (?4,(?beat,&gt;time)+ !time)
            )MixAt !low-rhyth
        }
    )Repeat
    &gt;low-rhyth Normalise !signal
    
    [ Dong low ]
    1000        !length
    3           !order
    "g4" note   !pitch
     500        !wide-point
     600        !narrow-point
    0.8         !narrow-amount
    (1.5,0)     !a
    (1,2000)     !b
    (750,0.5)   !c
    (950,0.25)  !d
    (?length,0) !e
    24          !modulation-index 
    24          !over-drive
    ?clang Do   !b1
    
    0 Silence !left !right !centre
    
    (?beat,4)* !time
    (
        (&gt;centre,0),
        (&gt;b1 Done dbs-6 !b1,(&gt;time,(?beat,8)*)+ !time)
    )MixAt !centre
    
    (
        1,200,
        {
            (
                (&gt;centre,0),
                (?b1,       (&gt;time,(?beat,8)*)+ !time)
            )MixAt !centre
        }
    )Repeat
    
    [ clang medium ]
    750         !length
    3           !order
    "b6b" note  !pitch
     200        !wide-point
     500        !narrow-point
    0.7         !narrow-amount
    (1,0)       !a
    (1,2000)     !b
    (300,0.5)   !c
    (400,0.25)  !d
    (?length,0) !e
    12          !modulation-index 
     3          !over-drive
     2500       !post-cut-low
    "b4b" Note  !post-cut-high 
    ?clang Do Done !b2
    (
        (?b2,0),
        (?b2,50)
    )MixAt Normalise dbs-18 !b2
    
    (?beat,21)* !time
    (
        1,200,
        {
            (
                (&gt;centre,0),
                (?b2,(&gt;time,(?beat,8)*)+ !time)
            )MixAt !centre
            
            (
                (&gt;left,0),
                (?b2,?time)
            )MixAt !left
        }
    )Repeat
    
    [ clang high ]
    750         !length
    3           !order
    "b6b" note  !pitch
     100        !wide-point
     200        !narrow-point
    0.9         !narrow-amount
    (1,0)       !a
    (1,2000)     !b
    (300,0.5)   !c
    (400,0.25)  !d
    (?length,0) !e
    12          !modulation-index 
     3          !over-drive
     5000       !post-cut-low
    "b6b" Note  !post-cut-high 
    ?clang Do Done !b2
    (
        (?b2,0),
        (?b2,50)
    )MixAt Normalise dbs-24 !b3
    
    (?beat,29.5)* !time
    (
        1,200,
        {
            (
                (&gt;centre,0),
                (?b3,(&gt;time,(?beat,8)*)+ !time)
            )MixAt !centre
            
            (
                (&gt;right,0),
                (?b3,?time)
            )MixAt !right
        }
    )Repeat

    (&gt;b3,0.75)DirectRelength !b3
    (?beat,62.75)* !time
    (
        1,200,
        {
            (
                (&gt;centre,0),
                (?b3 dbs-3,(&gt;time,(?beat,8)*)+ !time)
            )MixAt !centre
            
            (
                (&gt;right,0),
                (?b3 dbs+3,(?time,30)-)
            )MixAt !right
        }
    )Repeat
    
    [ high dong in middle ]
    (?b1,1.5)DirectReLength !b4
    (?beat,40)* !time
    (
        1,20,
        {
            (
                (&gt;centre,0),
                (?b4,(&gt;time,(?beat,8)*)+ !time)
            )MixAt !centre    
        }
    )Repeat
    
    (?b1,(5,3)/)DirectReLength !b5
    (?beat,49)* !time
    (
        1,200,
        {
            (
                (&gt;centre,0),
                (?b5 dbs-6,(&gt;time,(?beat,8)*)+ !time)
            )MixAt !centre
            (
                (&gt;left,0),
                (?b5,?time)
            )MixAt !left
            
        }
    )Repeat
    
    [ ting te te te high ]
    8000        !length
    2           !order
    "b1b" note  !pitch
    1000        !wide-point
    1500        !narrow-point
    0.9         !narrow-amount
    (1.5,0)     !a
    (1,1000)    !b
    (5000,0.5)  !c
    (7000,0.25) !d
    (?length,0) !e
    18          !modulation-index 
     6          !over-drive
     5000       !post-cut-low
     32         !post-cut-high 
    ?clang Do Done !b6
    (&gt;b6,16)DirectRelength !b6 !b6-source
    (?beat,4)/ !qbeat
    (
        (?b6 dbs+6,0),
        (?b6      ,?qbeat),
        (?b6      ,(?qbeat,2)*),
        (?b6      ,(?qbeat,3)*)    
    )MixAt Normalise dbs-12 !b6 
    
    (?beat,58.1)* !time
    (
        1,200,
        {
            (
                (&gt;right,0),
                (?b6 dbs-6,(&gt;time,(?beat,8)*)+ !time)
            )MixAt !right
            (
                (&gt;left,0),
                (?b6,(?time,30)+)
            )MixAt !left
            (
                (&gt;centre,0),
                (?b6,?time)
            )MixAt !centre
            
        }
    )Repeat
    
    [ Dong massive ]
    (?beat,62.9)* !time
    1500        !length
    3           !order
    "f3" note   !pitch
    1000        !wide-point
    1300        !narrow-point
    0.95        !narrow-amount
    (2.5,0)     !a
    (1,500)     !b
    ( 750,0.25) !c
    (1400,0.25) !d
    (?length,0) !e
    12          !modulation-index 
    36          !over-drive
    "f5"  Note  !post-cut-high
    "f1"  Note  !post-cut-low
    ?clang Do  Done !b7
    (
        1,200,
        {
            (
                (&gt;centre,0),
                (?b7 ,(&gt;time,(?beat,8)*)+ !time)
            )MixAt !centre
        }
    )Repeat
    
    (&gt;b6-source,(2,3)/)DirectRelength !b8
    (?beat,4)/ !qbeat
    (
        (?b8 dbs+6,0),
        (?b8      ,?qbeat),
        (?b8      ,(?qbeat,2)*),
        (?b8      ,(?qbeat,3)*)    
    )MixAt Normalise dbs-12 !b8 
    (?beat,(60,16)+)* !time
    (
        1,200,
        {
            (
                (&gt;right,0),
                (?b8 dbs-6,(&gt;time,(?beat,8)*)+ !time)
            )MixAt !right
            (
                (&gt;centre,0),
                (?b8,(?time,30)+)
            )MixAt !centre
            
        }
    )Repeat
    
    
    [ Stich it all together ]
    (
        (&gt;left,0),
        (?signal,50),
        (?centre,0)
    )MixAt Normalise !left
    
    (
        (&gt;right,0),
        (&gt;signal,0),
        (&gt;centre,0)
    )MixAt Normalise !right
    (&gt;left,&gt;right)
    
} !play
750 !beat
?play Do !750
760 !beat
?play Do !800

&gt;750 Done !bus1
&gt;800 Done !bus2

(
    ?bus1 GetStart,
    ?bus2 GetRest GetStart
)Mix Normalise !left

(
    ?bus1 GetRest GetStart,
    ?bus2 GetStart
)Mix Normalise !right

[
(
    ((48,?beat)*,?left  length,?left)Cut,
    ((48,?beat)*,?right length,?right)Cut
)StereoMonitor
]

(
    1,12,
    {
        !t
        {((30,(?t,10)*)+ Silence,?left)Concatenate } Do !nlTask
        {((40,(?t,10)*)+ Silence,?right)Concatenate} Do !nrTask
    
        {((?nlTask Done, -18)Volume,2000,1)DirectLowPass} Do  !nlTask
        {((?nrTask Done, -18)Volume,2000,1)DirectLowPass} Do  !nrTask
    
        {(?nlTask Done, ?left) Mix Normalise} Do !nlTask 
        {(?nrTask Done, ?right)Mix Normalise} Do !nrTask
        
        ?nlTask Done !left
        ?nrTask Done !right
    }
)Repeat

    
((&gt;left,&gt;right),"temp/tone.wav")WriteFile32