예제 #1
0
boolean Adafruit_VS1053_FilePlayer::startPlayingFile(const char *trackname) {
    // reset playback
    sciWrite(VS1053_REG_MODE, VS1053_MODE_SM_LINE1 | VS1053_MODE_SM_SDINEW);
    // resync
    sciWrite(VS1053_REG_WRAMADDR, 0x1e29);
    sciWrite(VS1053_REG_WRAM, 0);

    currentTrack = SD.open(trackname);
    if (!currentTrack) {
        return false;
    }

    // As explained in datasheet, set twice 0 in REG_DECODETIME to set time back to 0
    sciWrite(VS1053_REG_DECODETIME, 0x00);
    sciWrite(VS1053_REG_DECODETIME, 0x00);

    playingMusic = true;

    // wait till its ready for data
    while (!readyForData());


    // fill it up!
    while (playingMusic && readyForData())
        feedBuffer();

//  Serial.println("Ready");

    return true;
}
예제 #2
0
void Adafruit_VS1053_FilePlayer::feedBuffer(void) {
    static uint8_t running = 0;
    uint8_t sregsave;

#ifndef __SAM3X8E__
    // Do not allow 2 copies of this code to run concurrently.
    // If an interrupt causes feedBuffer() to run while another
    // copy of feedBuffer() is already running in the main
    // program, havoc can occur.  "running" detects this state
    // and safely returns.
    sregsave = SREG;
    cli();
    if (running) {
        SREG = sregsave;
        return;  // return safely, before touching hardware!  :-)
    } else {
        running = 1;
        SREG = sregsave;
    }
#endif

    if (!playingMusic) {
        running = 0;
        return; // paused or stopped
    }
    if (!currentTrack) {
        running = 0;
        return;
    }
    if (!readyForData()) {
        running = 0;
        return;
    }

    // Feed the hungry buffer! :)
    while (readyForData()) {
        //UDR0 = '.';

        // Read some audio data from the SD card file
        uint8_t bytesRead = (uint8_t) currentTrack.read(mp3buffer, VS1053_DATABUFFERLEN);

        if (bytesRead == 0) {
            // must be at the end of the file, wrap it up!
            playingMusic = false;
            currentTrack.close();
            running = 0;
            return;
        }
        playData(mp3buffer, bytesRead);
    }
    running = 0;
    return;
}
boolean Adafruit_VS1053_FilePlayer::startPlayingFile(const char *trackname) {
  // reset playback
  sciWrite(VS1053_REG_MODE, VS1053_MODE_SM_LINE1 | VS1053_MODE_SM_SDINEW);
  // resync
  sciWrite(VS1053_REG_WRAMADDR, 0x1e29);
  sciWrite(VS1053_REG_WRAM, 0);

  currentTrack = SD.open(trackname);
  if (!currentTrack) {
    return false;
  }
    
  // We know we have a valid file. Check if .mp3
  // If so, check for ID3 tag and jump it if present.
  if (isMP3File(trackname)) {
    currentTrack.seek(mp3_ID3Jumper(currentTrack));
  }

  // don't let the IRQ get triggered by accident here
  noInterrupts();

  // As explained in datasheet, set twice 0 in REG_DECODETIME to set time back to 0
  sciWrite(VS1053_REG_DECODETIME, 0x00);
  sciWrite(VS1053_REG_DECODETIME, 0x00);

  playingMusic = true;

  // wait till its ready for data
  while (! readyForData() ) {
#if defined(ESP8266)
	yield();
#endif
  }

  // fill it up!
  while (playingMusic && readyForData()) {
    feedBuffer();
  }
  
  // ok going forward, we can use the IRQ
  interrupts();

  return true;
}
예제 #4
0
boolean Adafruit_VS1053::prepareRecordOgg(char *plugname) {
  sciWrite(VS1053_REG_CLOCKF, 0xC000);  // set max clock
  delay(1);    while (! readyForData() );

  sciWrite(VS1053_REG_BASS, 0);  // clear Bass
  
  softReset();
  delay(1);    while (! readyForData() );

  sciWrite(VS1053_SCI_AIADDR, 0);
  // disable all interrupts except SCI
  sciWrite(VS1053_REG_WRAMADDR, VS1053_INT_ENABLE);
  sciWrite(VS1053_REG_WRAM, 0x02);

  int pluginStartAddr = loadPlugin(plugname);
  if (pluginStartAddr == 0xFFFF) return false;
  Serial.print("Plugin at $"); Serial.println(pluginStartAddr, HEX);
  if (pluginStartAddr != 0x34) return false;

  return true;
}
void Adafruit_VS1053_FilePlayer::feedBuffer_noLock(void) {
  if ((! playingMusic) // paused or stopped
      || (! currentTrack) 
      || (! readyForData())) {
    return; // paused or stopped
  }

  // Feed the hungry buffer! :)
  while (readyForData()) {
    // Read some audio data from the SD card file
    int bytesread = currentTrack.read(mp3buffer, VS1053_DATABUFFERLEN);
    
    if (bytesread == 0) {
      // must be at the end of the file, wrap it up!
      playingMusic = false;
      currentTrack.close();
      break;
    }

    playData(mp3buffer, bytesread);
  }
}
void Adafruit_VS1053::playBuffer(uint8_t *buffer, size_t buffsiz) {
#ifdef SPI_HAS_TRANSACTION
    if (useHardwareSPI) SPI.beginTransaction(VS1053_DATA_SPI_SETTING);
#endif
    digitalWrite(_dcs, LOW);
    while ( buffsiz ) {
        while (!readyForData());
        delayMicroseconds(3);
        size_t chunk_length = min(buffsiz,VS1053_DATABUFFERLEN);
        buffsiz -= chunk_length;
        while ( chunk_length-- ) spiwrite(*buffer++);
    }
    digitalWrite(_dcs, HIGH);
#ifdef SPI_HAS_TRANSACTION
    if (useHardwareSPI) SPI.endTransaction();
#endif
}
예제 #7
0
void Adafruit_VS1053::startRecordOgg(boolean mic) {
  /* Set VS1053 mode bits as instructed in the VS1053b Ogg Vorbis Encoder
     manual. Note: for microphone input, leave SMF_LINE1 unset! */
  if (mic) {
    sciWrite(VS1053_REG_MODE, VS1053_MODE_SM_ADPCM | VS1053_MODE_SM_SDINEW);
  } else {
    sciWrite(VS1053_REG_MODE, VS1053_MODE_SM_LINE1 | 
	     VS1053_MODE_SM_ADPCM | VS1053_MODE_SM_SDINEW);
  }
  sciWrite(VS1053_SCI_AICTRL0, 1024);
  /* Rec level: 1024 = 1. If 0, use AGC */
  sciWrite(VS1053_SCI_AICTRL1, 1024);
  /* Maximum AGC level: 1024 = 1. Only used if SCI_AICTRL1 is set to 0. */
  sciWrite(VS1053_SCI_AICTRL2, 0);
  /* Miscellaneous bits that also must be set before recording. */
  sciWrite(VS1053_SCI_AICTRL3, 0);
  
  sciWrite(VS1053_SCI_AIADDR, 0x34);
  delay(1);    while (! readyForData() );
}