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.

114 lines
5.5KB

  1. main.csd
  2. Pete Shadbolt.2014
  3. Based on code by Iain McCurdy, 2006
  4. THE delay OPCODE IS PLACED IN A SEPARATE, ALWAYS ON, INSTRUMENT FROM THE SOURCE SOUND PRODUCING INSTRUMENT.
  5. THE IS A COMMONLY USED TECHNIQUE WITH TIME SMEARING OPCODES AND EFFECTS LIKE REVERBS AND DELAYS.
  6. ksmps MAY NEED TO BE LOW (AND kr THEREFORE HIGH) WHEN WORKING WITH SHORT DELAY TIMES DEFINED INITIALLY AT KRATE
  7. <CsoundSynthesizer>
  8. <CsOptions>
  9. -iadc -odac -dm0
  10. </CsOptions>
  11. <CsInstruments>
  12. sr = 44100 ;SAMPLE RATE
  13. ksmps = 4 ;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE (MAY NEED TO BE LOW WHEN WORKING WITH SHORT DELAY TIMES DEFINED INITIALLY AT KRATE)
  14. nchnls = 2 ;NUMBER OF CHANNELS (2=STEREO)
  15. 0dbfs = 1 ;MAXIMUM AMPLITUDE
  16. ;FLTK INTERFACE CODE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  17. FLcolor 255, 255, 255, 0, 0, 0
  18. ; LABEL | WIDTH | HEIGHT | X | Y
  19. FLpanel "M I L C H L O D E", 500, 300, 0, 0
  20. ; ON | OFF | TYPE | WIDTH | HEIGHT | X | Y | OPCODE | INS | STARTTIM | DUR
  21. gkOnOff,ihOnOff FLbutton "Input On/Off", 1, 0, 22, 180, 25, 5, 5, 0, 1, 0, -1
  22. FLsetColor2 255, 255, 50, ihOnOff ;SET SECONDARY COLOUR TO YELLOW
  23. ;GENERAL_TEXT_SETTINGS SIZE | FONT | ALIGN | RED | GREEN | BLUE
  24. FLlabel 13, 1, 3, 255, 255, 255 ;LABELS MADE INVISIBLE (I.E. SAME COLOR AS PANEL)
  25. ;BUTTON BANKS TYPE | NUMX | NUMY | WIDTH | HEIGHT | X | Y | OPCODE | INS | STARTTIM | DUR
  26. ;gkinput, ihinput FLbutBank 14, 1, 2, 18, 40, 250, 0, -1
  27. ;GENERAL_TEXT_SETTINGS SIZE | FONT | ALIGN | RED | GREEN | BLUE
  28. FLlabel 13, 1, 3, 0, 0, 0 ;LABELS MADE VISIBLE AGAIN
  29. ;VALUE_DISPLAY_BOXES WIDTH | HEIGHT | X | Y
  30. iddlt FLvalue " ", 80, 20, 5, 75
  31. idmix FLvalue " ", 80, 20, 5, 125
  32. idfeedbackamt FLvalue " ", 80, 20, 5, 175
  33. idamp FLvalue " ", 80, 20, 5, 225
  34. idporttime FLvalue " ", 80, 20, 5, 275
  35. ;SLIDERS MIN | MAX | EXP | TYPE | DISP | WIDTH | HEIGHT | X | Y
  36. gkdlt,ihdlt FLslider "Delay Time (sec)", .001, 5, -1, 23, iddlt, 490, 25, 5, 50
  37. gkmix,ihmix FLslider "Dry/Wet Mix", 0, 1, 0, 23, idmix, 490, 25, 5, 100
  38. gkfeedamt,ihfeedamt FLslider "Feedback Ratio", -1, 1, 0, 23, idfeedbackamt, 490, 25, 5, 150
  39. gkamp,ihamp FLslider "Output Amplitude Rescaling", 0, 1, 0, 23, idamp, 490, 25, 5, 200
  40. gkporttime,ihporttime FLslider "Portamento Time", 0, 2, 0, 23, idporttime, 490, 25, 5, 250
  41. gkingain,ihingain FLslider "Live Input Gain", 0, 1, 0, 23, -1, 140, 20, 350, 5
  42. ;SET_INITIAL_VALUES VALUE | HANDLE
  43. FLsetVal_i 1, ihOnOff
  44. FLsetVal_i .5, ihingain
  45. FLsetVal_i .5, ihdlt
  46. FLsetVal_i 0.5, ihmix
  47. FLsetVal_i 0.7, ihfeedamt
  48. FLsetVal_i .7, ihamp
  49. FLsetVal_i 0.3, ihporttime
  50. FLpanel_end ;END OF PANEL CONTENTS
  51. FLrun ;RUN THE FLTK WIDGET THREAD
  52. ;END OF FLTK INTERFACE CODE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  53. instr 1 ;PLAYS FILE
  54. if gkOnOff=0 then ;SENSE FLTK ON/OFF SWITCH
  55. turnoff ;TURN THIS INSTRUMENT OFF IMMEDIATELY
  56. endif
  57. asigL, asigR ins ;TAKE INPUT FROM COMPUTER'S AUDIO INPUT
  58. gasigL = asigL * gkingain ;SCALE USING 'Input Gain' SLIDER
  59. gasigR = asigR * gkingain ;SCALE USING 'Input Gain' SLIDER
  60. endin
  61. instr 2 ;DELAY INSTRUMENT
  62. kporttime linseg 0, .001, 1, 1, 1 ;USE OF AN ENVELOPE VALUE THAT QUICKLY RAMPS UP FROM ZERO TO 1. THIS PREVENTS VARIABLES GLIDING TO THEIR REQUIRED VALUES EACH TIME THE INSTRUMENT IS STARTED.
  63. kporttime = kporttime * gkporttime ;SCALE PORTAMENTO FUNCTION WITH FLTK SLIDER VALUE
  64. kdlt portk gkdlt, kporttime ;PORTAMENTO IS APPLIED TO THE VARIABLE 'gkdlt'. A NEW VARIABLE 'kdlt' IS CREATED.
  65. adlt interp kdlt ;A NEW A-RATE VARIABLE 'adlt' IS CREATED BY INTERPOLATING THE K-RATE VARIABLE 'kdlt'
  66. ;;;LEFT CHANNEL DELAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  67. abufferL delayr 5 ;CREATE A DELAY BUFFER OF 5 SECONDS DURATION (EQUIVALENT TO THE MAXIMUM DELAY TIME POSSIBLE USING THIS EXAMPLE)
  68. adelsigL deltap3 adlt ;TAP THE DELAY LINE AT gkdlt SECONDS
  69. delayw gasigL + (adelsigL * gkfeedamt) ;WRITE AUDIO SOURCE AND FEEDBACK SIGNAL INTO THE BEGINNING OF THE BUFFER
  70. ;;;RIGHT CHANNEL DELAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  71. abufferR delayr 5 ;CREATE A DELAY BUFFER OF 5 SECONDS DURATION (EQUIVALENT TO THE MAXIMUM DELAY TIME POSSIBLE USING THIS EXAMPLE)
  72. adelsigR deltap3 adlt ;TAP THE DELAY LINE AT gkdlt SECONDS
  73. delayw gasigR + (adelsigR * gkfeedamt) ;WRITE AUDIO SOURCE AND FEEDBACK SIGNAL INTO THE BEGINNING OF THE BUFFER
  74. aL ntrpol gasigL, adelsigL, gkmix
  75. aR ntrpol gasigR, adelsigR, gkmix
  76. outs aL * gkamp, aR * gkamp ;CREATE A MIX BETWEEN THE WET AND THE DRY SIGNALS AT THE OUTPUT
  77. clear gasigL, gasigR ;CLEAR THE GLOBAL AUDIO SEND VARIABLES
  78. endin
  79. </CsInstruments>
  80. <CsScore>
  81. ;INSTR | START | DURATION
  82. i 2 0 -1 ;INSTRUMENT 2 (DELAY INSTRUMENT) PLAYS A HELD NOTE
  83. f 0 3600 ;'DUMMY' SCORE EVENT KEEPS REALTIME PERFORMANCE GOING FOR 1 HOUR
  84. </CsScore>
  85. </CsoundSynthesizer>