Created
December 17, 2013 11:56
-
-
Save iani/8003850 to your computer and use it in GitHub Desktop.
Explore a sound buffer by looping continuously over small segments of the buffer. MouseX controls the position of the loop in the buffer, MouseY controls the (proportional) duration of the loop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Session of Tue Dec 17 13:28:06 2013 | |
| /* | |
| Controlling the start and end points of a looped buffer | |
| For this we need to use a different technique: BufRd + Phasor. | |
| Explore a sound buffer by looping continuously over small segments of the buffer. | |
| MouseX controls the position of the loop in the buffer, | |
| MouseY controls the (proportional) duration of the loop. | |
| */ | |
| Server.default.boot; | |
| //: Test how to open a dialog window for choosing the path of the buffer to load: | |
| // Here we just post the path. | |
| Dialog.openPanel({ | path | | |
| path.postln; | |
| }) | |
| //: Next step: Load the chosen audio file into a buffer. | |
| Dialog.openPanel({ | path | | |
| Server.default.waitForBoot({ // optional: Just making sure that the buffer is running | |
| ~buffer = Buffer.read(Server.default, path); | |
| ~buffer.postln; | |
| }) | |
| }) | |
| //: Listen to the buffer | |
| ~synth = ~buffer.play; | |
| //: When we want to stop the buffer playing, we can do this: | |
| ~synth.free; | |
| //: Play the buffer, using BufRd and Phasor. | |
| // The start and end arguments control the start and end of the loop | |
| ~synth = { | rate = 1, amp = 1, start = 0, end = 1 | | |
| var bnum; | |
| bnum = ~buffer.bufnum; | |
| BufRd.ar(1, bnum, | |
| Phasor.ar(0, rate * BufRateScale.kr(bnum), | |
| start * BufFrames.kr(bnum), | |
| end * BufFrames.kr(bnum) | |
| ) | |
| ) | |
| * amp; | |
| }.play; | |
| //: loop over only small part of the buffer | |
| // (and play at a 10 fold, fast, rate) | |
| ~synth.set(\start, 0.5, \end, 0.55); | |
| ~synth.set(\rate, 10); | |
| //: Sloooooowww playback of a very small part of the buffer | |
| ~synth.set(\start, 0.5, \end, 0.505); | |
| ~synth.set(\rate, 0.25); | |
| //: Silence the synth and reset its rate while editing | |
| ~synth.set(\rate, 1); | |
| ~synth.set(\amp, 0); | |
| //: Exploring the buffer | |
| // (for example: to find where the fadeout starts) | |
| ~startBus = Bus.control; | |
| ~endBus = Bus.control; | |
| ~scrollSynth = { | width = 0.01 | | |
| var x; | |
| x = MouseX.kr(0, 1 - width); | |
| Out.kr(~startBus.index, x); | |
| Out.kr(~endBus.index, x + width); | |
| }.play; | |
| //: Scroll in the buffer with the mouse, looping over small segments | |
| ~synth.set(\rate, 1); | |
| ~synth.set(\amp, 1); | |
| ~synth.map(\start, ~startBus.index); | |
| ~synth.map(\end, ~endBus.index); | |
| //: Modify the scrolling synth to change the width of the loop with the mouse | |
| ~scrollSynth.free; | |
| ~scrollSynth = { | |
| var x, width; | |
| width = MouseY.kr(0.001, 0.1, \exponential); | |
| x = MouseX.kr(0, 1 - width); | |
| Out.kr(~startBus.index, x); | |
| Out.kr(~endBus.index, x + width); | |
| }.play; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment