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.

87 lines
2.0KB

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