Advertisement
enigma_0Z

ChucK HPF Click demonstration

Jun 13th, 2011
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. // Patches...
  2. Gain mg; // Master gain
  3. .2 => mg.gain;
  4.  
  5. Gain ng; // Note gain
  6. 1 => ng.gain;
  7.  
  8. SawOsc osc;
  9. HPF hpf;
  10.  
  11. // The patch (we're not patched into the DAC just yet
  12. osc => hpf => ng => mg;
  13.  
  14. // Midi note #'s (for testing)
  15. [ 40, 70 ] @=> int scale[];
  16.  
  17. // ADSR parameters. Reduce the note attack to tame the click, but even at
  18. // 25::ms, I can still hear it. I think this only masks the problem because
  19. // the note gain stage is after the filters and ugen.
  20. 1::ms => dur noteLenA;
  21. 1000::ms => dur noteLenD;
  22.  
  23. // How finely to do ADSR/modulation/whatever
  24. 1::ms => dur res;
  25.  
  26. // Working vars
  27. time later;
  28. 0 => int i;
  29. 0 => int note;
  30. 1 => float noteGain;
  31.  
  32. // Static HPF: This method doesn't cause much clicking, though setting the
  33. // cutoff frequency to something high does induce a little bit, I could
  34. // write that off to the nature of the filter being a *high* pass filter,
  35. // and technically a click is a very short instance of a very high freq
  36. // jump.
  37. //Std.mtof(scale[0]) * 4 => hpf.freq; // Set HPF for our low freq note
  38. Std.mtof(scale[1]) * 4 => hpf.freq; // Set HPF for our high freq note
  39.  
  40. // Final patching (into the DAC)
  41. mg => dac;
  42.  
  43. // infinite time loop
  44. while( true )
  45. {
  46. 0 => noteGain;
  47. noteGain => ng.gain;
  48. scale[i % scale.cap()] => note;
  49.  
  50. Std.mtof(note) => osc.freq;
  51.  
  52. // Dynamic HPF: This line causes the majority of the clicking. Comment
  53. // it out and use static HPF instead to see the difference.
  54. osc.freq() * 4 => hpf.freq;
  55.  
  56. <<< note, osc.freq(), hpf.freq() >>>;
  57.  
  58. // Attack
  59. now + noteLenA => later;
  60. while (now < later)
  61. {
  62. res/noteLenA +=> noteGain;
  63. noteGain => ng.gain;
  64. 1::res => now;
  65. }
  66.  
  67. // Decay
  68. now + noteLenD => later;
  69. while (now < later)
  70. {
  71. res/noteLenD -=> noteGain;
  72. noteGain => ng.gain;
  73. 1::res => now;
  74. }
  75.  
  76. // Pause for silence a little bit before sounding the next note - to
  77. // prevent discontinuities and in general to sound nice.
  78. 100::ms => now;
  79.  
  80. 1 +=> i;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement