Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Patches...
- Gain mg; // Master gain
- .2 => mg.gain;
- Gain ng; // Note gain
- 1 => ng.gain;
- SawOsc osc;
- HPF hpf;
- // The patch (we're not patched into the DAC just yet
- osc => hpf => ng => mg;
- // Midi note #'s (for testing)
- [ 40, 70 ] @=> int scale[];
- // ADSR parameters. Reduce the note attack to tame the click, but even at
- // 25::ms, I can still hear it. I think this only masks the problem because
- // the note gain stage is after the filters and ugen.
- 1::ms => dur noteLenA;
- 1000::ms => dur noteLenD;
- // How finely to do ADSR/modulation/whatever
- 1::ms => dur res;
- // Working vars
- time later;
- 0 => int i;
- 0 => int note;
- 1 => float noteGain;
- // Static HPF: This method doesn't cause much clicking, though setting the
- // cutoff frequency to something high does induce a little bit, I could
- // write that off to the nature of the filter being a *high* pass filter,
- // and technically a click is a very short instance of a very high freq
- // jump.
- //Std.mtof(scale[0]) * 4 => hpf.freq; // Set HPF for our low freq note
- Std.mtof(scale[1]) * 4 => hpf.freq; // Set HPF for our high freq note
- // Final patching (into the DAC)
- mg => dac;
- // infinite time loop
- while( true )
- {
- 0 => noteGain;
- noteGain => ng.gain;
- scale[i % scale.cap()] => note;
- Std.mtof(note) => osc.freq;
- // Dynamic HPF: This line causes the majority of the clicking. Comment
- // it out and use static HPF instead to see the difference.
- osc.freq() * 4 => hpf.freq;
- <<< note, osc.freq(), hpf.freq() >>>;
- // Attack
- now + noteLenA => later;
- while (now < later)
- {
- res/noteLenA +=> noteGain;
- noteGain => ng.gain;
- 1::res => now;
- }
- // Decay
- now + noteLenD => later;
- while (now < later)
- {
- res/noteLenD -=> noteGain;
- noteGain => ng.gain;
- 1::res => now;
- }
- // Pause for silence a little bit before sounding the next note - to
- // prevent discontinuities and in general to sound nice.
- 100::ms => now;
- 1 +=> i;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement