Saturday 20 September 2014

Mimicking Reale Note Evolution

Humans seem to like listening to real things, tubes, strings and such. 

These real things don't make one tone in a sound, their tone evolves. Here I discuss a way of using resampling (FM if you like) to achieve that effect.

Here is part of the patch I used to create Contrapunctus III

        if tp==0:
            env=sf.NumericShape((0,0),(96,1),(192,0.5),(length,0))
        elif tp==1:
            env=sf.NumericShape((0,0),(96,0.75),(length-128,1.0),(length,0))
        elif tp==2:
            env=sf.NumericShape((0,0),(96,0.75),(length-256,1.0),(length,0))
        elif tp==3:
            if length<1280:
                env=sf.NumericShape((0,0),(64,0.5),(256,1),(512,0.75),(length-256,0.5),(length,0))
            else:
                env=sf.NumericShape((0,0),(64,0.5),(256,1),(512,0.75),(length-512,.75),(length,0))
        else:
            env=sf.NumericShape((0,0),(64,0.25),(512,1),(length/2,0.75),(length,0))

        sig=sf.Multiply(sig,+env)
        sig=sf.FixSize(sig)

        mod=sf.NumericShape((0,0.995),(length,1.005))
        mod=sf.Mix(mod,sf.NumericVolume(env,0.01))
        sig=sf.FrequencyModulate(sig,mod)  

        sig=sf.FixSize(sig)

Here is the outcome:

So, let's go through the patch and see how it works:
        if tp==0:
            env=sf.NumericShape((0,0),(96,1),(192,0.5),(length,0))
        elif tp==1:
            env=sf.NumericShape((0,0),(96,0.75),(length-128,1.0),(length,0))
        elif tp==2:
            env=sf.NumericShape((0,0),(96,0.75),(length-256,1.0),(length,0))
        elif tp==3:
            if length<1280:
                env=sf.NumericShape((0,0),(64,0.5),(256,1),(512,0.75),(length-256,0.5),(length,0))
            else:
                env=sf.NumericShape((0,0),(64,0.5),(256,1),(512,0.75),(length-512,.75),(length,0))
        else:
            env=sf.NumericShape((0,0),(64,0.25),(512,1),(length/2,0.75),(length,0))

        sig=sf.Multiply(sig,+env)

First we have a dynamic envelope generator; it chooses the envelope based on the original length of the node (encoded in tp) and the current length (after some modification). The final line applies the envelope to the signal by simply multiplying one with the other. Note that NumericShape creates linear envelopes. Whilst Sonic Field can make exponential envelopes (via SimpleShape) and combination envelopes (by multiplying exponential and linear ones) I personally find a it easier to control linear envelopes and to add detail to them to mimic exponential behaviour.

So far so standard. This approach is pretty much text book synthesis plus some smarts over envelope shape. We need to make the shape 'full size' again so that we don't get unwanted volume effects. IE I tend to keep bringing signals back up to a deviation max of 1 so that when I do apply a volume to them, I get exactly what I want.

        sig=sf.FixSize(sig)

Does the the deviation correction. In the past I used Normalise a lot instead. This is actually more powerful because it removes any over all 'DC" component. By DC (an old fashion term to say the least) I mean an over all offset from zero. A pure tone (say a sine wave) should, when all the samples are added together, have a absolute offset of 0. Normalise makes this happen; in so doing it sometimes move the beginning or end sample of a signal away from zero. When the signals are mixed this puts clicks and pops into the sound. Now I try to use FixSize throughout and only use Normalise at the last step.

        mod=sf.NumericShape((0,0.995),(length,1.005))
        mod=sf.Mix(mod,sf.NumericVolume(env,0.01))
        sig=sf.FrequencyModulate(sig,mod)  

        sig=sf.FixSize(sig)

Finally we get tot the point of the post. I create an envelope which moves from 0.995 to 1.005. I then add to that the volume envelope which was used. However, I scale the volume envelop right down to 1% of its original size. What this gives me is a shape which moves over all up a bit but with more up when the volume is high. 


        sig=sf.FrequencyModulate(sig,mod)  

FrequencyModulate then 'bends' the note to the envelope. This mimics the pitch rising throughout the note (a little) and being higher when the volume is higher. That sort of bend - to my ears - is quite typical of a bowed instrument or a blown tube (flute or diapason).

No comments:

Post a Comment