Adafruit VS1053B Breakout Board Problem MP3 and WAV

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

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
hardada
 
Posts: 39
Joined: Sat Sep 10, 2011 1:50 pm

Re: Adafruit VS1053B Breakout Board Problem MP3 and WAV

Post by hardada »

Yes, Thanks. It is working now.
And Serial.print above and below the while prints the change from 1 to 0. OK

Before the Serial.prints picked it up, but the while or ifs didn't.

User avatar
hardada
 
Posts: 39
Joined: Sat Sep 10, 2011 1:50 pm

Re: Adafruit VS1053B Breakout Board Problem MP3 and WAV

Post by hardada »

Recap on earlier posts in this thread where I was getting a few milliseconds distortion / glitches between wav files when playing then as quicklyas possible after one another. The following fix seems to work.
Basically I think there is something wrong with sciWrite in the VS1053 library whn writing SCI control register values.
I rewrote it as sciInput as shown below and send 0x4800 to MODE at start and then set rsynch to Zero and also send SCI_CANCEL before stopping play. I can now cut off a file midstream and start the next and dont see any distortion on the waveform when zooming in on the output waveform. I got help on this via the vlsi forum.
It is not a professional fix but maybe point in the direction of what is wrong in the library.

Code: Select all

//
// This sketch is player_simple for Teensy3.1 modified to test speed
// for VS1053 breakout board...musicmaker taken out
// and serial prints commented out
//********************************************************

// include SPI, MP3 and SD libraries
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>
//#include "vs1053bpatch220plg.h"
// define the pins used
#define CLK 13       // SPI Clock, shared with SD card ( SCLK )
#define MISO 12      // Input data, from VS1053/SD card ( MISO )
#define MOSI 11      // Output data, to VS1053/SD card ( MOSI )
// 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) ( RST )
#define BREAKOUT_CS     10     // VS1053 chip sci control select pin (output) (CS )
#define BREAKOUT_DCS    8      // VS1053 Data/command select pin (output) ( XDCS )
// These are the pins used for the music maker shield
//#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 musicmaker shield
#define CARDCS 4     // Card chip select pin ( SDCS )
// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
#define DREQ 3       // VS1053 Data request, ideally an Interrupt pin ( DREQ ) 

Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(BREAKOUT_RESET, BREAKOUT_CS, BREAKOUT_DCS, DREQ, CARDCS);


void setup() {
  Serial.begin(9600);
  delay(1000);
  
pinMode (BREAKOUT_RESET, OUTPUT);  // RST library _reset
pinMode (BREAKOUT_CS, OUTPUT);     // CS  library _cs     Low for SCI read/write chipcontrol spi
pinMode (BREAKOUT_DCS, OUTPUT);    // XDCS library _dcs   Low for SPI data read/write chipData spi
//pinMode (CARDCS, INPUT);        // SDCS library _cardCS 
pinMode (DREQ, INPUT);             // DREQ library _dreq

  if (! musicPlayer.begin()) { // initialise the music player
     Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
     while (1);
  }
  Serial.println(F("VS1053 found"));
 
  delay(1000);
   
  SD.begin(CARDCS);    // initialise the SD card (SDCS)
  
  // Set volume for left, right channels. lower numbers == louder volume!
  musicPlayer.setVolume(5,5);
  
  sciInput(0, 0x4800);  // send MODE 0x4800 setting before playing file
  sciInput(0x07, 0x1e29); //BANNED Setting rsync to Zero before playing
  sciInput(0x06, 0);
   
  // Timer interrupts are not recommended, 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 is set as pin3 above
  
}

void loop() {

sciInput(0,0x4808);  // send SM_CANCEL before closing file
musicPlayer.stopPlaying();
   musicPlayer.startPlayingFile("B.wav");
   
delay(100);
sciInput(0,0x4808);  // send SM_CANCEL before closing file
musicPlayer.stopPlaying();
   musicPlayer.startPlayingFile("C.wav");
 delay(100);
 
}   //BANNED End of loop

// Below is alternative to sciWrite for writing to SCI control
 void sciInput(uint8_t addr, uint16_t data) {
  while(! digitalRead(DREQ));
  SPI.beginTransaction(SPISettings(250000, MSBFIRST, SPI_MODE0));
  
  digitalWrite(BREAKOUT_CS, LOW);  
  SPI.transfer(VS1053_SCI_WRITE);
  SPI.transfer(addr);
  SPI.transfer(data >> 8);
  SPI.transfer(data & 0xFF);
  digitalWrite(BREAKOUT_CS, HIGH);
 
  SPI.endTransaction();

 }
Last edited by adafruit_support_mike on Sun Mar 01, 2015 5:55 am, edited 1 time in total.
Reason: added CODE tags to preserve formatting

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

Re: Adafruit VS1053B Breakout Board Problem MP3 and WAV

Post by adafruit_support_mike »

Thanks for posting the code. I'll pass that along to the folks who work on the VS1053 library.

User avatar
hardada
 
Posts: 39
Joined: Sat Sep 10, 2011 1:50 pm

Re: Adafruit VS1053B Breakout Board Problem MP3 and WAV

Post by hardada »

I have been modifying the code to try to use interrupts, but I am not sure what I need the interrupt routine to do, or really how to set it up??
I thought I needed the interrupt to control the sending of the audio over SPI to the board, but I cannot get that to work.
I have 2 procedures, readsend32buf.......to send 32 bytes of audio over SPI and getplayit.....to get the sound file to play from SD. I can get it to work if I set attachinterrupts to getplayit, but if I set attachinterrupts to resdsend32buf I just get buzzing.
I have also tried RISING, CHANGE, FALLING etc doesn't matter
DREQ is the pin that is supposed to tell when the VS1053 can accept more data so I thought that pin should be attached to the sending data over SPI.???
Using with getplayit it just seems to check which file to play as DREQ rises and falls???? but seems to work??
Would be grateful for some help or point me to some similar example.
I am not using the library functions directly because I setup these simpler functions to see if I could understand it first.

Code: Select all

 attachInterrupt(DREQ, getplayit, CHANGE);
// attachInterrupt(DREQ, readsend32buf, RISING);
//DREQ is pin 3 and has interrupts
  
    }


void loop() {
  
 if (playing != playit)
 {
    if (playit == 1) 
   {
     playxx("B.wav");
   }
     else
  {
     playxx("C.wav");
  }
 }

while(! digitalRead(DREQ)); 
  readsend32buf();
   }    //..........end of loop...............
  
    //some more procedures / functions below
 
  void readsend32buf(void) {  //read and send buffer 32 bytes
        myfile.read(mybuffer, VS1053_DATABUFFERLEN);
   if (! myfile.available())
       {
         sciInput(0,0x4808);  // send SM_CANCEL before closing file
       myfile.close();
       playing = 0;
       }
     SPI.beginTransaction(VS1053_DATA_SPI_SETTING);
     digitalWrite(BREAKOUT_DCS, LOW);
    for (uint8_t i=0; i<VS1053_DATABUFFERLEN; i++) {
      SPI.transfer(mybuffer[i]);
        }
    digitalWrite(BREAKOUT_DCS, HIGH);
    SPI.endTransaction();
        }
  
  void sciInput(uint8_t addr, uint16_t data) {
  noInterrupts();
  while(! digitalRead(DREQ));
  SPI.beginTransaction(VS1053_CONTROL_SPI_SETTING);
  digitalWrite(BREAKOUT_CS, LOW);  
  SPI.transfer(VS1053_SCI_WRITE);
  SPI.transfer(addr);
  SPI.transfer(data >> 8);
  SPI.transfer(data & 0xFF);
  digitalWrite(BREAKOUT_CS, HIGH);
  SPI.endTransaction();
  interrupts();
           }
   
 void playxx(char *mname) {
   myfile = SD.open(mname, FILE_READ);
   if(! myfile) {
    Serial.println("file1 not found"); 
    while(1);
      }
    playing = playit;
   sciInput(0x07, 0x1e29); //BANNED Setting rsync to Zero
   sciInput(0x06, 0);
  if (! myfile.available() | (playing != playit)) 
      {
 sciInput(0,0x4808);  // send SM_CANCEL before closing file
 myfile.close();
 playing = 0;
  return;
    }
    }
          
  void getplayit(void)
      {
   if (touchRead(17) <= 900)
  {
     playit = 1;
  }
   else
  {
    playit = 2;
 
  }
      }

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

Re: Adafruit VS1053B Breakout Board Problem MP3 and WAV

Post by adafruit2 »

hiya thanks for the updates, we finally got to testing the changes and commited them to the library
not sure about your dreq question but we do have code in the library that does handle piping data into the SPI buffer, why not 'fork' it and then edit your changes in? that way you are starting with working code

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

Return to “Arduino Shields from Adafruit”