circuitpython/tests/testlib/synthblockhelper.py

30 lines
844 B
Python
Raw Normal View History

import array
from math import sin, pi
from synthio import LFO, MathOperation, lfo_tick
bend_out = array.array("h", [0, 32767])
bend_in = array.array("h", [32767, 0])
sweep = array.array("h", [-32767, 32767])
triangle = array.array("h", [0, 32767, 0, -32767])
sine = array.array("h", [int(32767 * sin(i * 2 * pi / 600)) for i in range(600)])
def print_result(*blocks):
for i in range(48000 / 256):
print(*lfo_tick(*blocks))
def mathop_test(kind):
v = LFO(sweep, rate=1, scale=2, once=True)
varying_a = kind(v, 2, -3)
varying_b = kind(-3, v, 2)
varying_c = kind(2, -3, v)
print_result(v, varying_a, varying_b, varying_c)
def lfo_test(sweep_input_name, **inputs):
sweep = LFO(sweep, rate=1, scale=2)
test = LFO(sine, **inputs)
setattr(test, sweep_input_name, sweep)
print_result(sweep, test)