Skip to content

Repository files navigation

makeRandomEnv

Constrained random SuperCollider envelope generation with exact durations and configurable endpoints.

Requirements

The generator and its test have no external repository dependencies.

Files

  • makeRandomEnv.scd: envelope generator
  • makeRandomEnvValidation.scd: constraint validation
  • makeRandomEnvTest_LoopExactDuration.scd: live exact-duration closed-envelope test

Load the generator

~makeRandomEnvDir =
    Platform.userHomeDir +/+ "makeRandomEnv";

(~makeRandomEnvDir
    +/+ "makeRandomEnv.scd").load;

makeRandomEnv.scd loads its validation helper automatically.

Generate an envelope

~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 duration
  • minLevel and maxLevel: permitted range for randomly generated interior levels
  • minSegments and maxSegments: permitted segment-count range
  • minSegmentDuration: shortest permitted segment
  • startLevel and endLevel: explicit endpoints or nil for generated endpoints
  • maxLevelChange: largest permitted change between adjacent levels
  • curve: SuperCollider envelope curve

Inspect the generated envelope:

~env.duration.postln;
~env.plot;

Configure endpoints

Begin and end at zero:

startLevel: 0.0,
endLevel: 0.0

Begin and end at the same nonzero level:

startLevel: 0.1,
endLevel: 0.1

Begin and end at different levels:

startLevel: 0.2,
endLevel: 0.7

Set 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.

Use an envelope in a SynthDef

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 the exact-duration loop test

  1. Run makeRandomEnvTest_LoopExactDuration.scd

  2. Confirm that SuperCollider reports a duration of 60.0

  3. Confirm that the reported start and end levels match

  4. Listen as each 60-second pass is reported in the Post window

  5. Confirm that the envelope repeats without a sudden level jump or fade to silence

  6. Stop the test

    ~makeRandomEnvTestSynth.free;

The test repeats one generated envelope. It does not generate a new envelope for each pass.

Notes

  • 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

About

Reusable SuperCollider tools for generating safe, configurable random envelopes with exact-duration and seamless-looping support

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages