Grand Central play audio from SD

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
bebo
 
Posts: 96
Joined: Tue Mar 29, 2011 8:22 am

Grand Central play audio from SD

Post by bebo »

I'm using the UDA1334 breakout with the Grand Central to play audio files using this script.

Code: Select all

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?

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: Grand Central play audio from SD

Post by adafruit_support_mike »

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.

User avatar
bebo
 
Posts: 96
Joined: Tue Mar 29, 2011 8:22 am

Re: Grand Central play audio from SD

Post by bebo »

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

Locked
Please be positive and constructive with your questions and comments.

Return to “Metro, Metro Express, and Grand Central Boards”