Skip to content

Instantly share code, notes, and snippets.

@trentgill
Created May 14, 2020 22:59
Show Gist options
  • Save trentgill/20ec5f560525b757d7b6b7229f05a1b8 to your computer and use it in GitHub Desktop.
Save trentgill/20ec5f560525b757d7b6b7229f05a1b8 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()
metro[3].time = 0.666
metro[3].event = nextnext_step
metro[3]: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
otone = { 1,5,7,3 }
utone = { 1,4,2,6,3 }
otoneIX = 1
utoneIX = 1
-- TODO independent sequences for otone & utone
overtone = 1
undertone = 1
function next_step()
overtone = otone[otoneIX]
print( overtone.."/".. undertone )
otoneIX = (otoneIX % #otone) + 1 -- increment our index, and wrap to #seq
end
function nextnext_step()
undertone = utone[utoneIX]
print( overtone.."/".. undertone )
utoneIX = (utoneIX % #utone) + 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 rate = 0.02 -- 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