MP3 shield click sound before playing audio files

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
dnear1
 
Posts: 16
Joined: Sun Sep 01, 2013 9:31 am

MP3 shield click sound before playing audio files

Post by dnear1 »

I have an VS1053 shield with wav files loaded on an SD card. This outputs to an Adafruit MAX9744 amplifier shield . When I play the audio files, there is a brief click before each file plays. If I play the audio files back to back in Windows Media Player, there isn't any click between files - it's perfectly smooth. Also, at random, the sound will become a loud "PSHHHHHHHWWWW" about the same length as the audio file that should be playing. After several sounds play, it will randomly resume to playing correctly.. The audio files are attached
I'm driving a 7-segment LED from a constant-current driver that matches the audio file being played. Excuse my code..

Code: Select all

/*************************************************** 
  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 can be any pins:
//#define RESET 9      // VS1053 reset pin (output)
//#define CS 10        // VS1053 chip select pin (output)
//#define DCS 8        // VS1053 Data/command select pin (output)
//#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
// above was original
// below is from kerns_JW on Adafruit  https://forums.adafruit.com/viewtopic.php?f=25&t=53543&p=270725#p270725
//Define MP3 Shield Setup
//#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
#define RESET 31 // VS1053 reset pin (output)
#define CS 30//7 // VS1053 chip select pin (output)
#define DCS 34//6 // VS1053 Data/command select pin (output)
#define DREQ 3 // VS1053 Data request pin (into Arduino)
#define CARDCS 32//4 // Card chip select pin
const int ledData = 44;//4;
const int ledClk=46;//5;
const int ledOe=5;//6;
const int ledLat=6;//7;

const int aseg=B10000000;
const int bseg=B1000000;
const int cseg=B100000;
const int dseg=B10000;
const int eseg=B1000;
const int fseg=B100;
const int gseg=B10;

char testdigit=0;
Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(RESET, CS, DCS, DREQ, CARDCS);

void setup() {
  pinMode(ledData,OUTPUT);
  pinMode(ledClk,OUTPUT);
  pinMode(ledOe,OUTPUT);
  pinMode(ledLat,OUTPUT);
  digitalWrite(ledOe,1);
  Serial.begin(9600);
  Serial.println("Adafruit VS1053 Simple Test");

  musicPlayer.begin(); // initialise the music player
  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
  musicPlayer.playFullFile("1.wav");
  delay(3000);
  musicPlayer.playFullFile("2.wav");
 //delay(3000);  musicPlayer.playFullFile("firstservice.output.wav");
 //delay(3000);  musicPlayer.playFullFile("goback.output.wav");
  // Play another file in the background, REQUIRES interrupts!
  //musicPlayer.startPlayingFile("track002.mp3");
}

void loop() {
  byte tempnumber;
  byte number;
  char filename[6]="1.wav";
  testdigit++;
  if(testdigit>9){
  testdigit=0;
  }
  digitalWrite(ledOe,1);
  number=0;
  for(tempnumber=0;tempnumber <testdigit;tempnumber ++)
  {
     number+=1<<tempnumber;
  }
  writeByte(maskDigit(testdigit));
  delayMicroseconds(1);
  digitalWrite(ledLat,1);
  delayMicroseconds(1);
  digitalWrite(ledLat,0);
 delayMicroseconds(1);
  digitalWrite(ledOe,0);
   // File is playing in the background
  if (musicPlayer.stopped()) {
    //delay(500);
filename[0]=testdigit + 48;//converts to ascii numeral
 musicPlayer.playFullFile(filename);  // Serial.println("Done playing music");
//musicPlayer.startPlayingFile(filename);
    //while (1);
  }
  if (Serial.available()) {
    char c = Serial.read();
    
    // if we get an 's' on the serial console, stop!
    if (c == 's') {
      musicPlayer.stopPlaying();
    }
    
    // if we get an 'p' on the serial console, pause/unpause!
    if (c == 'p') {
      if (! musicPlayer.paused()) {
        Serial.println("Paused");
        musicPlayer.pausePlaying(true);
      } else { 
        Serial.println("Resumed");
        musicPlayer.pausePlaying(false);
      }
    }
  }

  delay(100);
}
void writeByte(byte mydata) 
{
    uint8_t bitMask;
    for (bitMask = 0x01; bitMask; bitMask <<= 1) 
    {
	digitalWrite(ledData, (bitMask & mydata)?1:0);
    delayMicroseconds(1);
    digitalWrite(ledClk,1);
    delayMicroseconds(1);
    digitalWrite(ledClk,0);
    }
//Serial.println();
}
byte maskDigit(byte mydigit)
{
  byte temp;
  switch (mydigit) {
  case 1:
    temp=bseg | cseg;
    break;
    case 2:
    temp=aseg | bseg | gseg | eseg | dseg;
    break;
    case 3:
    temp=aseg | bseg | cseg | gseg | dseg;
    break;
    case 4:
    temp=fseg | gseg | bseg | cseg;
    break;
    case 5:
    temp=aseg | fseg | gseg | cseg | dseg;
    break;
    case 6:
    temp = aseg | fseg | eseg | dseg | cseg | gseg;
    break;
    case 7:
    temp=aseg | bseg | cseg;
    break;
    case 8:
    temp =aseg | bseg | cseg | dseg | eseg | fseg | gseg;
    break;
    case 9:
    temp =aseg | bseg | cseg | dseg | fseg | gseg;
    break;
    case 0:
    temp =aseg | bseg | cseg | dseg | eseg | fseg ;
    break;
    default:
    temp=0;
 }
 //Serial.print(" ");
 //Serial.print( temp,DEC);
    return temp;
}
Attachments
9.zip
(299.88 KiB) Downloaded 22 times

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: MP3 shield click sound before playing audio files

Post by adafruit_support_rick »

Do you get the audio artifacts if you run our unmodified example sketches?

Can you post clear, detailed pictures of both sides of the VS1053 and amplifier

dnear1
 
Posts: 16
Joined: Sun Sep 01, 2013 9:31 am

Re: MP3 shield click sound before playing audio files

Post by dnear1 »

Yes, the clicks were there with the unmodified sketch, but I didn't notice how bad until I started working and had the files on loop.
Attachments
shield bottom
shield bottom
20140603_073944.jpg (253.64 KiB) Viewed 890 times
shield top
shield top
20140603_073914.jpg (256.74 KiB) Viewed 890 times
Amplifier top
Amplifier top
20140603_073902.jpg (253.11 KiB) Viewed 890 times

dnear1
 
Posts: 16
Joined: Sun Sep 01, 2013 9:31 am

Re: MP3 shield click sound before playing audio files

Post by dnear1 »

More pics. The Arduino is just a standard mega1280
Attachments
vs1053 bottom
vs1053 bottom
20140603_074127.jpg (187.28 KiB) Viewed 890 times
under VS1053
under VS1053
20140603_074057.jpg (244.69 KiB) Viewed 890 times
amp bottom (sorry, it's under matte finish polycarbonate)
amp bottom (sorry, it's under matte finish polycarbonate)
20140603_074009.jpg (223.43 KiB) Viewed 890 times

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: MP3 shield click sound before playing audio files

Post by adafruit_support_rick »

I'm going to guess that you have a grounding problem someplace.

Let's work backwards: What happens if you leave the proto board and amplifier out of the equation? that is, replicate the "simple audio player" wiring from the tutorial, and use a pair of headphones? Do you still get the artifacts?

dnear1
 
Posts: 16
Joined: Sun Sep 01, 2013 9:31 am

Re: MP3 shield click sound before playing audio files

Post by dnear1 »

I handed the existing setup to a friend to look at, so I haven't been able to do testing with it.
But, I got my hands on an Arduino Mega2560 and since they finally got restocked, purchased the Arduino shield version of the Music Maker, and using another flash card, have the same results without a middle-adapter board or other wiring stuff to trip me up.

Here's 3 pictures of the board connections and a link to an MP4 recorded during playback.
https://www.dropbox.com/s/jbmvx4vjqfd64 ... .29.25.mp4
Attachments
2014-06-14 13.30.04.jpg
2014-06-14 13.30.04.jpg (177.41 KiB) Viewed 852 times
2014-06-14 13.29.56.jpg
2014-06-14 13.29.56.jpg (176.12 KiB) Viewed 852 times
2014-06-14 13.28.41.jpg
2014-06-14 13.28.41.jpg (157.86 KiB) Viewed 852 times

dnear1
 
Posts: 16
Joined: Sun Sep 01, 2013 9:31 am

Re: MP3 shield click sound before playing audio files

Post by dnear1 »

I tried using Audacity to convert my wav files to MP3, and they seem to always fail when playing as MP3. Tried Ogg Vorbis and got similar results. Tried outputting as Microsft PCM and it plays but still get the click when the audio file is selected.
Tried an actual music file converted to PCM and still get the click immediately before the file plays.

This is what the audio file looks like in Audacity.
Attachments
Snap 2014-06-14 at 16.06.05.jpg
Snap 2014-06-14 at 16.06.05.jpg (87.6 KiB) Viewed 850 times

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: MP3 shield click sound before playing audio files

Post by adafruit_support_rick »

I'm getting the same click. Interestingly, it doesn't occur on the very first file I play, but it does on all subsequent files.
I'm not getting the hiss at all. However, I'm using wav files, not mp3s. Can you convert your files to wavs and see if the hissing goes away?

dnear1
 
Posts: 16
Joined: Sun Sep 01, 2013 9:31 am

Re: MP3 shield click sound before playing audio files

Post by dnear1 »

I started with wav files. I only switched audio formats to see if there was some issue with it supporting wav files. The hiss is inconsistent and unpredictable, but happens more with other audio formats. With wav files, it might play fine for a few minutes, then hiss for a random number of files, then revert to normal.

I tried one thing that seemed to help, but not entirely. I tied the test pin to do and toggled it low for 1 ms before each audio file was played. This made it so that there were significantly less hiss occurrences, but they still occurred. It also seemed to cut down on the number of audio files that hissed in a row. But, this made the volume inconsistent between audio files. even if I set the volume the same as done in setup, which seemed to make it even less consistent. It frequently got louder. . I checked signals with my rigol scope, and the transitions have minimal ringing, but about half a volt overshoot on rising and half a volt overshoot on falling edges. Scope pins were grounded to the gnd pins on the shield by inserting a short header pin using the 3inch ground lead clips that come with the scope

dnear1
 
Posts: 16
Joined: Sun Sep 01, 2013 9:31 am

Re: MP3 shield click sound before playing audio files

Post by dnear1 »

Scoped CCS and DCS to make sure they weren't both toggling at the same time. I use single trigger so it would catch a waveform each time run was pressed and I could see the next 20ms of data. Not sure if there's an easy way to have the scope trigger specifically at that.. but from the looks of it, CCS is always HIGH when DCS is toggled high during access. and DCS is always LOW when CCS is LOW.

dnear1
 
Posts: 16
Joined: Sun Sep 01, 2013 9:31 am

Re: MP3 shield click sound before playing audio files

Post by dnear1 »

*test pin referenced above was actually reset pin.. silly auto-correct on my phone :/

dnear1
 
Posts: 16
Joined: Sun Sep 01, 2013 9:31 am

Re: MP3 shield click sound before playing audio files

Post by dnear1 »

"tied test pin to do" should have read "tied Reset pin on the Music Make shield to D9"

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: MP3 shield click sound before playing audio files

Post by adafruit_support_rick »

dnear1 wrote:*test pin referenced above was actually reset pin.. silly auto-correct on my phone :/
dnear1 wrote:"tied test pin to do" should have read "tied Reset pin on the Music Make shield to D9"
Got it.
I need to scope this when I get home. I'll try to get back to you tomorrow.

User avatar
adafruit2
 
Posts: 22148
Joined: Fri Mar 11, 2005 7:36 pm

Re: MP3 shield click sound before playing audio files

Post by adafruit2 »

to reduce any click before playing audio one thing you can try is reducing the volume all the way to (100,100) or larger right before you start, and then immediately increase the volume

dnear1
 
Posts: 16
Joined: Sun Sep 01, 2013 9:31 am

Re: MP3 shield click sound before playing audio files

Post by dnear1 »

I tried doing that. It did reduce the frequency of the click preceding the audio file, but it was not a reliable solution. It seems that the setVolume command does not function reliably either. Going to the VLSI forum, I found common issue might be improper SCK phase and polarity.. but it appears correct.. (SI sampled on rising CLK edge, SO shifted out on falling SCK edge) See attached waveforms from my Rigol DS1052E. I also noted the typical connection diagram in Page 13 of the VS1053 manual has 10 100nf bypass caps, plus a few other bulk caps but the shield appears to have only one specifically for the VS1053.. That may explain the data voltage overshoot I see..

I saw some notes about upgrading the "application" in the VS1053, but haven't dug deep enough to be able to check whether the chip has the latest firmware or not.

Below is the sketch I started fresh with and modified to rapidly change the volume..

Code: Select all

/*************************************************** 
  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 can be any pins:
#define RESET 9      // VS1053 reset pin (output)
#define CS 7//10        // VS1053 chip select pin (output)
#define DCS 6//8        // VS1053 Data/command select pin (output)
#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 = Adafruit_VS1053_FilePlayer(RESET, CS, DCS, DREQ, CARDCS);

void setup() {
  Serial.begin(9600);
  Serial.println("Adafruit VS1053 Simple Test");

  musicPlayer.begin(); // initialise the music player
  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
  musicPlayer.playFullFile("00.wav");
  // Play another file in the background, REQUIRES interrupts!
  musicPlayer.setVolume(100,100);
  musicPlayer.startPlayingFile("01.wav");
  musicPlayer.setVolume(20,20);
}

void loop() {
  // File is playing in the background
  if (musicPlayer.stopped()) {
  musicPlayer.setVolume(100,100);
  musicPlayer.startPlayingFile("01.wav");
  musicPlayer.setVolume(20,20);
    //Serial.println("Done playing music");
    //while (1);
  }
  if (Serial.available()) {
    char c = Serial.read();
    
    // if we get an 's' on the serial console, stop!
    if (c == 's') {
      musicPlayer.stopPlaying();
    }
    
    // if we get an 'p' on the serial console, pause/unpause!
    if (c == 'p') {
      if (! musicPlayer.paused()) {
        Serial.println("Paused");
        musicPlayer.pausePlaying(true);
      } else { 
        Serial.println("Resumed");
        musicPlayer.pausePlaying(false);
      }
    }
  }

  delay(100);
}
Attachments
Typical connection diagram from VS1053 manual
Typical connection diagram from VS1053 manual
Snap 2014-06-15 at 16.29.36.jpg (101.75 KiB) Viewed 805 times
Trigger on MISO (Channel 2), Clk is CH1
Trigger on MISO (Channel 2), Clk is CH1
Snap 2014-06-15 at 16.20.54.jpg (56.62 KiB) Viewed 805 times
Trigger on Clk (Channel 1), CH2 is MOSI
Trigger on Clk (Channel 1), CH2 is MOSI
Snap 2014-06-15 at 16.16.25.jpg (59.04 KiB) Viewed 805 times

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

Return to “Arduino Shields from Adafruit”