Browse Source

Reverts changes in the Lua examples to use the original 1-based index

tags/v1.3.0
Leonardo Laguna Ruiz Andrew Belt 5 years ago
parent
commit
4caf611d2d
3 changed files with 12 additions and 12 deletions
  1. +5
    -5
      examples/gain.lua
  2. +3
    -3
      examples/rainbow.lua
  3. +4
    -4
      examples/vco.lua

+ 5
- 5
examples/gain.lua View File

@@ -6,23 +6,23 @@ config.bufferSize = 32

function process(block)
-- Loop through each column
for i=0,5 do
for i=1,6 do
-- Get gain knob
gain = block.knobs[i]
-- Set gain light (red = 1)
block.lights[i][0] = gain
block.lights[i][1] = gain
-- Check mute switch
if block.switches[i] then
-- Mute output
gain = 0
-- Enable mute light (red = 1)
block.switchLights[i][0] = 1
block.switchLights[i][1] = 1
else
-- Disable mute light
block.switchLights[i][0] = 0
block.switchLights[i][1] = 0
end
-- Iterate input/output buffer
for j=0,block.bufferSize-1 do
for j=1,block.bufferSize do
-- Get input
x = block.inputs[i][j]
-- Apply gain to input


+ 3
- 3
examples/rainbow.lua View File

@@ -34,10 +34,10 @@ function process(block)
h = (1 - i / 6 + phase) % 1
rgb = hsvToRgb(h, 1, 1)
for c=1,3 do
block.lights[i-1][c-1] = rgb[c]
block.switchLights[i-1][c-1] = rgb[c]
block.lights[i][c] = rgb[c]
block.switchLights[i][c] = rgb[c]
end
block.outputs[i-1][0] = math.sin(2 * math.pi * h) * 5 + 5
block.outputs[i][1] = math.sin(2 * math.pi * h) * 5 + 5
end
end



+ 4
- 4
examples/vco.lua View File

@@ -9,10 +9,10 @@ config.bufferSize = 16
phase = 0
function process(block)
-- Knob ranges from -5 to 5 octaves
pitch = block.knobs[0] * 10 - 5
pitch = block.knobs[1] * 10 - 5
-- Input follows 1V/oct standard
-- Take the first input's first buffer value
pitch = pitch + block.inputs[0][0]
pitch = pitch + block.inputs[1][1]

-- The relationship between 1V/oct pitch and frequency is `freq = 2^pitch`.
-- Default frequency is middle C (C4) in Hz.
@@ -22,13 +22,13 @@ function process(block)

-- Set all samples in output buffer
deltaPhase = config.frameDivider * block.sampleTime * freq
for i=0,block.bufferSize-1 do
for i=1,block.bufferSize do
-- Accumulate phase
phase = phase + deltaPhase
-- Wrap phase around range [0, 1]
phase = phase % 1

-- Convert phase to sine output
block.outputs[0][i] = math.sin(2 * math.pi * phase) * 5
block.outputs[1][i] = math.sin(2 * math.pi * phase) * 5
end
end

Loading…
Cancel
Save