Duplicated Time ramps / Store


#1

Hello,

Newb on SC, I would like to know how can I add to this simple code:

f={ [{SinOsc.ar(Rand(100,700),Rand(0,1),0.05)}.dup(30),{SinOsc.ar(Rand(100,800),Rand(0,1),0.05)}.dup(30)] }.play;

a looping time ramp: all of the 30’s duplicated oscillators go from their current value to, let’s say, its half, in 10 second ( ie Line.kr(freq,freq/2,10) for a single oscillator), and start again the same ramp when it s finished?

Also, if I execute this line code and that I am glad with the current state of thoses 30 frequencies values produced by Rand, what is the most minimal way to store this current state and to recall it? And then to be able shortly to play with let’s say 10 stored states?

Thanks a lot.


#2

First, I think it’s a bit more idiomatic for SC to restructure the signals.

In your original version, you’re generating a two element array (i.e. stereo) and each element consists of 30 signals. It happens that SC handles this by producing 30 Out.ar units, each one handling one stereo pair, and they are all mixed down on the output bus. But I think, for the sake of readability (and readability is important when you come back to the code 5 years later and… erm, what was I thinking again?), it’s better to be explicit about mixing the signals down.

SynthDef(\thirty, { |out|
	var manyStereoPairs = {
		[SinOsc.ar(Rand(100, 700), Rand(0, 1), 0.05), SinOsc.ar(Rand(100, 800), Rand(0, 1), 0.05)]
	}.dup(30),
	mixed = manyStereoPairs.sum;
	Out.ar(out, mixed);
}).add;

There’s actually a trick to fold the stereo pairs down – the following should be equivalent:

d = SynthDef(\thirty, { |out|
	var manyStereoPairs = {
		SinOsc.ar([Rand(100, 700), Rand(100, 800)], { Rand(0, 1) }.dup(2), 0.05)
	}.dup(30),
	mixed = manyStereoPairs.sum;
	Out.ar(out, mixed);
}).add;

There’s nothing “officially” wrong with your original synth, but… I didn’t understand it at first, so I think the code style is unclear. (Also these 2 versions are slightly more efficient because the sum has a nice optimization that multiple Out units do not.)

looping time ramp

You’ll have to use EnvGen for this. Line doesn’t loop, and there’s no way to make it loop.

Also, if I execute this line code and that I am glad with the current state of thoses 30 frequencies values produced by Rand, what is the most minimal way to store this current state and to recall it? And then to be able shortly to play with let’s say 10 stored states?

Random seeds.

d = SynthDef(\thirty, { |out, randSeed = 0|
	var manyStereoPairs, mixed;
	RandSeed.kr(1, randSeed);
	manyStereoPairs = {
		SinOsc.ar([Rand(100, 700), Rand(100, 800)], { Rand(0, 1) }.dup(2), 0.05)
	}.dup(30);
	mixed = manyStereoPairs.sum;
	Out.ar(out, mixed);
}).add;

x = Synth(\thirty, [randSeed: 32847832]);
x.free;

// 2nd time, sounds exactly the same
x = Synth(\thirty, [randSeed: 32847832]);
x.free;

// different seed, different sound
x = Synth(\thirty, [randSeed: 8564535]);
x.free;

So, for each trial, you make a number for the random seed first, and if you like the sound produced by the random seed, save the number in an array. Then the seed becomes the “preset.”

RandSeed will affect the behavior of other synths that use random numbers (e.g. LFDNoise* units and many others) – RandID can give you more control over that, but you might not need to worry about it.

hjh