Volume - routine

Hi!
Why does the routine sound quieter and quieter as it goes on?;
I Have this problem:
When the routine goes on and advance the volume goes quieter, waht is wrong in my code?
thanks!


/////////////////////////////

b = Buffer.read(server: s, path:"C:/Users/honol/OneDrive/Documents/555/polar.wav");
b.play;

a = Buffer.read(server: s, path:"C:/Users/honol/OneDrive/Documents/555/222.wav");
a.play;

d = Buffer.read(server: s, path:"C:/Users/honol/OneDrive/Documents/555/zucco.wav");
d.play;

e = Buffer.read(server: s, path:"C:/Users/honol/OneDrive/Documents/555/agonis.wav");
e.play;


(
SynthDef(\playa, {
	var sig, buf = \buf.ir(0);
	sig = PlayBuf.ar(
		numChannels: 2,
		bufnum: buf,
		rate: BufRateScale.ir(buf) * \rate.ir(10),
		//startPos: \spos.ir(0),
		//loop: \loop.ir(0),
	);
	sig = sig * Env(
		levels: [0,1,0],
		times: [\atk.ir(0.001), \sust.ir(1200), \rel.ir(3)],
		curve: [-2, - 2]
	).ar(2);
	sig = Pan2.ar(sig, \pan.ir(0), \amp.ir(0.9));
	Out.ar(\out.ir(0), sig);
}).add;
)

///////////////////////////////////////////////

(
SynthDef(\koto, {
	var sig, buf = \buf.ir(0);
	sig = PlayBuf.ar(
		numChannels: 2,
		bufnum: buf,
		rate: BufRateScale.ir(buf) * \rate.ir(10),
		//startPos: \spos.ir(0),
		//loop: \loop.ir(0),
	);
	sig = sig * Env(
		levels: [0,1,0],
		times: [\atk.ir(0.001), \sust.ir(1200), \rel.ir(1)],
		curve: [-2, - 2]
	).ar(2);
	sig = Pan2.ar(sig, \pan.ir(0), \amp.ir(0.5));
	Out.ar(\out.ir(0), sig);
}).add;
)

/////////////////////////////////////////////////////////////////////////


(
SynthDef(\koto2, {
	var sig, buf = \buf.ir(0);
	sig = PlayBuf.ar(
		numChannels: 2,
		bufnum: buf,
		rate: BufRateScale.ir(buf) * \rate.ir(10),
		//startPos: \spos.ir(0),
		//loop: \loop.ir(0),
	);
	sig = sig * Env(
		levels: [0,1,0],
		times: [\atk.ir(0.001), \sust.ir(1200), \rel.ir(3)],
		curve: [-2, - 2]
	).ar(2);
	sig = Pan2.ar(sig, \pan.ir(0), \amp.ir(0.8));
	Out.ar(\out.ir(0), sig);
}).add;
)

//////////////////////////////////////////////////////////////////////

(
SynthDef(\drums, {
	var sig, buf = \buf.ir(0);
	sig = PlayBuf.ar(
		numChannels: 2,
		bufnum: buf,
		rate: BufRateScale.ir(buf) * \rate.ir(10),
		//startPos: \spos.ir(0),
		//loop: \loop.ir(0),
	);
	sig = sig * Env(
		levels: [0,1,0],
		times: [\atk.ir(0.001), \sust.ir(1200), \rel.ir(3)],
		curve: [-2, - 2]
	).ar(2);
	sig = Pan2.ar(sig, \pan.ir(0), \amp.ir(0.8));
	Out.ar(\out.ir(0), sig);
}).add;
)

///////////////////////////////////////////////////////////////////////////

t = TempoClock.new(245/60).permanent_(true);

/*(
~pat = Pbind(
	\instrument, \playa,
	\buf, b,
	\dur, Prand([2, 1/4, 1], inf),
	\amp, 0.9,
	\rate, Pseq([
	Pseq([-26, 3, 7, 9, -12, 5, 8, 3, 5, 4, 12], 2),
	Prand([5, 7, 3], 3),
	Pseq([3, 8, 4], 2)
	],30).midiratio,
    ).postln;


~seq = ~pat.play(t);

/*
~pat = Pbind(
	\instrument, \koto,
	\buf, a,
	\dur, Pseq([1/2, 1, 1/5, 0.6], inf),
	\amp, 0.3,
	\rate, Pseq([
	Pseq([26, 10], 2),
	],inf).midiratio,
    ).postln;


~seq = ~pat.play(t);
*/
~pat = Pbind(
	\instrument, \drums,
	\buf, e,
	\dur, Pseq([
		Pseq([1/2, 1, 1/5, 0.6], 3),
		//Prand([1/2, 1, 1/4, 1/7], 8),
],100),
	\amp, 0.9,
	\rate, Pseq([
	Pseq([-26, 3], 2),
	],inf).midiratio,
    ).postln;


