Last active
February 14, 2024 03:55
-
-
Save vinc6/ff2a87ce0e8bdbbfff622c2b49d82c80 to your computer and use it in GitHub Desktop.
script for frequency tracker and such
This file contains 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
--- pitch quantizer | |
-- vinc 240211 | |
-- in1: freq | |
-- in2: amp | |
-- out1: pitch quantized sine osc | |
-- out2: pitch quantized cv | |
-- out3: trig | |
-- out4: amp env follower | |
lasf_f = 0 | |
function quantizer(hz) | |
table.sort(f_chart, | |
function(n1, n2) | |
return math.abs(hz - n1) < math.abs(hz - n2) | |
end | |
) | |
quantized_f = f_chart[1] | |
table.sort(f_chart) | |
coroutine.resume(freq_co, quantized_f) | |
end | |
freq_co = coroutine.create( | |
function() | |
while true do | |
if quantized_f ~= last_f then | |
output[1]( oscillate(quantized_f) ) | |
output[2].volts = hztovolts(quantized_f) | |
output[3]( pulse() ) | |
ii.wsyn[ math.srandom(1,2) ].play_note(output[2].volts, output[4].volts) | |
last_f = quantized_f | |
print(quantized_f) | |
end | |
coroutine.yield(freq_co) | |
end | |
end | |
) | |
function init() | |
f_chart = {} | |
for i = 1, 88 do | |
f_chart[i] = 27.5*2^( (i-1)/12 ) | |
print(#f_chart, f_chart[i]) | |
end | |
input[1]{ mode = 'freq' | |
, time = 0.1 | |
, freq = quantizer | |
} | |
input[2]{ mode = 'volume' | |
, time = 0.05 | |
, volume = function(vol) | |
output[4].volts = vol | |
end | |
} | |
output[2].shape = 'linear' | |
output[2].slew = 0.005 | |
output[4].shape = 'exponential' | |
output[4].slew = 0.05 | |
for n = 1, 2 do | |
ii.wsyn[n].ar_mode(1) | |
ii.wsyn[n].curve(4) | |
ii.wsyn[n].ramp(2.5) | |
ii.wsyn[n].fm_index(0) | |
ii.wsyn[n].fm_env(0) | |
ii.wsyn[n].fm_ratio(8/7) | |
ii.wsyn[n].lpg_time(-2.95) | |
ii.wsyn[n].lpg_symmetry(-4.65) | |
ii.wsyn[n].voices(4) | |
end | |
math.srandomseed( time() * unique_id() ) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment