Sound design (first two days at APO33)

With the physics model created, then the question was of course how to make translate the resulting data into sound. The first idea I try out is if I take the distance from the center rod of each ring of nodes as a wave amplitude. So in other words, I translate these distances to a wavetable, which is then played back. As the model is set into motion, this will cause the waves to become louder and more complex at the same time.

(
SynthDef( \wavetable, {
    var bufSelect = Linen.kr( \gate.kr(1), \fade.kr(0.25), 1, \fade.kr );
    var signal = VOsc.ar( \bufnum.kr(0) + bufSelect, \freq.kr(500), \phase.kr(0) );
    Out.ar( \out.kr(0), Pan2.ar( signal, \pos.kr(0), \amp.kr(0.1) ) );
}).add;
);


10.do{ |jt, j|
    var distances = 10.collect{ |it| 
        ~physics.getParticleParameter( jt, it, \distance );
    } - ~meanParticleDistances[j];
    ~sigs[j] = ~createSplineSignal.value( distances );
    if ( ~sigs[j].notNil ){
        ~wavebuffers[j][~bufid].loadCollection( ~sigs[j].asWavetable );
        ~wavetables[j].set( \gate, ~bufid );
    };
};

To smooth the wavetable, I am using splines to interpolate to a smooth function between the points. Occasionally these give a glitch in the sound, so I am doing a check whether the glitch happens.

~createSplineSignal = { |indata|
    var splinedata, spline, signal;
    var data = indata;
    var maxData = data.maxItem;
    data = data ++ data[0];
    splinedata = [ (0..10), data ].flop;
    spline = BSpline( splinedata, 3 );
    signal = spline.interpolate(256).flop[1];
    // sometimes there is a strange glitch in the interpolation,
    // so we need to catch it:
    if ( (maxData - signal.maxItem).abs > 5.0 ){ 
        maxData.post; "\t".post;signal.maxItem.postln;
        nil;
    }{
        Signal.newFrom( signal );
    }
};
Tue, 16 August, 2016
RSS Feed