I have an ESP32-S3-WROOM on a custom PCB.
I'm retrieving a wav file (a song) from an SD card via SPI and playing it through DAC PCM5102A using I2S.
I am able to retrieve any wav file from the SD card and write the name of the file to the shell.
I am also able to play a generated tone with I2C through the DAC.
The problem is that after the wav file plays for a split second, it gets distorted.
I have an oscilloscope here, and have test points on BCLK, LRCK, and DOUT lines.
I've seen this issue reported in a few places, Reddit, Arduino forum and others, but no solution.
I'm working in microPython but if microPython is missing support for a needed parameter I can switch.
Setup
Code: Select all
i2s = I2S(
0, # I2S bus ID (use 0 or 1)
sck=Pin(35), # BCLK (Bit Clock)
ws=Pin(36), # LRCK (Word Select / Left-Right Clock)
sd=Pin(37), # DOUT (Data Out)
mode=I2S.TX, # Transmit mode
bits=16, # 16-bit audio
#bits=32, # 32-bit audio
#format=I2S.STEREO,
format=I2S.MONO,
rate=44100, # Standard audio rate (adjust as needed)
#rate=22500,
ibuf=100000 # Buffer size
)Code: Select all
def play_specific_sound():
file_path = "/sd/final_pump_clip.wav"
#if file_path not in os.listdir("/sd"):
if "final_pump_clip.wav" not in os.listdir("/sd"):
print("File not found:", file_path)
return
print("Playing:", file_path)
with open(file_path, "rb") as f:
f.read(44) # Skip WAV header
while True:
audio_data = f.read(128) # Read in chunks
if not audio_data:
break
i2s.write(audio_data) # Send to DAC
# Convert 16-bit PCM to properly aligned I2S 16-bit format
print("Playback finished")