Skip to content

Commit

Permalink
fine I will use displayio for hwtest
Browse files Browse the repository at this point in the history
  • Loading branch information
todbot committed Aug 11, 2023
1 parent 16de55f commit aa3524a
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions circuitpython/hwtest/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,20 @@
buffer_size=8192) # buffer_size=4096) # need a big buffer when screen updated
synth = synthio.Synthesizer(sample_rate=28000)
audio.play(mixer)
mixer.voice[0].level = 0.5 # turn down the volume a bit since this can get loud
mixer.voice[0].level = 0.75 # turn down the volume a bit since this can get loud
mixer.voice[0].play(synth)

wave_saw = np.linspace(30000,-30000, num=256, dtype=np.int16) # default squ is too clippy
amp_env = synthio.Envelope(sustain_level=0.8, release_time=0.4, attack_time=0.001)
synth.envelope = amp_env

# maingroup = displayio.Group()
# display.show(maingroup)
# text1 = label.Label(terminalio.FONT, text="hello\nworld...", line_spacing=0.75, x=5,y=dh//4,scale=1)
# text2 = label.Label(terminalio.FONT, text="@todbot", line_spacing=0.75, x=dw//2, y=dh-15, scale=1)
# maingroup.append(text1)
# maingroup.append(text2)
maingroup = displayio.Group()
display.show(maingroup)
text1 = label.Label(terminalio.FONT, text="helloworld...", x=0, y=10)
text2 = label.Label(terminalio.FONT, text="@todbot", x=0, y=25)
text3 = label.Label(terminalio.FONT, text="hwtest. press!", x=0, y=50)
for t in (text1, text2, text3):
maingroup.append(t)

midi_notes = (33, 45, 52, 57)
touch_notes = [None] * 4
Expand All @@ -69,24 +70,25 @@ def check_touch():
touch = touchs[i]
touch.update()
if touch.rose:
#print("touch press",i)
print("touch press",i)
f = synthio.midi_to_hz(midi_notes[i])
filter = synth.low_pass_filter(filter_freq, filter_resonance)
n = synthio.Note( frequency=f, waveform=wave_saw, filter=filter )
synth.press( n )
touch_notes[i] = n
if touch.fell:
#print("touch release", i)
print("touch release", i)
synth.release( touch_notes[i] )

note = synthio.Note(frequency=0)
#note = synthio.Note(frequency=0)
sw_pressed = False

async def debug_printer():
while True:
print("K:%3d %3d S:%d" % (knobA.value//255, knobB.value//255, sw_pressed) )
print("T", touchins[0].raw_value//16, touchins[1].raw_value//16, touchins[2].raw_value//16, touchins[3].raw_value//16)
print()
text1.text = "K:%3d %3d S:%d" % (knobA.value//255, knobB.value//255, sw_pressed)
text2.text = "T:" + ''.join(["%3d " % v for v in (touchins[0].raw_value//16, touchins[1].raw_value//16, touchins[2].raw_value//16, touchins[3].raw_value//16)])
print(text1.text)
print(text2.text)
await asyncio.sleep(0.3)

async def input_handler():
Expand All @@ -97,7 +99,11 @@ async def input_handler():

while True:
filter_freq = knobA.value/65535 * 8000 + 100 # range 100-8100
filter_resonance = knobB.value/65535 * 3 + 0 # range 0-3
filter_resonance = knobB.value/65535 * 3 + 0.2 # range 0.2-3.2

for n in touch_notes: # real-time adjustment of filter
if n:
n.filter = synth.low_pass_filter(filter_freq, filter_resonance)

check_touch()

Expand All @@ -108,8 +114,7 @@ async def input_handler():
if key.pressed:
sw_pressed = True
f = synthio.midi_to_hz(random.randint(32,60))
filter = synth.low_pass_filter(filter_freq, filter_resonance)
note = synthio.Note(frequency=f, waveform=wave_saw, filter=filter)
note = synthio.Note(frequency=f, waveform=wave_saw) # , filter=filter)
synth.press(note)
await asyncio.sleep(0.01)

Expand Down

0 comments on commit aa3524a

Please sign in to comment.