2323import analogio , keypad
2424import audiobusio , audiomixer , synthio
2525import ulab .numpy as np
26- import displayio , terminalio
26+ import i2cdisplaybus , displayio , terminalio
2727import adafruit_displayio_ssd1306
2828from adafruit_display_text import bitmap_label as label
2929import touchio
3434midi_notes = list (range (45 ,45 + 16 ))
3535filter_freq = 4000
3636filter_resonance = 1.2
37- output_volume = 0.75 # turn down the volume a bit since this can get loud
37+ output_volume = 1.0
3838
3939# pin definitions
4040sw_pin = board .GP28
6767for pin in touch_pins :
6868 print ("touch pin:" , pin )
6969 touchin = touchio .TouchIn (pin )
70- touchin .threshold = int (touchin .threshold * 1.05 )
70+ touchin .threshold = int (touchin .threshold * 1.1 )
7171 touchins .append (touchin )
7272 touchs .append (Debouncer (touchin ))
7373
74-
74+ print ( "starting up..." )
7575midi_in_usb = usb_midi .ports [0 ]
7676midi_in_uart = busio .UART (rx = uart_rx_pin , tx = uart_tx_pin , baudrate = 31250 , timeout = 0.001 )
7777i2c = busio .I2C (scl = i2c_scl_pin , sda = i2c_sda_pin , frequency = 1_000_000 )
7878
7979dw ,dh = 128 , 64
80- display_bus = displayio . I2CDisplay (i2c , device_address = 0x3c )
80+ display_bus = i2cdisplaybus . I2CDisplayBus (i2c , device_address = 0x3c )
8181display = adafruit_displayio_ssd1306 .SSD1306 (display_bus , width = dw , height = dh , rotation = 180 )
8282
8383# set up the synth->audio system
9898
9999# set up info to be displayed
100100maingroup = displayio .Group ()
101- display .show ( maingroup )
101+ display .root_group = maingroup
102102text1 = label .Label (terminalio .FONT , text = "pico_test_synth" , x = 0 , y = 10 )
103103text2 = label .Label (terminalio .FONT , text = "@todbot" , x = 0 , y = 25 )
104104text3 = label .Label (terminalio .FONT , text = "pico_test_synth!" , x = 0 , y = 50 )
@@ -116,13 +116,14 @@ def check_touch():
116116 if touch .rose :
117117 print ("touch press" ,i )
118118 f = synthio .midi_to_hz (midi_notes [i ])
119- filter = synth . low_pass_filter ( filter_freq , filter_resonance )
120- n = synthio .Note ( frequency = f , waveform = wave_saw , filter = filter )
119+ filter = synthio . Biquad ( synthio . FilterMode . LOW_PASS , filter_freq , filter_resonance )
120+ n = synthio .Note (frequency = f , waveform = wave_saw , filter = filter , amplitude = 0.75 )
121121 synth .press ( n )
122122 touch_notes [i ] = n
123123 if touch .fell :
124124 print ("touch release" , i )
125- synth .release ( touch_notes [i ] )
125+ if touch_notes [i ]:
126+ synth .release ( touch_notes [i ] )
126127
127128async def debug_printer ():
128129 t1_last = ""
@@ -153,8 +154,9 @@ async def input_handler():
153154
154155 for n in touch_notes : # real-time adjustment of filter
155156 if n :
156- n .filter = synth .low_pass_filter (filter_freq , filter_resonance )
157-
157+ n .filter .frequency = filter_freq
158+ n .filter .Q = filter_resonance
159+
158160 check_touch ()
159161
160162 if key := keys .events .get ():
@@ -164,7 +166,7 @@ async def input_handler():
164166 if key .pressed :
165167 sw_pressed = True
166168 f = synthio .midi_to_hz (random .randint (32 ,60 ))
167- note = synthio .Note (frequency = f , waveform = wave_saw ) # , filter=filter )
169+ note = synthio .Note (frequency = f , waveform = wave_saw , amplitude = 0.8 )
168170 synth .press (note )
169171 await asyncio .sleep (0.001 )
170172
0 commit comments