def playfile(filename): wave_file = open("/sounds/" + filename, "rb") with WaveFile(wave_file) as wave: with AudioOut(board.SPEAKER) as audio: audio.play(wave) while audio.playing: brightPulse() cp.pixels.fill(BLACK)
def playfile(filename): wave_file = open(filename, "rb") with WaveFile(wave_file) as wave: with AudioOut(board.SPEAKER) as audio: audio.play(wave) moveUp() while audio.playing: move() moveBack()
### AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ### LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ### OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ### SOFTWARE. import time import random from board import * from digitalio import DigitalInOut, Direction from audiopwmio import PWMAudioOut as AudioOut from audiocore import WaveFile ### Maker Pi Pico has small speaker (left channel) on GP18 audio_out = AudioOut(GP18) ### Audio is part of tack00's https://freesound.org/people/tack00/sounds/399257/ DRIP_FILENAME = "one-drip-16k.wav" try: drip = WaveFile(open(DRIP_FILENAME, "rb")) except OSError: print("Missing audio file:", DRIP_FILENAME) drip = None animation_step = 0.1 ### tenth of a second ### Each "frame" in animation is either a list of pins ### to illuminate or a sound sample to start playing animation = [[GP0], [GP0], [GP0], [GP0],
pixels.fill(BLACK) pixels.show() # Debouncer ------------------------------------------------------ buttons = [Debouncer(mpr121[i]) for i in range(12)] # Audio Setup ------------------------------------------------------ spkr_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE) spkr_enable.direction = digitalio.Direction.OUTPUT spkr_enable.value = True audio = AudioOut(board.SPEAKER) tracks = ( WaveFile(open("sounds/F2.wav", "rb")), # 0 WaveFile(open("sounds/G2.wav", "rb")), # 1 WaveFile(open("sounds/A2.wav", "rb")), # 2 WaveFile(open("sounds/Bb2.wav", "rb")), # 3 WaveFile(open("sounds/C2.wav", "rb")), # 4 WaveFile(open("sounds/D3.wav", "rb")), # 5 WaveFile(open("sounds/E3.wav", "rb")), # 6 WaveFile(open("sounds/F3.wav", "rb")), # 7 WaveFile(open("sounds/F1.wav", "rb")), # 7 WaveFile(open("sounds/G1.wav", "rb")), # 8 WaveFile(open("sounds/A1.wav", "rb")), # 9 WaveFile(open("sounds/Bb1.wav", "rb")), # 10 WaveFile(open("sounds/C1.wav", "rb")), # 11
ringing = "songs/full_ring.wav" wrong_number = "songs/blank_number.wav" dial_tone = "songs/dial_tone_loop.wav" busy_signal = "songs/busy_loop.wav" button_tones = [ "dtmf/tt_1.wav", "dtmf/tt_2.wav", "dtmf/tt_3.wav", "dtmf/tt_4.wav", "dtmf/tt_5.wav", "dtmf/tt_6.wav", "dtmf/tt_7.wav", "dtmf/tt_8.wav", "dtmf/tt_9.wav", "dtmf/tt_star.wav", "dtmf/tt_0.wav", "dtmf/tt_pound.wav" ] digits_entered = 0 # counter dialed = [] # list of digits user enters to make one 7 digit number dialed_str = "" # stores the phone number string for dictionary comparison audio = AudioOut(board.TX) # PWM out pin mixer = audiomixer.Mixer( voice_count=4, sample_rate=22050, channel_count=1, bits_per_sample=16, samples_signed=True, ) audio.play(mixer) mixer.voice[0].level = 1.0 # dial tone voice mixer.voice[1].level = 1.0 # touch tone voice mixer.voice[2].level = 0.0 # song/message voice mixer.voice[3].level = 0.0 # busy signal wave_file0 = open(dial_tone, "rb") wave0 = WaveFile(wave_file0)
if (key & self._readKeyPress()) == key: keyPressed = True return keyPressed def bufferedKeyPress(self): if self.pin_datanotready.value: return self.last_key_press self.last_key_press = self._readKeyPress() return self.last_key_press piano = KitronikPiano(std_i2c, board.P1) audio = AudioOut(board.P0) ### P0 is klef speaker ### from 1.0 to 2.0 in equal temperament st_mult = [2**(st / 12) for st in range(12 + 1)] midpoint = 32768 vol = 32767 samples_per_waveform = 16 c_waves = 128 buffer_size = c_waves * samples_per_waveform twopi = 2 * math.pi a4_hz = 440 a4_st = 9 ### 9 st above C
# setup pixels pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=1, auto_write=True) # name colors so you don't need to refer to numbers RED = (255, 0, 0) ORANGE = (255, 50, 0) BLACK = (0, 0, 0) GREEN = (0, 255, 0) PURPLE = (100, 0, 255) YELLOW = (255, 230, 0) BLUE = (0, 0, 255) # setup bluetooth uart_server = UARTServer() # External Audio Stuff audio = AudioOut(board.SPEAKER) # Speaker wave_file = None def play_wav(name, loop=False): """ Play a WAV file in the 'sounds' directory. :param name: partial file name string, complete name will be built around this, e.g. passing 'foo' will play file 'sounds/foo.wav'. :param loop: if True, sound will repeat indefinitely (until interrupted by another sound). """ global wave_file # pylint: disable=global-statement print("playing", name) if wave_file: wave_file.close()
print(*args, **kwargs) AUDIO_DAUGHTERBOARD = False if AUDIO_DAUGHTERBOARD: ### Using pins presented on ESP-01 to talk to Feather nRF52840 adb_uart = busio.UART(board.GP16, board.GP17, baudrate=115200) scanner_left = 1 scanner_right = 2 PWMAUDIO_CLASH_PINS = () else: ### TODO - PIO PWM would be nice to avoid losing GP2 GP3 for audio AUDIO_PIN_L = board.GP18 AUDIO_PIN_R = board.GP19 audio_out = AudioOut(AUDIO_PIN_L, right_channel=AUDIO_PIN_R) left_file = open("scanner-left-16k.wav", "rb") right_file = open("scanner-right-16k.wav", "rb") ### This non pops a bit on 7.0.0-alpha.6 and after 10-100 minutes ### the audio stops and both audio pwm get stuck perhaps at ### a lowish duty cycle scanner_left = WaveFile(left_file) scanner_right = WaveFile(right_file) ### The use of GP18 also effectively reserves GP19 ### and the RP2040 hardware cannot then offer PWM on GP2 and GP3 ### PIO PWM could be a solution here when it works in CircuitPython PWMAUDIO_CLASH_PINS = (board.GP2, board.GP3, board.GP18, board.GP19)
wav_files = (('wav/amen_22k16b_160bpm.wav', 1.0), ('wav/dnb21580_22k16b_160bpm.wav', 0.9), ('wav/drumloopA_22k16b_160bpm.wav', 1.0), ('wav/femvoc_330662_22k16b_160bpm.wav', 0.8), ('wav/scratch3667_4bar_22k16b_160bpm.wav', 0.5), ('wav/pt_limor_modem_vox_01.wav', 0.4), ('wav/snowpeaks_22k_s16.wav', 0.8), ('wav/dnb21580_22k16b_160bpm_rev.wav', 1.0)) # pins used by keyboard KEY_PINS = (board.RX, board.D2, board.D3, board.D4, board.D5, board.D6, board.D7, board.D8) km = keypad.Keys(KEY_PINS, value_when_pressed=False, pull=True) audio = AudioOut(board.D10) # RP2040 PWM, use RC filter on breadboard mixer = audiomixer.Mixer(voice_count=len(wav_files), sample_rate=22050, channel_count=1, bits_per_sample=16, samples_signed=True) audio.play(mixer) # attach mixer to audio playback for i in range( len(wav_files)): # start all samples at once for use w handle_mixer wave = audiocore.WaveFile(open(wav_files[i][0], "rb")) mixer.voice[i].play(wave, loop=True) mixer.voice[i].level = 0 def handle_mixer(num, pressed):
### AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ### LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ### OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ### SOFTWARE. import time import random import board import digitalio from audiopwmio import PWMAudioOut as AudioOut from audiocore import WaveFile ### Maker Pi Pico has small speaker (left channel) on GP18 AUDIO_PIN = board.GP18 audio_out = AudioOut(AUDIO_PIN) ### Audio is part of tack00's https://freesound.org/people/tack00/sounds/399257/ DRIP_FILENAME = "one-drip-16k.wav" try: drip = WaveFile(open(DRIP_FILENAME, "rb")) except OSError: print("Missing audio file:", DRIP_FILENAME) drip = None ### Pins and vertical displacement left_pins = ( (board.GP0, 0), (board.GP1, 1), # gap (board.GP2, 3), (board.GP3, 4),
KEY_K5 = 0x2000 KEY_K6 = 0x4000 KEY_K7 = 0x8000 KEY_K8 = 0x01 KEY_K9 = 0x02 KEY_K10 = 0x04 KEY_K11 = 0x08 KEY_K12 = 0x10 KEY_K13 = 0x20 KEY_K14 = 0x40 keySensitivity = 8 keyNoiseThreshold = 5 keyRegValue = 0x0000 audio = AudioOut(board.P0) buff = bytearray(1) buff2 = bytearray(2) buff3 = bytearray(5) pin1 = digitalio.DigitalInOut(board.P1) pin1.pull = digitalio.Pull.UP pin1.direction = digitalio.Direction.INPUT # Startup procedure # Test /change pin is low, then test basic communication if (pin1.value==0): # Reads the chip ID, should be 0x11 (chip ID addr = 0) buff[0] = 0 while not i2c.try_lock(): pass i2c.writeto(CHIP_ADDRESS, buff)
infected() elif animation_num == 4: prophetsbane() elif animation_num == 5: vorpal() #-------------------- Bluefruit setup ble = BLERadio() uart_service = UARTService() advertisement = ProvideServicesAdvertisement(uart_service) scan_response = Advertisement() scan_response.complete_name = "Bad Ass Halo Energy Sword" #-------------------- Audio setup audio = AudioOut(board.A0) # Speaker wave_file = None def play_wav(name, loop=False): """ Play a WAV file in the 'sounds' directory. :param name: partial file name string, complete name will be built around this, e.g. passing 'foo' will play file 'sounds/foo.wav'. :param loop: if True, sound will repeat indefinitely (until interrupted by another sound). """ global wave_file # pylint: disable=global-statement if DEBUG == True: print("playing", name) if wave_file: