Advertisement
Guest User

Test

a guest
Dec 16th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.20 KB | None | 0 0
  1. // A pitch sequencer which samples a single cello note, and plays a sequence of root -> m3 -> m6 -> P8.
  2. // The sample is A3, but the root of the sequence can be changed by multiplying the sample's frequency.
  3. SndBuf celloA3 => ADSR env => NRev reverb =>  dac;
  4.  
  5. // Load the cello note sample.
  6. me.dir() => string path;
  7. "/audio/A3.wav" => string filename;
  8. path+filename => filename;
  9. filename => celloA3.read;
  10.  
  11. // Duration of keyOn / keyOff.
  12. // Set keyOn very low (~25) for Pacman sounds!
  13. 130::ms => dur keyOnDur;
  14. 10::ms => dur keyOffDur;
  15.  
  16. // Configure ASDR
  17. env.set(10::ms, 8::ms, 0.7, keyOffDur);
  18.  
  19. // Configure reverb
  20. 0.12 => reverb.mix;
  21.  
  22. // Define the root notes we want to use, in order: A3, D3, F3, G3, A3.
  23. [
  24.     celloA3.freq(),
  25.     celloA3.freq() * Math.pow(2.0, (-7.0/12.0)),
  26.     celloA3.freq() * Math.pow(2.0, (-4.0/12.0)),
  27.     celloA3.freq() * Math.pow(2.0, (-2.0/12.0)),
  28.     celloA3.freq()
  29. ] @=> float roots[];
  30.  
  31. // Play the sequence four times for each of the roots.
  32. for (0 => int i; i < roots.cap(); i++) {
  33.     pitchSequence(roots[i], false);
  34.     pitchSequence(roots[i], false);
  35.     pitchSequence(roots[i], false);
  36.     if (i == 4)
  37.     {
  38.         pitchSequence(roots[i], true);
  39.     }
  40.     else
  41.     {
  42.         pitchSequence(roots[i], false);
  43.     }
  44. }
  45.    
  46. fun void pitchSequence(float rootFreq, int isFinalSequence) {
  47.     // Root
  48.     2.5 => celloA3.gain;
  49.     0 => celloA3.pos;
  50.     rootFreq => celloA3.freq;
  51.     env.keyOn();
  52.     keyOnDur => now;
  53.     env.keyOff();
  54.     keyOffDur => now;
  55.    
  56.     // Minor 3rd
  57.     1.5 => celloA3.gain;
  58.     0 => celloA3.pos;
  59.     rootFreq * Math.pow(2.0, (3.0/12.0)) => celloA3.freq;
  60.     env.keyOn();
  61.     keyOnDur => now;
  62.     env.keyOff();
  63.     keyOffDur => now;
  64.    
  65.     // Minor 6th
  66.     1.5 => celloA3.gain;
  67.     0 => celloA3.pos;
  68.     rootFreq * Math.pow(2.0, (8.0/12.0)) => celloA3.freq;
  69.     env.keyOn();
  70.     keyOnDur => now;
  71.     env.keyOff();
  72.     keyOffDur => now;
  73.    
  74.     // +1 Octave
  75.     1 => celloA3.gain;
  76.     0 => celloA3.pos;
  77.     rootFreq * 2 => celloA3.freq;
  78.     env.keyOn();
  79.     keyOnDur => now;
  80.     env.keyOff();
  81.     if (isFinalSequence)
  82.     {
  83.         2::second => now;
  84.     }
  85.     else
  86.     {
  87.         keyOffDur => now;
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement