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.

153 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].setLoopPoint(loopTime);
  43. pedals[i].setFeedback(feedback);
  44. }
  45. }
  46. else if(msg.address=="/channel") {
  47. msg.getInt(0) => int i;
  48. pedals[i].setGain(msg.getFloat(1));
  49. pedals[i].setPan(msg.getFloat(2));
  50. pedals[i].setWet(msg.getFloat(3));
  51. }
  52. else if(msg.address=="/arm") {
  53. msg.getInt(0) => int channel;
  54. for( 0 => int i; i < pedals.cap(); i++ ) { pedals[i].arm(i==channel); }
  55. }
  56. else if(msg.address=="/metronome") {
  57. //msg.getInt(0) => metronomeLevel;
  58. }
  59. else if(msg.address=="/clear") {
  60. msg.getInt(0) => int channel;
  61. pedals[channel].clear();
  62. }
  63. else if(msg.address=="/fx") {
  64. (100+msg.getFloat(0)*10000) => lpf.freq;
  65. (100+msg.getFloat(1)*10000) => hpf.freq;
  66. msg.getFloat(2) => reverb.mix;
  67. }
  68. else if(msg.address=="/master") {
  69. msg.getFloat(0) => mainOutput.gain;
  70. }
  71. }
  72. }
  73. public class LoopPedal
  74. {
  75. // We are wrapping a live sampler, LiSa
  76. LiSa sample;
  77. sample => Gain wet;
  78. sample => Gain dry;
  79. // Setup
  80. 10::second => sample.duration; // Allocate max 10 secs of memory
  81. 0::second => sample.recPos => sample.playPos;
  82. 1.0 => sample.feedback;
  83. 1 => sample.loop;
  84. setLoopPoint(1::second);
  85. setWet(0.5);
  86. public void setLoopPoint( dur length ) { length => sample.loopEnd => sample.loopEndRec; }
  87. public void setFeedback( float fb ) { fb => sample.feedback; }
  88. public void setGain( float gain ) { gain => sample.gain; }
  89. public void setPan( float pan ) { } //pan => panner.pan; }
  90. public void setWet( float ratio ) { ratio => wet.gain; 1-ratio => dry.gain;}
  91. public void clear() { sample.clear(); }
  92. public void recordFrom(UGen ugen) { ugen => sample; }
  93. public void outputTo(UGen wetSink, UGen drySink) {
  94. 1 => sample.play;
  95. wet => wetSink;
  96. dry => drySink;
  97. }
  98. public void arm(int value) {
  99. 0 => adcThru.gain;
  100. sample.playPos() => sample.recPos;
  101. value => sample.record;
  102. }
  103. }
  104. /*
  105. // Start the metronome and the vu meter (optional)
  106. //0 => int metronomeLevel;
  107. //spork ~plip();
  108. //spork ~vu_meter();
  109. // TODO timing here should be done using events
  110. fun void metronome()
  111. {
  112. SinOsc s => dac;
  113. 0.01::second => dur plipTime;
  114. while(true){
  115. for( 0 => int i; i < 4; i++ ) {
  116. if (i==0){2000 => s.freq;} else {1000 => s.freq;}
  117. .1*metronomeLevel => s.gain;
  118. plipTime => now;
  119. 0 => s.gain;
  120. loopTime/4 - plipTime => now;
  121. }
  122. }
  123. }
  124. */