Is there more to it than just copy and pasting the plugin onto the card?
Is it possible to not use the plugin? It doesn't matter what sort of file type it is.
I can't seem to find this problem repeated anywhere... is there something that I'm supposed to do that is supposed to be fairly obvious?
The code is unchanged, except for the beginning, which just changes the pin layout.
Thanks.
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
****************************************************/
// This is a very beta demo of Ogg Vorbis recording. It works...
// Connect a button to digital 7 on the Arduino and use that to
// start and stop recording.
// A mic or line-in connection is required. See page 13 of the
// datasheet for wiring
// Don't forget to copy the v44k1q05.img patch to your micro SD
// card before running this example!
// include SPI, MP3 and SD libraries
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>
// Feather M0 or 32u4
#if defined(__AVR__) || defined(ARDUINO_SAMD_FEATHER_M0)
#define VS1053_CS 6 // VS1053 chip select pin (output)
#define VS1053_DCS 10 // VS1053 Data/command select pin (output)
#define CARDCS 5 // Card chip select pin
// DREQ should be an Int pin *if possible* (not possible on 32u4)
#define VS1053_DREQ 9 // VS1053 Data request, ideally an Interrupt pin
// Feather ESP8266
#elif defined(ESP8266)
#define VS1053_CS 16 // VS1053 chip select pin (output)
#define VS1053_DCS 15 // VS1053 Data/command select pin (output)
#define CARDCS 2 // Card chip select pin
#define VS1053_DREQ 0 // VS1053 Data request, ideally an Interrupt pin
// Feather ESP32
#elif defined(ESP32)
#define VS1053_CS 32 // VS1053 chip select pin (output)
#define VS1053_DCS 33 // VS1053 Data/command select pin (output)
#define CARDCS 14 // Card chip select pin
#define VS1053_DREQ 15 // VS1053 Data request, ideally an Interrupt pin
// Feather Teensy3
#elif defined(TEENSYDUINO)
#define VS1053_CS 3 // VS1053 chip select pin (output)
#define VS1053_DCS 10 // VS1053 Data/command select pin (output)
#define CARDCS 8 // Card chip select pin
#define VS1053_DREQ 4 // VS1053 Data request, ideally an Interrupt pin
// WICED feather
#elif defined(ARDUINO_STM32_FEATHER)
#define VS1053_CS PC7 // VS1053 chip select pin (output)
#define VS1053_DCS PB4 // VS1053 Data/command select pin (output)
#define CARDCS PC5 // Card chip select pin
#define VS1053_DREQ PA15 // VS1053 Data request, ideally an Interrupt pin
#elif defined(ARDUINO_FEATHER52)
#define VS1053_CS 30 // VS1053 chip select pin (output)
#define VS1053_DCS 11 // VS1053 Data/command select pin (output)
#define CARDCS 27 // Card chip select pin
#define VS1053_DREQ 31 // VS1053 Data request, ideally an Interrupt pin
#endif
//// Feather ESP32 layout
////#elif defined(ESP32)
#define RESET 33 // VS1053 reset pin (output)
//#define CS 32 // VS1053 chip select pin (output)
//#define DCS 33 // VS1053 Data/command select pin (output)
//#define CARDCS 14 // Card chip select pin
//#define DREQ 15 // VS1053 Data request, ideally an Interrupt pin
//// define the pins used
//#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 A0 // Card chip select pin
//#define DREQ A1 // VS1053 Data request, ideally an Interrupt pin
#define REC_BUTTON 14
Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(RESET, VS1053_CS, VS1053_DCS, VS1053_DREQ, CARDCS);
// WITH RESET --- Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(RESET, CS, DCS, DREQ, CARDCS);
File recording; // the file we will save our recording to
#define RECBUFFSIZE 128 // 64 or 128 bytes.
uint8_t recording_buffer[RECBUFFSIZE];
//#include "soc/soc.h"
//#include "soc/rtc_cntl_reg.h"
void setup() {
Serial.begin(9600);
Serial.println("Adafruit VS1053 Ogg Recording Test");
// initialise the music player
if (!musicPlayer.begin()) {
Serial.println("VS1053 not found");
while (1); // don't do anything more
}
musicPlayer.sineTest(0x44, 500); // Make a tone to indicate VS1053 is working
if (!SD.begin(CARDCS)) {
Serial.println("SD failed, or not present");
while (1); // don't do anything more
}
Serial.println("SD OK!");
// Set volume for left, right channels. lower numbers == louder volume!
musicPlayer.setVolume(10, 10);
// when the button is pressed, record!
pinMode(REC_BUTTON, INPUT);
digitalWrite(REC_BUTTON, HIGH);
// load plugin from SD card! We'll use mono 44.1KHz, high quality
if (! musicPlayer.prepareRecordOgg("v44k1q05.img")) {
Serial.println("Couldn't load plugin!");
while (1);
}
}
uint8_t isRecording = false;
void loop() {
if (!isRecording && !digitalRead(REC_BUTTON)) {
Serial.println("Begin recording");
isRecording = true;
// Check if the file exists already
char filename[15];
strcpy(filename, "RECORD00.OGG");
for (uint8_t i = 0; i < 100; i++) {
filename[6] = '0' + i / 10;
filename[7] = '0' + i % 10;
// create if does not exist, do not open existing, write, sync after write
if (! SD.exists(filename)) {
break;
}
}
Serial.print("Recording to "); Serial.println(filename);
recording = SD.open(filename, FILE_WRITE);
if (! recording) {
Serial.println("Couldn't open file to record!");
while (1);
}
musicPlayer.startRecordOgg(true); // use microphone (for linein, pass in 'false')
}
if (isRecording)
saveRecordedData(isRecording);
if (isRecording && !digitalRead(REC_BUTTON)) {
Serial.println("End recording");
musicPlayer.stopRecordOgg();
isRecording = false;
// flush all the data!
saveRecordedData(isRecording);
// close it up
recording.close();
delay(1000);
}
}
uint16_t saveRecordedData(boolean isrecord) {
uint16_t written = 0;
// read how many words are waiting for us
uint16_t wordswaiting = musicPlayer.recordedWordsWaiting();
// try to process 256 words (512 bytes) at a time, for best speed
while (wordswaiting > 256) {
//Serial.print("Waiting: "); Serial.println(wordswaiting);
// for example 128 bytes x 4 loops = 512 bytes
for (int x = 0; x < 512 / RECBUFFSIZE; x++) {
// fill the buffer!
for (uint16_t addr = 0; addr < RECBUFFSIZE; addr += 2) {
uint16_t t = musicPlayer.recordedReadWord();
//Serial.println(t, HEX);
recording_buffer[addr] = t >> 8;
recording_buffer[addr + 1] = t;
}
if (! recording.write(recording_buffer, RECBUFFSIZE)) {
Serial.print("Couldn't write "); Serial.println(RECBUFFSIZE);
while (1);
}
}
// flush 512 bytes at a time
recording.flush();
written += 256;
wordswaiting -= 256;
}
wordswaiting = musicPlayer.recordedWordsWaiting();
if (!isrecord) {
Serial.print(wordswaiting); Serial.println(" remaining");
// wrapping up the recording!
uint16_t addr = 0;
for (int x = 0; x < wordswaiting - 1; x++) {
// fill the buffer!
uint16_t t = musicPlayer.recordedReadWord();
recording_buffer[addr] = t >> 8;
recording_buffer[addr + 1] = t;
if (addr > RECBUFFSIZE) {
if (! recording.write(recording_buffer, RECBUFFSIZE)) {
Serial.println("Couldn't write!");
while (1);
}
recording.flush();
addr = 0;
}
}
if (addr != 0) {
if (!recording.write(recording_buffer, addr)) {
Serial.println("Couldn't write!"); while (1);
}
written += addr;
}
musicPlayer.sciRead(VS1053_SCI_AICTRL3);
if (! (musicPlayer.sciRead(VS1053_SCI_AICTRL3) & _BV(2))) {
recording.write(musicPlayer.recordedReadWord() & 0xFF);
written++;
}
recording.flush();
}
return written;
}