here is a gist that aims to help investigate auto-levelling strategies in supercollider.
it consists of:
- a class file called
PolyLevelTest.sc, which is compatible with norns system, and should be installed in e.g. Platform.userExtensionDir,)
- a script called
poly_level_test.scd which should be run line-by-line according to the comments.
the input synth makes rando FM notes with random noise mixture, filtered randomly. so perceptual loudness and spectral distribution varies a lot, although the raw amplitude of each voice should be the same (unless i messed up.)
there are two basic approaches shown here.
- use the
onFree method when spawning a voice, to define a callback that will fire when that voice is finished; in that callback, calculate and apply appropriate master output bus gain given the current count of active voices. parameters of this calculation can be tuned at runtime. (currently just a single param, estimating added gain per voice.)
limitations: in the very quick and dirty implementation here, this just sounds like a really terrible compressor to me. gain factor is smoothed, but it is still just a series of flat plateaus connected by exponential ramps. overshoot would be a problem if amp smoothing time were longer than the attack time of a voice.
further work for this approach: it would be more robust and flexible to actually use ampltude followers on each voice and/or break out the signals from the voice amplitude envelopes. this is effectively a compressor, but with the gain calculation explicitly broken out and performed on the client side (while keeping per-sample smoothing/filtering calculations on the server side.) like other bus limiters, this would benefit from a lookahead path at the expense of latency.
- use
Limiter or Normalizer Ugens, performing all gain computation on the server.
Normalizer is just a very aggressive limiter with automatic makeup gain. both of these ugens guarantee that output will never exceed specified gain limit by using a lookahead delay.
limitations: lookahead means latency.
further work: break out limiter parameters for tweaking.