forked from micropython/micropython
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Description
Running this on 6.2.0-beta.3-11-g7970c882a on 2021-03-04 on a Pi Pico
import time
import math
import random
import struct
import board
import pwmio
import digitalio
from audiopwmio import PWMAudioOut as AudioOut
from audiocore import WaveFile
import rp2pio
import adafruit_pioasm
AUDIO_PIN_L = board.GP18
AUDIO_PIN_R = board.GP19
audio_out = AudioOut(AUDIO_PIN_L, right_channel=AUDIO_PIN_R)
stereo_file1 = open("scanner-left-16k.wav", "rb")
stereo_file2 = open("scanner-right-16k.wav", "rb")
buffer1 = bytearray(80 * 1024)
buffer2 = bytearray(80 * 1024)
sound_sample1 = WaveFile(stereo_file1, buffer1)
sound_sample2 = WaveFile(stereo_file2, buffer2)
def start_sound(sample):
if sample is not None:
audio_out.play(sample)
def wait_sound():
while audio_out.playing:
pass
print("SLEEP 12")
time.sleep(12)
pwm_gp4 = pwmio.PWMOut(board.GP4, frequency=7000, duty_cycle=0)
pwm_gp5 = pwmio.PWMOut(board.GP5, frequency=7000, duty_cycle=0)
pwm_gp6 = pwmio.PWMOut(board.GP6, frequency=7000, duty_cycle=0)
pwm_gp7 = pwmio.PWMOut(board.GP7, frequency=7000, duty_cycle=0)
pwm_gp8 = pwmio.PWMOut(board.GP8, frequency=7000, duty_cycle=0)
pwm_gp9 = pwmio.PWMOut(board.GP9, frequency=7000, duty_cycle=0)
pwm_gp10 = pwmio.PWMOut(board.GP10, frequency=7000, duty_cycle=0)
pwm_gp11 = pwmio.PWMOut(board.GP11, frequency=7000, duty_cycle=0)
pwm_gp12 = pwmio.PWMOut(board.GP12, frequency=7000, duty_cycle=0)
pwm_gp13 = pwmio.PWMOut(board.GP13, frequency=7000, duty_cycle=0)
pwm_gp14 = pwmio.PWMOut(board.GP14, frequency=7000, duty_cycle=0)
pwm_gp15 = pwmio.PWMOut(board.GP15, frequency=7000, duty_cycle=0)
pwm_gp16 = pwmio.PWMOut(board.GP16, frequency=7000, duty_cycle=0)
pwm_gp17 = pwmio.PWMOut(board.GP17, frequency=7000, duty_cycle=0)
print("CHECKING SUB", globals()["wait_sound"])
while True:
print("PLAY 1")
start_sound(sound_sample1)
print("WAIT 1")
wait_sound()
time.sleep(1)
print("PLAY 2")
start_sound(sound_sample2)
print("WAIT 2")
wait_sound()
time.sleep(1)
Gives this output:
Adafruit CircuitPython 6.2.0-beta.3-11-g7970c882a on 2021-03-04; Raspberry Pi Pico with rp2040
>>>
soft reboot
Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
SLEEP 12
CHECKING SUB <function wait_sound at 0x20006030>
PLAY 1
WAIT 1
Traceback (most recent call last):
File "code.py", line 60, in <module>
NameError: name 'wait_sound' is not defined
Code done running.
Press any key to enter the REPL. Use CTRL-D to reload.
Commenting out pwm_gp4 line magically fixes the problem but it's very unclear what's the actual cause of this.
The buffer sizes are unusually high. I was making them bigger than the wav file to try and fit the whole thing in memory.
This could relate to #4208. The nrf code has issues around buffers, see #3030
The wav files can be found in https://github.com/kevinjwalters/circuitpython-examples/tree/master/audio if you want to play with this.