Skip to content

RP2040: audiobusio.I2SOut: on playing wav from file: i2s.playing False too early and random #4271

@dglaude

Description

@dglaude

Testing I2SOut on pico + "pico base" with 6.2.0-beta.2-154-gd4bf0d5e2

("pico base" use PCM5100A DAC for line out audio over I2S, just like in Raspberry Pi reverence design)

Playing "StreetChicken.wav" from flash on I2S, the file and code inspiration come from the learn guide: https://learn.adafruit.com/adafruit-i2s-stereo-decoder-uda1334a/circuitpython-wiring-test

The sound is metalic (randomly, sometime it is good) and i2s.playing return False "randomly" long before the end of the sound file.

Code:

import board
import audiocore
import audiobusio
import time

print("Playing 10 times StreetChicken.wav")

f = open("StreetChicken.wav", "rb")
wav = audiocore.WaveFile(f)
i2s = audiobusio.I2SOut(board.GP27, board.GP28, board.GP26)

for i in range(10):
    start=time.monotonic()
    i2s.play(wav)
    while i2s.playing:
        pass
    stop = time.monotonic()
    print("Total lenght = ", stop, "-", start, "=", stop-start)

Expected result:

Perfect sound, the wave file should play 10 times and last more or less exactly the same length.

Effective result:

The sound is unperfect (metalic scratch) and the timing is random

Playing 10 times StreetChicken.wav
Total lenght = 972.984 - 972.949 = 0.0349121
Total lenght = 973.148 - 972.985 = 0.163086
Total lenght = 974.415 - 973.149 = 1.26587
Total lenght = 974.985 - 974.416 = 0.568848
Total lenght = 976.125 - 974.987 = 1.13818
Total lenght = 980.144 - 976.126 = 4.01782
Total lenght = 981.144 - 980.145 = 0.998779
Total lenght = 981.947 - 981.145 = 0.802002
Total lenght = 983.191 - 981.948 = 1.24292
Total lenght = 983.877 - 983.192 = 0.685059

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions