Sampler in ChucK
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

147 řádky
4.5KB

  1. //TODO: turn off adcThru when recording, and turn it back on afterwards
  2. //TODO: Effects break panning for some unknown reason
  3. //TODO varying number of bars
  4. //TODO: Subdivide metronome (still a bit wierd)
  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 => float adcThruLevel;
  16. 1 => int adcThruMute;
  17. adcThruLevel * adcThruMute => adcThru.gain;
  18. 10000 => lpf.freq;
  19. 10 => hpf.freq;
  20. // Plug in the pedals
  21. LoopPedal pedals[4];
  22. for( 0 => int i; i < pedals.cap(); i++ ) {
  23. pedals[i].recordFrom(mainInput);
  24. pedals[i].outputTo(outputWet, outputDry);
  25. }
  26. // Create the metronome
  27. Metronome metronome;
  28. spork ~metronome.run();
  29. // Start listening to OSC messages
  30. OscIn oin; 9000 => oin.port;
  31. oin.listenAll();
  32. OscMsg msg;
  33. // Event loop
  34. while (true) {
  35. oin => now;
  36. while (oin.recv(msg)) {
  37. if (msg.address=="/input") {
  38. msg.getFloat(0) => adc.gain;
  39. msg.getFloat(1) => adcThruLevel;
  40. adcThruLevel * adcThruMute => adcThru.gain;
  41. }
  42. else if(msg.address=="/delay") {
  43. msg.getFloat(0)::second => dur loopTime;
  44. msg.getFloat(1) => float feedback;
  45. for( 0 => int i; i < pedals.cap(); i++ ) {
  46. pedals[i].setLoopPoint(loopTime);
  47. pedals[i].setFeedback(feedback);
  48. }
  49. }
  50. else if(msg.address=="/channel") {
  51. msg.getInt(0) => int i;
  52. pedals[i].setGain(msg.getFloat(1));
  53. pedals[i].setPan(msg.getFloat(2));
  54. pedals[i].setWet(msg.getFloat(3));
  55. }
  56. else if(msg.address=="/arm") {
  57. msg.getInt(0) => int channel;
  58. (channel<0) => adcThruMute;
  59. adcThruLevel * adcThruMute => adcThru.gain;
  60. for( 0 => int i; i < pedals.cap(); i++ ) { pedals[i].arm(i==channel); }
  61. }
  62. else if(msg.address=="/metronome") {
  63. metronome.mute(msg.getInt(0));
  64. }
  65. else if(msg.address=="/clear") {
  66. msg.getInt(0) => int channel;
  67. pedals[channel].clear();
  68. }
  69. else if(msg.address=="/fx") {
  70. (100+msg.getFloat(0)*10000) => lpf.freq;
  71. (100+msg.getFloat(1)*10000) => hpf.freq;
  72. msg.getFloat(2) => reverb.mix;
  73. }
  74. else if(msg.address=="/master") {
  75. msg.getFloat(0) => mainOutput.gain;
  76. }
  77. }
  78. }
  79. class LoopPedal
  80. {
  81. // We are wrapping a live sampler, LiSa
  82. LiSa sample;
  83. sample => Gain wet;
  84. sample => Gain dry;
  85. // Setup
  86. 10::second => sample.duration; // Allocate max 10 secs of memory
  87. 0::second => sample.recPos => sample.playPos;
  88. 1.0 => sample.feedback;
  89. 1 => sample.loop;
  90. setLoopPoint(1::second);
  91. setWet(0.5);
  92. public void setLoopPoint( dur length ) { length => sample.loopEnd => sample.loopEndRec; }
  93. public void setFeedback( float fb ) { fb => sample.feedback; }
  94. public void setGain( float gain ) { gain => sample.gain; }
  95. public void setPan( float pan ) { } //pan => panner.pan; }
  96. public void setWet( float ratio ) { ratio => wet.gain; 1-ratio => dry.gain;}
  97. public void clear() { sample.clear(); }
  98. public void recordFrom(UGen ugen) { ugen => sample; }
  99. public dur remaining() { sample.loopEnd() => dur ltime; return (ltime - sample.playPos()) % (ltime/4.); }
  100. public int beat() {
  101. <<< 4*sample.playPos()/sample.loopEnd()>>>;
  102. return Math.round(4 * sample.playPos() / sample.loopEnd()) $ int;
  103. }
  104. public void outputTo(UGen wetSink, UGen drySink) {
  105. 1 => sample.play;
  106. wet => wetSink;
  107. dry => drySink;
  108. }
  109. public void arm(int value) {
  110. sample.playPos() => sample.recPos;
  111. value => sample.record;
  112. }
  113. }
  114. class Metronome
  115. {
  116. // A simple metronome
  117. SinOsc s => ADSR a;
  118. 0.5 => s.gain;
  119. a.set(0.001, .1, .5, .05);
  120. 0.01::second => dur plipTime;
  121. fun void mute(int value) {
  122. if (value){ a => dac; } else { a =< dac; }
  123. }
  124. fun void run() {
  125. while(true){
  126. 500 + 500*(pedals[0].beat()==1) => s.freq;
  127. a.keyOn(); plipTime => now; a.keyOff();
  128. pedals[0].remaining() => now;
  129. }
  130. }
  131. }