Constrained random SuperCollider envelope generation with exact durations and configurable endpoints.
- SuperCollider: tested with version 3.13.0
The generator and its test have no external repository dependencies.
makeRandomEnv.scd: envelope generatormakeRandomEnvValidation.scd: constraint validationmakeRandomEnvTest_LoopExactDuration.scd: live exact-duration closed-envelope test
~makeRandomEnvDir =
Platform.userHomeDir +/+ "makeRandomEnv";
(~makeRandomEnvDir
+/+ "makeRandomEnv.scd").load;makeRandomEnv.scd loads its validation helper automatically.
~env = ~makeRandomEnv.(
duration: 60.0,
minLevel: 0.1,
maxLevel: 0.95,
minSegments: 5,
maxSegments: 11,
minSegmentDuration: 2.0,
startLevel: 0.1,
endLevel: 0.1,
maxLevelChange: 0.1,
curve: \sin
);The function returns a standard SuperCollider Env.
duration: exact total envelope durationminLevelandmaxLevel: permitted range for randomly generated interior levelsminSegmentsandmaxSegments: permitted segment-count rangeminSegmentDuration: shortest permitted segmentstartLevelandendLevel: explicit endpoints ornilfor generated endpointsmaxLevelChange: largest permitted change between adjacent levelscurve: SuperCollider envelope curve
Inspect the generated envelope:
~env.duration.postln;
~env.plot;Begin and end at zero:
startLevel: 0.0,
endLevel: 0.0Begin and end at the same nonzero level:
startLevel: 0.1,
endLevel: 0.1Begin and end at different levels:
startLevel: 0.2,
endLevel: 0.7Set either endpoint to nil to generate that endpoint randomly.
Matching endpoints create a closed envelope. They do not guarantee that an audio source or recorded sample will have a seamless waveform boundary.
The NamedControl capacity must be at least the largest permitted number of segments:
~maxEnvSegments = 11;
SynthDef(\example, {
|outBus = 0|
var envControl;
var amplitude;
var signal;
envControl = NamedControl.kr(
\env,
Env.newClear(~maxEnvSegments).asArray
);
amplitude = EnvGen.kr(
envControl,
doneAction: Done.freeSelf
);
signal = PinkNoise.ar(0.2) * amplitude;
Out.ar(outBus, signal ! 2);
}).add;Pass the generated envelope when creating the Synth:
Synth(\example, [
\outBus, 0,
\env, ~env
]);-
Run
makeRandomEnvTest_LoopExactDuration.scd -
Confirm that SuperCollider reports a duration of
60.0 -
Confirm that the reported start and end levels match
-
Listen as each 60-second pass is reported in the Post window
-
Confirm that the envelope repeats without a sudden level jump or fade to silence
-
Stop the test
~makeRandomEnvTestSynth.free;
The test repeats one generated envelope. It does not generate a new envelope for each pass.
- Total duration is supplied by the project rather than randomized by the generator
- Playback repetition and audio-file rendering remain project responsibilities
- Matching endpoints protect the envelope boundary, not the waveform boundary of the source audio