Hi Jordan,
Sorry I wrote that late last night and should have waited until today to write something more coherent.
Could you be a bit more descriptive?
I’m using arrays to control the playback of a sample. If the sample is 4 seconds long, and the array contains four integers e.g., [0, 1, 2, 3] then 0 will play the first second, 1 the second etc.
By reordering the array it reorders the sample playback.
e.g., [3, 2, 1, 0] would playback the audio slices in reverse order; the 4th second, the 3rd second… etc.
Here’s the current code slightly simplified:
~b0 = Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav");
~b0.play;
m = [ [ 0, 1, 2, 3 ], [ 1, 0, 3, 2 ], [ 1, 3, 0, 2 ], [ 3, 1, 2, 0 ], [ 3, 2, 1, 0 ]; ]
m[1].postln;
d = ~b0.numFrames / ~b0.sampleRate; /// duration of sample
p = 4; /// number of parts to split the sample into
z = ~b0.numFrames / p; /// length of a slice in frames
y = z/~b0.sampleRate; /// length of a slice in seconds
(
SynthDef.new (\voice, {
arg amp=1, out=0, gate=1, buf, start, end, rate=1, dur;
var eg = EnvGen.kr(Env.asr(0.001, 1, 0.001), gate, doneAction: 2);
var sig, ptr;
ptr = Phasor.ar(0, BufRateScale.kr(buf)*rate, start, end);
sig = BufRd.ar(2, buf, ptr);
sig = sig * amp;
Out.ar(out, (sig*eg));
}).add;
)
~b0.play;
p = Pbind(
\instrument, \voice,
\dur, y,
\amp, 1,
\start, Pseq(m[0]*z, 1).trace,
\end, Pseq(m[0]*z+z, 1).trace,
).play;
It almost works, although there is bug, and the sample has significant gaps between the sections, so even though the array in the Pbind is [0, 1, 2, 3] it does not play back cleanly.
However this code does not actually achieve what I would like, it is meant as a stepping stone to greater complexity. What I want is to have the 0 in this part of the code increment every x number of repeats, thereby returning a new section of the array.
\start, Pseq(m[0]*z, 1).trace,
\end, Pseq(m[0]*z+z, 1).trace,
I’m aiming for a degree of flexibility in this because then it might also be interesting to have a pattern control the index of the array, so rather than increment, it could be random, or use a modulo, or whatever else.
To make matters more complicated I would like to have multiple instances of this running at the same time, to create layers. This is where the limits of my understanding of SC hit me sideways, because I have zero problem conceptualising it algorithmically, and huge problems with coding it.
So this is a rough summary:
There is an audio sample
There is an array of fixed length
The audio sample is played back in a fixed length loop but reordered depending on the array.
There is the capability of have multiple arrays of potentially different length, and for multiple voices to play simultaneously.
I don’t feel here, although I could be wrong, that my limitation is understanding the Patterns as such, which as a musician and composer I find quite intuitive and logical, it’s more the more fundamental grammar of SC, and building code of medium level complexity.