Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////////////////////// BufRateScale UGen //////////////////////////
- // Here's a video demonstration: https://youtu.be/0SYCZkv18tI
- s.boot;
- s.meter;
- s.scope;
- s.plotTree;
- s.reboot;
- s.quit;
- // Remember this UGen when working with audio files in SuperCollider!
- // Drum Loop
- ~drums = Buffer.read(s, "insertaudiofilehere");
- ~drums.play;
- ~drums.duration; // If you would like to see the sound file's duration.
- ~drums.numChannels; // If you would like to see how many channels it is.
- ~drums.sampleRate; // Great way to see your audio file's sample rate.
- //////////// Drum Loop ////////////
- // Old bad code...
- // My drum loop is running at a sample rate of 48k.
- // The audio server is running at 44.1k.
- // Because of this, you're hearing a slower drum loop (compared to its original speed).
- // Try your audio file with the code below...
- (
- ~tortoDrums = SynthDef(\play, {
- arg buf=0, rate=1, spos=0, pan=0, amp=1, out=0;
- var sig;
- sig = PlayBuf.ar(2, buf, rate, spos);
- pan = Pan2.ar(sig, pan, amp);
- Out.ar(out, sig);
- }).add;
- )
- ~tortoDrums = Synth(\play, [\buf, ~drums]);
- ~tortoDrums.free; // Free the synth if you don't have an Env or doneAction value.
- // Better code
- (
- ~tortoDrums = SynthDef(\play, {
- arg buf=0, rate=1, spos=0, pan=0, amp=1, out=0;
- var sig;
- sig = PlayBuf.ar(
- 2,
- buf,
- BufRateScale.kr(buf) * rate, // edited rate argument
- spos
- );
- pan = Pan2.ar(sig, pan, amp);
- Out.ar(out, sig);
- }).add;
- )
- ~tortoDrums = Synth(\play, [\buf, ~drums]); // It plays at its original speed!
- ~tortoDrums.free; // Free the synth if you don't have an Env or doneAction value.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement