Advertisement
SoundEngraver

BufRateScale UGen

Feb 23rd, 2024 (edited)
1,416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //////////////////////////  BufRateScale UGen //////////////////////////
  2.  
  3. // Here's a video demonstration: https://youtu.be/0SYCZkv18tI
  4.  
  5. s.boot;
  6.  
  7. s.meter;
  8. s.scope;
  9. s.plotTree;
  10.  
  11. s.reboot;
  12. s.quit;
  13.  
  14. // Remember this UGen when working with audio files in SuperCollider!
  15.  
  16. // Drum Loop
  17.  
  18. ~drums = Buffer.read(s, "insertaudiofilehere");
  19.  
  20.  
  21. ~drums.play;
  22.  
  23. ~drums.duration; // If you would like to see the sound file's duration.
  24. ~drums.numChannels; // If you would like to see how many channels it is.
  25.  
  26. ~drums.sampleRate; // Great way to see your audio file's sample rate.
  27.  
  28.  
  29.  
  30.  
  31. //////////// Drum Loop ////////////
  32.  
  33. // Old bad code...
  34. // My drum loop is running at a sample rate of 48k.
  35. // The audio server is running at 44.1k.
  36. // Because of this, you're hearing a slower drum loop (compared to its original speed).
  37.  
  38.  
  39. // Try your audio file with the code below...
  40.  
  41. (
  42. ~tortoDrums = SynthDef(\play, {
  43.     arg buf=0, rate=1, spos=0, pan=0, amp=1, out=0;
  44.     var sig;
  45.     sig = PlayBuf.ar(2, buf, rate, spos);
  46.     pan = Pan2.ar(sig, pan, amp);
  47.     Out.ar(out, sig);
  48. }).add;
  49. )
  50.  
  51. ~tortoDrums = Synth(\play, [\buf, ~drums]);
  52. ~tortoDrums.free; // Free the synth if you don't have an Env or doneAction value.
  53.  
  54.  
  55.  
  56. // Better code
  57.  
  58. (
  59. ~tortoDrums = SynthDef(\play, {
  60.     arg buf=0, rate=1, spos=0, pan=0, amp=1, out=0;
  61.     var sig;
  62.     sig = PlayBuf.ar(
  63.         2,
  64.         buf,
  65.         BufRateScale.kr(buf) * rate, // edited rate argument
  66.         spos
  67.     );
  68.     pan = Pan2.ar(sig, pan, amp);
  69.     Out.ar(out, sig);
  70. }).add;
  71. )
  72.  
  73. ~tortoDrums = Synth(\play, [\buf, ~drums]); // It plays at its original speed!
  74. ~tortoDrums.free; // Free the synth if you don't have an Env or doneAction value.
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement