Hi guys,
I have a question about a strange artifact I’m facing working with granular synthesis and custom buffer envelopes.
I will try to explain it with my (simplified) code.
First let’s create the synth definition
(
SynthDef(\grain_player_test, {
|
out=0, gate=1, amp=0.9, pan=0.0,
atk=5, dcy=0.2, sus=0.7, rel=5,
buf, rate=1, length=1, density=5, envbuf=(-1)
|
var sig, env;
var trigger = Impulse.kr( density );
var pos = 0.5 + TRand.kr(-0.35, 0.35, trigger);
env = EnvGen.kr(Env.adsr(atk, dcy, sus, rel), gate, doneAction:2);
sig = GrainBuf.ar(
1, // number of channels
trigger,
length,
buf,
rate,
pos,
2,
envbufnum:envbuf
);
sig = LeakDC.ar(sig);
sig = sig * env * amp;
Out.ar(out, Pan2.ar(sig, pan));
}).add;
);
and loading any soft, continuos, harmonic mono samples you have;
~buf_pad = Buffer.read(s, "/path/to/my/pad/sample.wav");
Then instantiate the synth, you should hear a sterophonic granular/drone-sort-of sound.
(
x = Synth(\grain_player_test, [
\out, 0, \gate, 1, \amp, 0.9,
\buf, ~buf_pad,
\rate, 1, \pan, 0.0,
\atk, 5, \dcy, 0.2, \sus, 0.7, \rel, 5,
\density, 1,
\length, 10
])
);
As you can see we are using the default envbuf
(Hann envalope) here. The result is fine!
Now, create a custom buffer envelope with an initial sharp edge and a closing soft ramp
~winenv = Env([1,0],[1]).discretize(n:1024);
~buf_env = Buffer.loadCollection(s, Array.newFrom( ~winenv ) );
// you can plot it to see its shape
~winenv.plot;
~buf_env.plot;
And now use this envelope to shape the individual grains (let’s separate them a bit, and also make them shorter to better understand the glitch phenomenon I was talking about):
x.set(\length, 1, \density, 0.5, \amp, 0.9, \envbuf, ~buf_env)
If you hear what I do, you will perceive a clip at the beginning of each grain (which makes perfect sense since we have a sharp shape on the rising edge of the envelope) but, why is there also a clip at the end of the grain from the moment that we have a smooth shape this side?
I’ve done also another experiment with a different envelope (this time it has a triangular shape):
~winenv = Env([0,1,0],[1,1]).discretize(n:1024);
~buf_env = Buffer.loadCollection(s, Array.newFrom( ~winenv ) );
x.set(\length, 1, \density, 0.5, \amp, 0.9, \envbuf, ~buf_env)
This time the sound is perfectly smooth.
Why?
Is there something I’m not doing the correct way?
Does the dimensione of the buffer has somthing to do with it? In case so, is there a suggested dimensione for the buffer?
Aside from this: it that the best way to convert an envelope to a buffer the one I’m using here?
Thank you so mush for you support
regards
na