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.

88 lines
2.4KB

  1. // TODO: turn off adcThru when recording
  2. // Effects chain
  3. adc => Gain adcThru => Gain mixer => dac; // Monitor input through a mixer
  4. SampleChan channels[4];
  5. // Levels
  6. //0 => adc.gain;
  7. .5 => adcThru.gain;
  8. // Each channel should output to the mixer
  9. for( 0 => int i; i < channels.cap(); i++ ) { channels[i].outputTo(mixer); }
  10. // Listen to OSC messages
  11. OscIn oin; 9000 => oin.port;
  12. oin.listenAll();
  13. OscMsg msg;
  14. // Event loop
  15. while (true) {
  16. oin => now;
  17. //1::second => now;
  18. while (oin.recv(msg)) {
  19. if (msg.address=="/input")
  20. {
  21. msg.getFloat(0) => adc.gain;
  22. msg.getFloat(1) => adcThru.gain;
  23. }
  24. else if(msg.address=="/delay")
  25. {
  26. msg.getFloat(0)::second => dur loopPoint;
  27. msg.getFloat(1) => float feedback;
  28. for( 0 => int i; i < channels.cap(); i++ ) {
  29. channels[i].setLoopPoint(loopPoint);
  30. channels[i].setFeedback(feedback);
  31. }
  32. }
  33. else if(msg.address=="/channel")
  34. {
  35. msg.getInt(0) => int i;
  36. channels[i].setGain(msg.getFloat(1));
  37. channels[i].setPan(msg.getFloat(2));
  38. }
  39. else if(msg.address=="/arm")
  40. {
  41. msg.getInt(0) => int channel;
  42. for( 0 => int i; i < channels.cap(); i++ ) { channels[i].arm(i==channel); }
  43. }
  44. else if(msg.address=="/clear")
  45. {
  46. msg.getInt(0) => int channel;
  47. channels[channel].clear();
  48. }
  49. }
  50. }
  51. public class SampleChan
  52. {
  53. // Chain
  54. adc => LiSa sample => LPF filter;
  55. // Setup
  56. 10::second => sample.duration; //This is the max duration
  57. 0::second => sample.recPos => sample.playPos;
  58. 1.0 => sample.feedback;
  59. 1 => sample.loop;
  60. 1 => filter.Q;
  61. setLoopPoint(1::second);
  62. setFilter(10000);
  63. public void setLoopPoint( dur length ) { length => sample.loopEnd => sample.loopEndRec; }
  64. public void setFeedback( float fb ) { fb => sample.feedback; }
  65. public void setFilter( float freq ) { freq => filter.freq; }
  66. public void setGain( float gain ) { gain => filter.gain; }
  67. public void setPan( float pan ) { }
  68. public void clear() { sample.clear(); }
  69. public void outputTo(UGen ugen) {
  70. 1 => sample.play;
  71. filter => ugen;
  72. }
  73. public void arm(int value) {
  74. sample.playPos() => sample.recPos;
  75. value => sample.record;
  76. }
  77. }