change piano sample

This commit is contained in:
Siwat Sirichai 2022-04-09 23:20:02 +07:00
parent 5e7a923c3a
commit 3c96a3f3ad
28 changed files with 29 additions and 12 deletions

View File

@ -1,26 +1,26 @@
from time import sleep
from telemetrix_rpi_pico import telemetrix_rpi_pico
from siwatlib.debounce import debounce
from siwatlib.sound import beep
from siwatlib.sound import piano_key
import winsound
index_shift = 2
freqs = [261.6256,293.6648,329.6276,349.2282,391.9954,440.0000,493.8833,523.2511]
debouncers = []
def handle_button_press(data):
freq = freqs[data[1]-index_shift]
print(freq)
recieved_state = not data[2]
if debouncers[data[1]-index_shift].set_state(state=recieved_state):
beep(frequency=freq,duration=0.25)
try:
print(str(data[1])+' Pressed')
recieved_state = not data[2]
if debouncers[data[1]-index_shift].set_state(state=recieved_state):
piano_key((data[1]-1)*2-1)
except KeyError:
pass
mcu = telemetrix_rpi_pico.TelemetrixRpiPico(com_port='COM10')
for i in range(2,10):
debouncers.append(debounce(state=False,debounce_time=0.15))
debouncers.append(debounce(state=False,debounce_time=0.2))
mcu.set_pin_mode_digital_input(i,callback=handle_button_press)
while True:
sleep(100)

View File

@ -1 +1,2 @@
telemetrix-rpi-pico
playsound==1.2.2

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,6 +1,8 @@
from pysine import pysine
import winsound
import threading
from playsound import playsound
import os
MODE = 'pysine'
@ -24,4 +26,16 @@ def beep(frequency: float, duration: float):
)
__beeper__.start()
#TODO Tune the piano
def __piano_key_thread__(note: str):
note = format(note,'02')
soundfile = os.path.dirname(__file__)+'\\piano_sample\\key'+note+'.mp3'
print(soundfile)
playsound(soundfile)
def piano_key(note: str):
threading.Thread(target=__piano_key_thread__,
kwargs={'note': note}
).start()

2
test.py Normal file
View File

@ -0,0 +1,2 @@
from siwatlib.sound import piano_key
piano_key(4)