Hz.ModEnv
is a parameter modulator
that can be used to drive parameter
changes of one or more parameters in your audio graph. See Hz.ADSR
instead if you wish to produce audio-rate modulation signals for side-chaining.
// ModEnv example, modulate the Amplitude of the oscillator.
// NB: since Hz.Osc already has a builtin adsr, this example
// is educational. You can easily repurpose it to modulate
// an abitrary anode parameter of your choosing..
let id = `f${this.GetId()}: `;
let scene = await Ascene.BeginFiber(this);
let env = scene.NewModulator("Hz.ModEnv");
let osc = scene.NewAnode("Hz.Osc", {cfg: "stereo"});
let out = scene.GetDAC();
scene.Chain(osc, out);
const remap = env.NewRemapper({mode: 1/*set, not add*/});
scene.ModulateParam(env, osc, "Amplitude", remap);
osc.SetParam("Amplitude", 0);
await scene.Sync();
const noteDurS = .5;
osc.SetParam("/adsr/Active", 0);
env.SetParam("A", .5 * noteDurS);
env.SetParam("R", .5 * noteDurS);
await scene.Sync();
let noteHold = scene.Seconds(noteDurS + .3);
let noteTail = 2 * scene.Seconds(noteDurS) - noteHold;
for(let j=0; j < 30; j++)
{
let n = 35 + (j+3) % 30;
env.NoteOn(n, .9);
osc.NoteOn(n, .9);
await scene.Wait(noteHold);
yield;
env.NoteOff(n);
osc.NoteOff(n);
await scene.Wait(noteTail);
yield;
}
console.log("Done");