Created
July 30, 2022 00:46
-
-
Save jamshark70/4d1beb947a4aac77ea32e6c1c6b42160 to your computer and use it in GitHub Desktop.
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
// H. James Harkins | |
// A demonstration of the effect of convolving | |
// Dirac impulses against a convolution kernel. | |
// It turns out to be granular synthesis! | |
// (Except, every grain is the full kernel, | |
// no control over rate, duration etc.) | |
s.boot; | |
s.record; | |
p = ProxySpace.new.push; | |
p.gui; | |
~out = { Limiter.ar(\in.ar(0), 0.98).dup }; | |
~impulse = { |t_trig| Trig1.ar(t_trig, SampleDur.ir) }; | |
~impulse <>> ~out; | |
// play the impulse on demand | |
( | |
Button(nil, Rect(800, 200, 100, 30)) | |
.front | |
.states_([["click"]]) | |
.action_({ ~impulse.set(\t_trig, 1) }); | |
) | |
// 1 pulse per second | |
~impulse = { Impulse.ar(1) }; | |
// convolution | |
// the piano note is fairly long (loading about 2 seconds here) | |
// so we'll use "partitioned convolution" | |
// setup takes 3 steps | |
// substitute your own sample here | |
( | |
fork { | |
b = Buffer.readChannel(s, "/media/dlm/7D53-8744/samplelibs/SalamanderGrandPianoV3_48khz24bit/48khz24bit/D#5v6.wav", numFrames: 131072, channels: [1]); | |
s.sync; | |
c = Buffer.alloc(s, PartConv.calcBufSize(1024, b), 1); | |
s.sync; | |
c.preparePartConv(b, 1024); | |
}; | |
) | |
// but the convolution unit is easy to use | |
( | |
~convolver = { | |
var trig = \in.ar(0); | |
PartConv.ar(trig, 1024, c) | |
}; | |
) | |
// patch the convolver to the output | |
~impulse <>> ~convolver <>> ~out; | |
// each pulse = one note! | |
~impulse = { Impulse.ar(3) }; | |
// impulse varies by mouse | |
( | |
~impulse = { | |
var freq = MouseX.kr(1, 800, 1); | |
SendReply.kr(Impulse.kr(10), '/freq', freq); | |
Impulse.ar(freq) | |
}; | |
) | |
// display Hz | |
( | |
if(z.isNil) { | |
z = NumberBox(nil, Rect(800, 500, 200, 80)).front; | |
z.font = Font.default.size_(48); | |
z.onClose_({ | |
z = nil; | |
OSCdef(\freq).free; | |
}); | |
}; | |
OSCdef(\freq, { |msg| | |
{ z.value = msg[3] }.defer; | |
}, '/freq', s.addr); | |
) | |
p.clear; p.pop; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment