0

Grand Central play audio from SD
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Grand Central play audio from SD

by bebo on Sun Apr 14, 2019 4:13 pm

I'm using the UDA1334 breakout with the Grand Central to play audio files using this script.
Code: Select all | TOGGLE FULL SIZE
import time
import array
import math
import audioio
import board
import audiobusio
import busio, storage, os, adafruit_sdcard, digitalio

spi = busio.SPI(board.SD_SCK, board.SD_MOSI, board.SD_MISO)
cs = digitalio.DigitalInOut(board.SD_CS)
sd = adafruit_sdcard.SDCard(spi, cs)
vfs = storage.VfsFat(sd)
storage.mount(vfs, '/sd')

with open('/sd/sweetiepie.wav', 'rb') as sound:
    sfx = audioio.WaveFile(sound)


# For Grand Central M4

    audio = audiobusio.I2SOut(board.D14, board.D33, board.D32)

    while True:
        audio.play(sfx)
        while audio.playing:
            pass


I've tried it with the wav file stored in the root directory of CIRCUITPY ( using < with open('sweetiepie.wav', 'rb') as sound:>) and it works great.
However when I try to use the same wav file stored on the SD card, it plays back with significant distortion and at about 80% speed.
Is there a way to read and play wav files directly from the SD card?

bebo
 
Posts: 85
Joined: Tue Mar 29, 2011 8:22 am

Re: Grand Central play audio from SD

by adafruit_support_mike on Sun Apr 14, 2019 11:58 pm

That will probably be latency and bitrate issues related to the SD card.

The onboard QPSI Flash chip has four data lines, but the SD card's SPI connection only has one. That makes the Flash at least 4x faster than the SD card. The problems you're hacing, especially the reduced speed, are characteristic of a data connection that just isn't fast enough.

You can reduce the communication load by changing the encoding settings for the track you want to play. Dropping from 24-bit audio to 8-bit will give you a 3x reduction in data, and probably won't have much effect on the quality of the output.

adafruit_support_mike
 
Posts: 57479
Joined: Thu Feb 11, 2010 2:51 pm

Re: Grand Central play audio from SD

by bebo on Mon Apr 15, 2019 3:11 pm

I'll have to try that. Thanks for the advice.

bebo
 
Posts: 85
Joined: Tue Mar 29, 2011 8:22 am

Please be positive and constructive with your questions and comments.