I’m trying to playback the signal from the buffer using TGrains or GrainBuf. Or in other words make a granulator behave like a simple sampler. And in this context I see the behaviour that’s I can’t quite explain. Maybe somebody can help me to get what is the key factor here.
Here is the code. It plays back a sample using a BufRd and GrainBuf (or TGrains) and subtracts one from another:
b = Buffer.readChannel(s, "/path/to/soundfile_with_sampling_rate_that_match_scsynth_SR", channels:[0]);
b.play;
b.sampleRate;
Ndef(\granular_reconstruct).clear;
Ndef(\granular_reconstruct).ar(2);
Ndef(\granular_reconstruct).set(\bufnum, b.bufnum);
(
Ndef(\granular_reconstruct, { |bufnum|
var overlap=2, tFreq=20;
var phasor, bufrd, gran, env;
var bufFrames = BufFrames.ir(bufnum);
var t = Impulse.ar(tFreq);
phasor = Phasor.ar(
rate: BufRateScale.kr(bufnum),
start: 0.0,
end: bufFrames,
);
bufrd = BufRd.ar(
numChannels: 1,
bufnum: bufnum,
phase: phasor,
interpolation: 1
);
// bufrd = DelayN.ar(bufrd, delaytime: overlap / tFreq * MouseX.kr(0.499,0.51).poll);
// // on UGen(MouseX): 0.500292 gives good null test
// gran = TGrains.ar(
// numChannels: 1,
// trigger: t,
// bufnum: bufnum,
// rate: 1,
// centerPos: phasor / SampleRate.ir,
// dur: overlap / tFreq,
// pan: 0,
// amp: 1,
// interp: 1
// );
gran = GrainBuf.ar(
numChannels: 1,
trigger: t,
dur: overlap / tFreq,
sndbuf: bufnum,
rate: 1,
pos: phasor / bufFrames,
interp: 1,
envbufnum: -1,
);
bufrd
-
gran
!2
}).play;
)
And here starts the interesting part that I don’t quite get.
With the sampling rate 44100 GrainBuf gives me perfect null test with BufRd. TGrains gives non-regular amplitude mudulation, or in other words some grains match the content of BufRd ( and the output is 0) but some grains don’t. If I turn TGrains interpoaltion to 2 or 4 things become a bit better (the output becomes a bit quiter) but still no perfect null test.
Now if I start SuperCollider with 48000 Hz Sampling Rate both GrainBuf and TGrains can’t give succesfull null test and result in non-periodic amplitude modulation.
Now on another machine thigs are a bit different. With 48000 Hz Sampling Rate TGrains is able to produce succesfull null test and GrainBuf results in amplitude modulation. And with 44100 Hz both TGrains and GrainBuf fail to pass null test.
On these 2 machines I tested things with same and different SC versions, same and different audio cards (built-in ones and USB Focusrite Solo). OS and kernels are different (different versions of Debian) but jackd versions are the same and clocksource/timer related configurations are the same. When changing sampling rate I also change the soundfile to match scsynth’s (or jackd’s) sampling rate. In all cases of amplitude modulation output turning on interpolation in granulator make things better but still modulation is there.
Does anybody have a clue what might be the key factor there? Why GrainBuf fails where TGrains doesn’t and vice versa. And how server sampling rate is connected to this behaviour. And may be something else…