Hi guys,
let’s say I want a sample to be played normally up to a certain point in time, then I want the same sample to be played in reverse from that very point in time towards the beginning. But I want to have the freedom to stop the reverse playback before it reaches the beginning of the audio file.
This is a way for me to experiment with BufRd using Env as the phase.
So, let’s say I have a piano sample (taken from the Sonatina Synphonic Orchestra)
s.boot;
~mySample = Buffer.readChannel(s,"/my/Sonatina Symphonic Orchestra/Samples/Grand Piano/piano-p-c4.wav", channels:0);
I would like to process this way:
- play the sample normally for 2 third of the “playback time”;
- play back it for the remaining 1 third of the “playback time”;
I have a function to calculate these values for me:
(
~func_calculate_levels_and_times = {
|timeRatio, playback_time, buf|
var timeA = timeRatio * playback_time;
var timeB = playback_time - timeA;
var framesA = buf.numFrames * timeA / buf.duration;
var framesB = framesA-(buf.numFrames * timeB / buf.duration);
[[0, framesA, framesB], [timeA, timeB]];
}
)
~func_calculate_levels_and_times.value( 2/3, 4, ~mySample);
So, I’ll use this envelope:
Env.new( [ 0, 117600.0, 58800.0 ], [ 2.6666666666667, 1.3333333333333 ], \lin).plot;
Now I can build my SynthDef:
(
SynthDef(\bufplay_back_and_forth, {
|out=0, buf, pan=0.0, amp=1.0, framesA=44100, framesB=44100,timeA=1, timeB=1 |
var env = Env.new( [ 0, framesA, framesB ], [ timeA, timeB ], \lin );
var sig = BufRd.ar(1, buf, EnvGen.ar( env, 1, doneAction:2), loop:0, interpolation:2);
sig = sig * amp;
Out.ar(out, Pan2.ar(sig, pan));
}).add;
)
and eventually play it!
Synth(\bufplay_back_and_forth, [\buf, ~mySample, \framesA, 117600.0, \framesB, 58800.0, \timeA, 2.6666666666667, \timeB, 1.3333333333333 ]);
You can try yourself, changing the playback time or the ratio if you want but, you will hear a kind of glitch in the signal, right at the point where the envelope reaches its highest point (the point where the playback direction reverses).
This, in my case, is undesirable behaviour. I would not like to have any spurious elements during playback.
I realised that this glitch is obviously caused by a ‘singularity’ in the resulting waveform: a point at which the oscillation pattern undergoes an abrupt change of direction.
See here a recording I’ve made of the resulting sound. I have marked the “singularity”.
Reasoning for a moment, I realise that, in order to avoid this glitch, the point of reverse reproduction should take place at a belly point, or in any case at a point where the specularity due to the reversal of the direction of reproduction does not cause any audible artefacts.
I am therefore wondering if there are any ugen who can suggest to me what might be the best time to make this reversal of the direction of reproduction.
Alternatively, I ask you what you think might be the best method to achieve the desired result.
Thank you very much for your support
na