Advertisement
SoundEngraver

Looping Audio Files

Mar 6th, 2024
1,109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //////////////////////////  LOOP AUDIO FILES //////////////////////////
  2.  
  3. s.boot;
  4.  
  5. s.meter;
  6. s.scope;
  7. s.plotTree;
  8.  
  9.  
  10. // Only use when necessary. It isn't always needed.
  11.  
  12. s.reboot;
  13. s.quit;
  14.  
  15.  
  16. ///////////////////// Things To Know Before Running Code /////////////////////
  17.  
  18. /*
  19.  
  20. All my original SC documents are in the "dracula" color.
  21. To find or change this, go To SuperCollider ––> Preferences ––> Editor ––> Font & Colors.
  22. ––> Select under Color, dracula.
  23.  
  24. Arguments in Synths are represented with a backslash, "\", in green under the "dracula" color font. Values presented with these arguments can be changed. Only remember to NEVER cross 0, when using an exponential method like "exprand."
  25.  
  26. Arguments also precede a colon ":", as seen in a list of a UGen following a variable, "var."
  27. Example: sig = PlayBuf.ar(2, buf, rate, startPos: spos);
  28.  
  29. Argument and variable names can be changed to your liking.
  30.  
  31. Please be careful with volume output. Always have SuperCollider run through headphones. If you're unsure what the output will be, keep headphones away, with your main volume all the way down. Check your level meter and Stethoscope for visual cues. If everything looks safe (e.g. level meter is NOT in the red), proceed.
  32.  
  33. You can always execute a hard stop with Command Period.
  34.  
  35. */
  36.  
  37. // Audio File
  38.  
  39. ~audio = Buffer.read(s, "insertaudiofilehere");
  40.  
  41. ~audio.play;
  42. ~audio.free; //free the synth
  43.  
  44. ~audio.duration; // audio file's duration
  45. ~audio.numChannels; // audio file's channel number
  46.  
  47. ~audio.sampleRate; // audio file's sample rate
  48.  
  49.  
  50. (
  51. ~tortoDrums = SynthDef(\playDrums, {
  52.     arg buf=0, rate=1, spos=0, loop=1, pan=0, amp=0.5, out=0;
  53.     var sig;
  54.     sig = PlayBuf.ar(
  55.         numChannels: 2,
  56.         bufnum: buf,
  57.         rate: BufRateScale.kr(buf) * rate,
  58.         startPos: spos,
  59.         loop: loop,
  60.         // Note: My loop argument is set to 1, which means true, or that it will loop.
  61.         // If the loop argument is set to 0, it means false, or that it won't loop.
  62.     );
  63.     sig = Pan2.ar(sig, pan, amp);
  64.     Out.ar(out, sig);
  65. }).add;
  66. )
  67.  
  68. ~tortoDrums = Synth(\playDrums, [\buf, ~drums]);
  69. ~tortoDrums.set(\loop, 0); // Evaluating this will stop the loop.
  70.  
  71. ~tortoDrums.free; // Free the synth, since there is no doneAction value.
  72.  
  73. // If you want a doneAction value, the loop argument must be set to 0, or the doneAction value will not be evaluated.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement