Skip to content

Instantly share code, notes, and snippets.

@trentgill
Created May 14, 2020 22:59
Show Gist options
  • Save trentgill/a5a0dce99cd0e6e2ec5131571d52c212 to your computer and use it in GitHub Desktop.
Save trentgill/a5a0dce99cd0e6e2ec5131571d52c212 to your computer and use it in GitHub Desktop.
--- subharmonic pitch source
magic = 1/math.log(2)
function init()
output[1].volts = 0
metro[1].time = 1.0
metro[1].event = next_step
metro[1]:start()
--input[1].mode( 'stream', 0.002)
metro[2].time = 0.002
metro[2].event = bang_outputs
metro[2]:start()
end
-- 0, -12, -19, -24, -28, -31, -33.5, -36
function just_volts( f )
return math.log(f) * magic
end
-- sequence of pairs of ratios
seq =
{ { 1,1 }
, { 5,4 }
, { 8,7 }
, { 11,8 }
, { 3,2 }
, { 2,1 }
}
seqIX = 1
-- TODO independent sequences for otone & utone
overtone = 1
undertone = 1
function next_step()
--output[1].volts = just_volts( 1/undertone )
--undertone = undertone + 1
overtone = seq[seqIX][1]
undertone = seq[seqIX][2]
print( overtone.."/".. undertone )
seqIX = (seqIX % #seq) + 1 -- increment our index, and wrap to #seq
end
slew = {0.01,0.01}
function process_v(v,index)
--slew
local _input = v
local old = slew[index]
local rate = 0.005 -- sets the slew rate (0..1)
local _output = old + rate * (_input - old) -- linear interpolation
slew[index] = _output
--quantize to integers
_output = math.floor(_output)
return _output
end
function bang_outputs()
output[1].volts = just_volts( process_v( overtone,1)/ process_v( undertone,2 ))
end
--- using the inputs to control numerator & denomenator directly
--slew = {0,0}
--function process_v(v,index)
-- v = 1 + (v+5)*1.3 -- convert (-5..5) into (1..14)
-- --v = math.floor(v)
--
-- local _input = v
-- local old = slew[index]
-- local rate = 0.02 -- sets the slew rate (0..1)
-- local _output = old + rate * (_input - old) -- linear interpolation
-- slew[index] = _output
--
-- _output = math.floor(_output)
--
-- return _output
--end
--
--input[1].stream = function(v)
-- local overtone = process_v( input[2].volts,1 )
-- output[1].volts = just_volts( overtone/process_v(v,2) )
--
--end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment