From 1c7f0c0e4a1f1b6c8fe3840ee429347db80f5c59 Mon Sep 17 00:00:00 2001 From: Brian Heim Date: Wed, 18 Dec 2019 22:32:14 -0600 Subject: [PATCH] Update examples, add vco.scd --- examples/gain.scd | 5 +++-- examples/rainbow.scd | 4 ++-- examples/vco.scd | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 examples/vco.scd diff --git a/examples/gain.scd b/examples/gain.scd index 322aa7f..ff69f76 100644 --- a/examples/gain.scd +++ b/examples/gain.scd @@ -1,10 +1,11 @@ // Simplest possible script using all variables, demonstrating buffering -// by Brian Heim +// by Andrew Belt +// adapted for SC by Brian Heim ~vcv_frameDivider = 1; ~vcv_bufferSize = 32; -~vcv_process = {|block| +~vcv_process = { |block| // Loop through each row VcvPrototypeProcessBlock.numRows.do { |i| // Get gain knob diff --git a/examples/rainbow.scd b/examples/rainbow.scd index 5f676e4..ebbfc82 100644 --- a/examples/rainbow.scd +++ b/examples/rainbow.scd @@ -1,6 +1,6 @@ // Rainbow RGB LED example -// by Brian Heim -// adapted from example by Andrew Belt +// by Andrew Belt +// adapted for SC by Brian Heim // Call process() every 256 audio samples ~vcv_frameDivider = 256; diff --git a/examples/vco.scd b/examples/vco.scd new file mode 100644 index 0000000..219c27a --- /dev/null +++ b/examples/vco.scd @@ -0,0 +1,37 @@ +// Voltage-controlled oscillator example +// by Andrew Belt +// adapted for SC by Brian Heim + +~vcv_frameDivider = 1; +~vcv_bufferSize = 32; + +~phase = 0; +~vcv_process = { |block| + + var pitch, freq, deltaPhase; + + // Knob ranges from -5 to 5 octaves + pitch = block.knobs[0] * 10 - 5; + // Input follows 1V/oct standard + // Take the first input's first buffer value + pitch = pitch + block.inputs[0][0]; + + // The relationship between 1V/oct pitch and frequency is `freq = 2^pitch`. + // Default frequency is middle C (C4) in Hz. + // https://vcvrack.com/manual/VoltageStandards.html#pitch-and-frequencies + freq = 261.6256 * pow(2, pitch); + postf("Freq: % Hz", freq); + + deltaPhase = ~vcv_frameDivider * block.sampleTime * freq; + + // Set all samples in output buffer + block.bufferSize.do { |i| + // Accumulate phase & wrap around range [0, 1] + ~phase = (~phase + deltaPhase) % 1.0; + + // Convert phase to sine output + block.outputs[0][i] = sin(2pi * ~phase) * 5; + }; + + block +}