~seq = ~pat.play(t);

/*
~pat = Pbind(
	\instrument, \koto2,
	\buf, d,
	\dur, Pseq([3, 5, 0.6], inf),
	\amp, 0.9,
	\rate, Pseq([
	Pseq([-26, 3], 2),
	],inf).midiratio,
    ).postln;


~seq = ~pat.play(t);

*/)

~seq.stop;

*/
*/

//////////////////////////////////////////////
//////////////////////////////////////////////

(
f = {
	(
~pat = Pbind(
	\instrument, \playa,
	\buf, b,
	\dur, Prand([2, 1/4, 1], 30),
	\amp, 0.8,
	\rate, Pseq([
	Pseq([-26, 3, 7, 9, -12, 5, 8, 3, 5, 4, 12], 2),
	Prand([5, 7, 3], 3),
	Pseq([3, 8, 4], 2)
	],30).midiratio,
    ).postln;
	~seq = ~pat.play(t);
	);
	2.wait;
	(
	~pat = Pbind(
	\instrument, \koto2,
	\buf, d,
	\dur, Pseq([3, 5, 0.6], 30),
	\amp, 0.8,
	\rate, Pseq([
	Pseq([-26, 3], 2),
	],30).midiratio,
    ).postln;
    ~seq = ~pat.play(t);
	);
	5.wait;
	(
	~pat = Pbind(
	\instrument, \drums,
	\buf, e,
	\dur, Pseq([
		Pseq([1/2, 1, 1/5, 0.6], 30),
		//Prand([1/2, 1, 1/4, 1/7], 8),
],100),
	\amp, 0.8,
	\rate, Pseq([
	Pseq([-26, 3], 2),
	],30).midiratio,
    ).postln;
~seq = ~pat.play(t);
	);
		15.wait;
	(
	~pat = Pbind(
	\instrument, \koto2,
	\buf, d,
	\dur, Pseq([3, 5, 0.6], 30),
	\amp, 0.8,
	\rate, Pseq([
	Pseq([-26, 3], 2),
	],30).midiratio,
    ).postln;
    ~seq = ~pat.play(t);
	);
	8.wait;
	(
	~pat = Pbind(
	\instrument, \drums,
	\buf, e,
	\dur, Pseq([
		Pseq([1/2, 1, 1/5, 0.6], 30),
		//Prand([1/2, 1, 1/4, 1/7], 8),
],100),
	\amp, 0.8,
	\rate, Pseq([
	Pseq([-26, 3], 2),
	],30).midiratio,
    ).postln;
~seq = ~pat.play(t);
	);
	};

r = Routine(f);
)

r.next;

r.reset;

r.play;


//////////////

Hi, I wonder it has passing 8 days since, and nobody answer my question?
It is so complex or the code is so bad generated that it must not be answered?

Thanks.

Ah. I did have a look, but didn’t have the audio samples. At that time, I was too busy to continue so I thought i’d just wait and see if somebody else would take it up. Then they didn’t.

(As for “it must not be answered,” please remember that forum members are all volunteers. The lack of an answer may be for any number of reasons that have nothing to do with a judgment on the code – I intended to come back to the thread, but then I had two shows last week, and then work was busy for a few days and I forgot. It’s OK to drop a thread once in awhile. We’re volunteers and we’re not perfect.)

The most likely cause is the envelope definition.

In Env, the number of envelope nodes (let’s call it n) is given by the levels array minus one. times and curves should have n-1 items.

In your Env, both levels and times have three items. That’s an inconsistent definition. Let’s see what happens when you define an envelope with three levels and two times.

Env([0, 1, 0], [1, 2, 3], [-2, -2]).asArray

-> [0, 2, -99, -99, 1, 1, 5, -2, 0, 2, 5, -2]
    |               |  |         |  ^times[1]
    |               |  |         ^levels[2]
    |               |  ^times[0]
    |               ^levels[1]
    ^levels[0]

The envelope begins at 0 (levels[0]). The first envelope node goes to the target value 1 (levels[1]) in “times[0]” seconds (1 sec). Then the second envelope node goes to the target value 0 (levels[2]) in “times[1]” seconds (1 sec). times[2] (= 3) is dropped. You’ve named the times “atk,” “sust” and “rel” but in fact, “sustain” doesn’t act like sustain. It’s a (very long) release.

In the patterns, you haven’t overridden \atk, \sust, \rel so the default values will be used. so you have an attack value = 0.001, and the second envelope segment goes to 0 (release) in 1200 seconds or 20 minutes.

I guess maybe you meant levels: [0, 1, 1, 0]?

If it were my code, I would also rethink that 20-minute sustain time. The envelopes aren’t gated, so there is no way to stop them once they start (except n_free). They just have to run out the 20-minute clock.

HTH,
hjh

I understads the errors, but:

SC is too much complex for me, after being so far 4 weeks looking after Eli Fieldsteel youtube videos I also dont know how to code well in SC, so thanks but I will give up with the software, best wishes to all.
oxxo

Sad to hear you’re giving up on SC. Is it mainly because the documentation feels too technical?
One effective way to learn SC, Max, Pd, or Csound is to work on a project together with someone experienced.
Books and videos can help too, especially when they address the specific issues you’re facing.
If you decide to continue later, feel free to ask with a minimal example of your project — someone here may give you helpful answers.

Could it be possible that you help me in private lessons in order I can advance?
Answer to the intern inbox.

My programming and English skills are intermediate, so I’m not ready to teach lessons yet. But I can share my thoughts in the forum whenever I have time.
If you post again about “SC lessons” or “Project helper using SC,” I think some people will respond.

I would recommend working through Eli Fieldsteel’s book and the examples he has - if you want to learn SuperCollider.

1 Like
(
SynthDef(\playa, {
	var sig, buf = \buf.ir(0);
	sig = PlayBuf.ar(
		numChannels: 2,
		bufnum: buf,
		rate: BufRateScale.ir(buf) * \rate.ir(10),
		//startPos: \spos.ir(0),
		//loop: \loop.ir(0),
	);
	sig = sig * Env(
		levels: [0,1, 1, 0],
		times: [\atk.ir(0.001), \sust.ir(1), \rel.ir(3)],
		curve: [-2, - 2]
	).ar(2);
	sig = Pan2.ar(sig, \pan.ir(0), \amp.ir(0.9));
	Out.ar(\out.ir(0), sig);
}).add;
)

My understanding was not too clear about what was your answer; but I’m posting about what I think I have to correct yes, ok?

let me know if im very confused and I have to read Eli`s book from scratch, I saw his videos from 2023 until “routine video”.

I haven’t tested but I think it should be like that, yes.

I realized later that maybe my post was a bit too much. I tend to want to explain why something needs to be written this way and not that way; maybe that isn’t always helpful. Sorry about that.

hjh

Pan2, Balance2

You are using a 2‑channel signal together with Pan2:

...
sig = PlayBuf.ar(
		numChannels: 2,
...
sig = Pan2.ar(sig
...

but for stereo input Balance2 is usually the better choice.

See Quick stereo pan question


ir, kr, ar

...
rate: BufRateScale.ir(buf) * \rate.ir(10),
...
sig = Pan2.ar(sig, \pan.ir(0), \amp.ir(0.9));
...

Also, .ir is appropriate only when you do not need to control a parameter while the Synth is running. To control parameters of a running Synth, .kr is generally the better choice, and .ar is used when audio-rate modulation or very subtle, sample-accurate changes are required.

(
s.waitForBoot {
	SynthDef(\playa, {
		var buf = \buf.kr(0);
		var rate = BufRateScale.kr(buf) * \rate.kr(10);
		// var rate = BufRateScale.kr(buf) * \rate.ir(10);
		var env = Env([0,1, 1, 0], [\atk.kr(0.001), \sust.kr(1), \rel.kr(3)], -2);
		var sig = PlayBuf.ar(2, buf, rate, 1, \start.kr(0), \loop.kr(0));
		env = env.ar(Done.freeSelf);
		sig = sig * env;
		sig = Balance2.ar(sig[0], sig[1], \pan.kr(0), \amp.kr(0.9));
		// sig = Balance2.ar(sig[0], sig[1], \pan.ir(0), \amp.ir(0.9));
		Out.ar(\out.kr(0), sig);
	}).add;
	
	~buf = Buffer.read(s, ExampleFiles.sinedPink);
	~bufSwap = Buffer.readChannel(s, ExampleFiles.sinedPink, channels: [1, 0]);
	
	s.sync;
	
	fork { 
		100.do { |i|
			var duration = 0.2;
			Synth(\playa, [
				buf: ~buf, 
				rate: [1/2, 1, 1, 2].pyramid[i % 4] / 4, 
				loop: 1, 
				sust: duration * 0.1,
				rel: 0.1,
				pan: 1.0.rand2,
				amp: (-9, -10.5 .. -15).choose.dbamp
			]);
			duration.wait
		}
	};
	
	fork {
		var synth = Synth(\playa, [buf: ~bufSwap, loop: 1, sust: 20]);
		10.do { |i|
			synth.set(
				\rate, (24 - i).midiratio, // this only works when using .kr
				\amp, [-15, -27][i % 2].dbamp // this only works when using .kr
			);
			1.wait
		}
	}
}
)

Could you read the following draft, which I intend to include as a guide in the next version of SC? It is not final yet, so there may be many inaccuracies:
github.com/supercollider/supercollider

You can leave feedback here or there.