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.

79 lines
2.1KB

  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. }
  38. else if(msg.address=="/arm")
  39. {
  40. msg.getInt(0) => int channel;
  41. for( 0 => int i; i < channels.cap(); i++ ) { channels[i].arm(i==channel); }
  42. }
  43. }
  44. }
  45. public class SampleChan
  46. {
  47. // Chain
  48. adc => LiSa sample => LPF filter;
  49. // Setup
  50. 10::second => sample.duration; //This is the max duration
  51. 0::second => sample.recPos => sample.playPos;
  52. 1.0 => sample.feedback;
  53. 1 => sample.loop;
  54. 1 => filter.Q;
  55. setLoopPoint(1::second);
  56. setFilter(10000);
  57. public void setLoopPoint( dur length ) { length => sample.loopEnd => sample.loopEndRec; }
  58. public void setFeedback( float fb ) { fb => sample.feedback; }
  59. public void setFilter( float freq ) { freq => filter.freq; }
  60. public void setGain( float gain ) { gain => filter.gain; }
  61. public void outputTo(UGen ugen) {
  62. 1 => sample.play;
  63. filter => ugen;
  64. }
  65. public void arm(int value) {
  66. value => sample.record;
  67. }
  68. }