Black Lives Matter - Action and Equality. ... Adafruit is part of the Stop Hate for Profit campaign. Adafruit is open and shipping.
0

wav files distortion on Music Maker
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

wav files distortion on Music Maker

by ssherk27 on Fri Dec 04, 2015 4:16 pm

I am getting very bad audio from .wav files on the Music Maker shield. I am using an UNO and 16bit 44.1 wav files (16bit <= 48K supported). They sound slowed down and extremely distorted. I reformatted my SD cards, no difference. I have two Music Maker shields and two UNO, and the problem is identical with both. I have been using the simple music player demo. Everything sounds fine when I substititue MP3's back in.

ssherk27
 
Posts: 8
Joined: Thu Aug 27, 2009 11:26 am

Re: wav files distortion on Music Maker

by ssherk27 on Mon Dec 07, 2015 12:58 pm

I have now discovered that my Music Players will only play 8-bit .wav files! Any 16-bit 44.1kH file plays with awful crunching distortion and slowly. The datasheet does say that it should play 16-bit. Has anyone had success with 16-bit 44.1 .wav files? Am I missing something? Both of my shield and boards do fine with .mp3 and 8-bit plays cleanly, too.


In case I am making some very stupid beginner mistake here is the simple code that I am using.
Thanks for any guidance.

Code: Select all | TOGGLE FULL SIZE
/***************************************************
  This is an example for the Adafruit VS1053 Codec Breakout

  Designed specifically to work with the Adafruit VS1053 Codec Breakout
  ----> https://www.adafruit.com/products/1381

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries. 
  BSD license, all text above must be included in any redistribution
 ****************************************************/

// include SPI, MP3 and SD libraries
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>

// define the pins used
//#define CLK 13       // SPI Clock, shared with SD card
//#define MISO 12      // Input data, from VS1053/SD card
//#define MOSI 11      // Output data, to VS1053/SD card
// Connect CLK, MISO and MOSI to hardware SPI pins.
// See http://arduino.cc/en/Reference/SPI "Connections"

// These are the pins used for the breakout example
#define BREAKOUT_RESET  9      // VS1053 reset pin (output)
#define BREAKOUT_CS     10     // VS1053 chip select pin (output)
#define BREAKOUT_DCS    8      // VS1053 Data/command select pin (output)
// These are the pins used for the music maker shield
#define SHIELD_RESET  -1      // VS1053 reset pin (unused!)
#define SHIELD_CS     7      // VS1053 chip select pin (output)
#define SHIELD_DCS    6      // VS1053 Data/command select pin (output)

// These are common pins between breakout and shield
#define CARDCS 4     // Card chip select pin
// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
#define DREQ 3       // VS1053 Data request, ideally an Interrupt pin

Adafruit_VS1053_FilePlayer musicPlayer = // I think that this names the thing as musicPlayer
  // create breakout-example object!
 // Adafruit_VS1053_FilePlayer(BREAKOUT_RESET, BREAKOUT_CS, BREAKOUT_DCS, DREQ, CARDCS);
  // create shield-example object!
 Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS); // these are all variables state above
 
void setup() {
  Serial.begin(9600);
  Serial.println("Adafruit VS1053 Simple Test");

  if (! musicPlayer.begin()) { // initialise the music player (but it is asking if musicPlayer is not beginning!)
     Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
     while (1);
  }
  Serial.println(F("VS1053 found"));  // so it seems that the musicPlayer initializes when shield is booted
 
  SD.begin(CARDCS);    // initialise the SD card
 
  // Set volume for left, right channels. lower numbers == louder volume!
  musicPlayer.setVolume(20,20);

  // Timer interrupts are not suggested, better to use DREQ interrupt!
  //musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT); // timer int

  // If DREQ is on an interrupt pin (on uno, #2 or #3) we can do background
  // audio playing
 `   musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT);  // DREQ int 
 
  // Play one file, don't return until complete
 
}

void loop() {
   Serial.println(F("Playing track 001"));
   musicPlayer.playFullFile("track001.wav");
 

  delay(100);
}

ssherk27
 
Posts: 8
Joined: Thu Aug 27, 2009 11:26 am

Re: wav files distortion on Music Maker

by adafruit_support_mike on Mon Dec 07, 2015 9:18 pm

You're probably running into the limits of the microcontroller's communication speed.

The minimum bit rate necessary to support 16-bit stereo at 44.1kHz is a bit higher than 1.4Mbps. For a Music Maker, the microcontroller has to pass all the data twice: once reading it from the SD card and once writing it to the VS1053. That would put the bitrate at about 2.8Mbps.

The ATmega328's maximum SPI rate is half the system clock, or 8MHz for a 16MHz Arduino. You'd have to code pretty tightly to get that kind of throughput. The existing library isn't that fast.

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

Re: wav files distortion on Music Maker

by ssherk27 on Tue Dec 08, 2015 5:00 pm

Thanks. How about the Arduino Zero with a clock speed of 48Mhz? What is the minimum requirement for clock rate for 16 bit 44.1 .wav? (I'm not clear on how to estimate the relationship of bit rate to half the system clock.)

ssherk27
 
Posts: 8
Joined: Thu Aug 27, 2009 11:26 am

Re: wav files distortion on Music Maker

by adafruit_support_mike on Thu Dec 10, 2015 3:26 am

It depends on how much other code is running while you're trying to read and write data through the SPI bus.

A Zero's 48MHz clock should be fast enough to handle all the extra processing, but I haven't tested that library with that board, so I'm not sure whether the code would work.

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

Please be positive and constructive with your questions and comments.