Sampler in ChucK
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
4.1KB

  1. // TODO: turn off adcThru when recording
  2. // TODO: Effects break panning for some unknown reason
  3. // TODO: currently I don't turn ADC thru back on after recording
  4. // Effects chain with limiters, reverb, filters
  5. NRev reverb => LPF lpf => HPF hpf => Dyno outputLimiter => dac;
  6. outputLimiter.limit();
  7. reverb @=> UGen @ outputWet; // Reference to wet output
  8. outputLimiter @=> UGen @ outputDry; // Reference to dry output
  9. outputLimiter @=> UGen @ mainOutput; // Reference to main output
  10. // Capture mic/line in and monitor through DAC. Limit
  11. adc => Dyno inputLimiter => Gain adcThru => mainOutput; // Monitor input
  12. inputLimiter.limit();
  13. inputLimiter @=> UGen @ mainInput;
  14. // Default parameters
  15. .5 => adcThru.gain;
  16. 10000 => lpf.freq;
  17. 10 => hpf.freq;
  18. 1::second => dur loopTime;
  19. // Plug in the pedals
  20. LoopPedal pedals[4];
  21. for( 0 => int i; i < pedals.cap(); i++ ) {
  22. pedals[i].recordFrom(mainInput);
  23. pedals[i].outputTo(outputWet, outputDry);
  24. }
  25. // Start listening to OSC messages
  26. OscIn oin; 9000 => oin.port;
  27. oin.listenAll();
  28. OscMsg msg;
  29. // Event loop
  30. while (true) {
  31. oin => now;
  32. while (oin.recv(msg)) {
  33. if (msg.address=="/input") {
  34. msg.getFloat(0) => adc.gain;
  35. msg.getFloat(1) => adcThru.gain;
  36. }
  37. else if(msg.address=="/delay") {
  38. msg.getFloat(0)::second => loopTime;
  39. msg.getFloat(1) => float feedback;
  40. for( 0 => int i; i < pedals.cap(); i++ ) {
  41. pedals[i].setLoopPoint(loopTime + (i*.1)::second);
  42. pedals[i].setFeedback(feedback);
  43. }
  44. }
  45. else if(msg.address=="/channel") {
  46. msg.getInt(0) => int i;
  47. pedals[i].setGain(msg.getFloat(1));
  48. pedals[i].setPan(msg.getFloat(2));
  49. pedals[i].setWet(msg.getFloat(3));
  50. }
  51. else if(msg.address=="/arm") {
  52. msg.getInt(0) => int channel;
  53. for( 0 => int i; i < pedals.cap(); i++ ) { pedals[i].arm(i==channel); }
  54. }
  55. else if(msg.address=="/metronome") {
  56. //msg.getInt(0) => metronomeLevel;
  57. }
  58. else if(msg.address=="/clear") {
  59. msg.getInt(0) => int channel;
  60. pedals[channel].clear();
  61. }
  62. else if(msg.address=="/fx") {
  63. (100+msg.getFloat(0)*10000) => lpf.freq;
  64. (100+msg.getFloat(1)*10000) => hpf.freq;
  65. msg.getFloat(2) => reverb.mix;
  66. }
  67. else if(msg.address=="/master") {
  68. msg.getFloat(0) => mainOutput.gain;
  69. }
  70. }
  71. }
  72. public class LoopPedal
  73. {
  74. // We are wrapping a live sampler, LiSa
  75. LiSa sample;
  76. sample => Gain wet;
  77. sample => Gain dry;
  78. // Setup
  79. 10::second => sample.duration; // Allocate max 10 secs of memory
  80. 0::second => sample.recPos => sample.playPos;
  81. 1.0 => sample.feedback;
  82. 1 => sample.loop;
  83. setLoopPoint(1::second);
  84. setWet(0.5);
  85. public void setLoopPoint( dur length ) { length => sample.loopEnd => sample.loopEndRec; }
  86. public void setFeedback( float fb ) { fb => sample.feedback; }
  87. public void setGain( float gain ) { gain => sample.gain; }
  88. public void setPan( float pan ) { } //pan => panner.pan; }
  89. public void setWet( float ratio ) { ratio => wet.gain; 1-ratio => dry.gain;}
  90. public void clear() { sample.clear(); }
  91. public void recordFrom(UGen ugen) { ugen => sample; }
  92. public void outputTo(UGen wetSink, UGen drySink) {
  93. 1 => sample.play;
  94. wet => wetSink;
  95. dry => drySink;
  96. }
  97. public void arm(int value) {
  98. 0 => adcThru.gain;
  99. sample.playPos() => sample.recPos;
  100. value => sample.record;
  101. }
  102. }
  103. /*
  104. // Start the metronome and the vu meter (optional)
  105. //0 => int metronomeLevel;
  106. //spork ~plip();
  107. //spork ~vu_meter();
  108. // TODO timing here should be done using events
  109. fun void metronome()
  110. {
  111. SinOsc s => dac;
  112. 0.01::second => dur plipTime;
  113. while(true){
  114. for( 0 => int i; i < 4; i++ ) {
  115. if (i==0){2000 => s.freq;} else {1000 => s.freq;}
  116. .1*metronomeLevel => s.gain;
  117. plipTime => now;
  118. 0 => s.gain;
  119. loopTime/4 - plipTime => now;
  120. }
  121. }
  122. }
  123. */