Hello to all! Thanks for the help
hey, a really simple example of using your three buffers and play them simultaneously could be this:
// create the SynthDef for buffer playback:
(
SynthDef(\playbuf, { |sndBuf|
var sig;
sig = PlayBuf.ar(1, sndBuf, \rate.kr(1), loop: 1);
sig = sig * \amp.kr(-10.dbamp);
sig = sig * Env.asr(0.001, 1, 0.001).ar(Done.freeSelf, \gate.kr(1));
sig = Pan2.ar(sig, \pan.kr(0));
Out.ar(\out.kr(0), sig);
}).add;
)
// load buffers from disk and assign them to a variable
~bufA = Buffer.read(s, "C:/Users/Asrock B460M-HDV/Music/Sample x Exam/Amen-Break-Sample-_136-bpm_.wav");
~bufB = Buffer.read(s, "C:/Users/Asrock B460M-HDV/Music/Sample/break01.wav");
~bufC = Buffer.read(s, "C:/Users/Asrock B460M-HDV/Music/Sample/169_-gated-pad.wav");
// put those three buffers in an array
~myBufs = [~bufA, ~bufB, ~bufC];
// use .collect which iterates over your array of buffers to create a Synth voice for each of them, so you end up with three Synth voices each plays one of your buffers. All three synths start simultaneously.
(
Routine({
s.bind {
~myBufs.collect{ |buf|
Synth(\playbuf, [
\rate, 1,
\sndBuf, buf,
\amp, -10.dbamp,
\out, 0,
]);
};
};
}).play;
)
Note that Playbuf when set in loop mode will play each buffer to the end and will start all over again. Its probably the case for your buffers that they dont have the same length, so they will start together when scheduled together, but each one finishes its cycle at another moment in time and therefore starts its next cycle at a different moment in time, so your three synth voices will get out of sync over time.
Its also a good habit to add an evenlope for each SynthDef you create. The evelope makes sure that your sounds fade in smoothly and you can release them, which you probably would like to do if you want to schedule events at different times using a Routine or Patterns. The Routine is already implemented in the code above and is not necessary there for just creating three synths. But together with the envelope you can set up a loop and wait for a specific moment in time and then release your Synths Nodes.
I guess a good starting point to get familiar with the basic functionality of creating SynthDefs, working with buffers and scheduling events with Routines or Patterns are the Tutorials by Eli Fieldsteel:
you can insert the envelope from the helpfile in your SynthDef like this:
(
SynthDef(\playbuf, { |sndBuf|
var sig, env;
env = EnvGen.ar(Env([0, 1, 0.5, 1, 0], [0.01, 0.5, 0.02, 0.5]), doneAction: Done.freeSelf);
sig = PlayBuf.ar(1, sndBuf, \rate.kr(1), loop: 1);
sig = sig * env;
sig = sig * \amp.kr(-10.dbamp);
sig = Pan2.ar(sig, \pan.kr(0));
Out.ar(\out.kr(0), sig);
}).add;
)
Env
does create an envelope shape from levels, durations and curves and EnvGen
does then execute this evelope recipe.
This specific envelope doesnt has a gate set up, therefore it will go through all its segments and then gets released because it has set doneAction: Done.freeSelf
. The release of the envelope will make the current Synth disappear from the audio server. That will happen independently from setting the loop inside Playbuf. So after the envelope has gone through all its segments the synth gets released and has to be scheduled once more to start playing back the audio file stored in your buffer. You could either do that with a Routine and a loop, with Patterns or set up a trigger Ugen in the SynthDef which triggers your envelope at a specific rate.
I think creating a GUI which mets these needs might probably be a bit too ambitious. I would look at the tutorials first and make sure the SynthDef is working as you would like and scheduling events with your three buffers is also working as you would like.