-
Notifications
You must be signed in to change notification settings - Fork 2
Description
This might ultimately be a displayio/core issue, or some combination of those and audiobusio rather than something specific to this library, but this is where I've noticed first it and created a reproducer.
Refreshing the display seems to cause static if it's done during the while audio.playing
loop. This code illustrates the issue:
It uses this bmp: https://github.com/FoamyGuy/Adafruit_CircuitPython_FruitJam_Animation/blob/main/f_spritesheet.bmp
And this wav file: https://cdn-learn.adafruit.com/assets/assets/000/057/463/original/StreetChicken.wav?1531255658
import adafruit_imageload
import adafruit_ticks
import board
from audiocore import WaveFile
import audiobusio
import adafruit_tlv320
import supervisor
from displayio import Group, TileGrid
display = supervisor.runtime.display
display.auto_refresh = False
i2c = board.I2C()
dac = adafruit_tlv320.TLV320DAC3100(i2c)
dac.configure_clocks(sample_rate=22050, bit_depth=16)
dac.headphone_output = True
dac.headphone_volume = -60 # dB
wave_file = open("StreetChicken.wav", "rb")
wave = WaveFile(wave_file)
audio = audiobusio.I2SOut(board.I2S_BCLK, board.I2S_WS, board.I2S_DIN)
main_group = Group()
display.root_group = main_group
bmp, palette = adafruit_imageload.load("f_spritesheet.bmp")
tgs = []
for i in range(5):
tgs.append(TileGrid(bitmap=bmp, pixel_shader=palette, tile_width=32, tile_height=39))
tgs[-1].y = 42 * i
main_group.append(tgs[-1])
index_count = bmp.width // tgs[0].tile_width
interval = 1/30
last_update = adafruit_ticks.ticks_ms() / 1000
cur_x = 0
while True:
audio.play(wave)
while audio.playing:
now = adafruit_ticks.ticks_ms() / 1000
if last_update + interval < now:
last_update = now
cur_x = (cur_x + 1) % 200
for tg in tgs:
tg.x = cur_x
tg[0] = (tg[0] + 1) % index_count
display.refresh()
print("Done!")
The amount of static and interference seems correlated to how many pixels on the display need updated. If all of the code making visually changes is commented out the sound plays clearly. If the number of TileGrids is lowered by using something smaller than 5 in for i in range(5):
the interference lessens, I don't notice any issues with 1 or 2 TileGrids, I can start to hear some with 3, and by 4 and 5 the interference is very apparent.
Testing performed on:
Adafruit CircuitPython 9.2.5 on 2025-03-19; Adafruit Fruit Jam with rp2350b