12#if !defined(ARDUINO_ARCH_RENESAS)
14#include <avr/pgmspace.h>
27static const uint16_t bitrate_table[15][6]
PROGMEM = {
29 { 32, 32, 32, 32, 8, 8},
30 { 64, 48, 40, 48, 16, 16},
31 { 96, 56, 48, 56, 24, 24},
32 {128, 64, 56, 64, 32, 32},
33 {160, 80, 64, 80, 40, 40},
34 {192, 96, 80, 96, 48, 48},
35 {224,112, 96,112, 56, 56},
36 {256,128,112,128, 64, 64},
37 {288,160,128,144, 80, 80},
38 {320,192,160,160, 96, 69},
39 {352,224,192,176,112,112},
40 {384,256,224,192,128,128},
41 {416,320,256,224,144,144},
42 {448,384,320,256,160,160}
50#define MIDI_NOTE_OFF 8
54#define MIDI_HDR_CHUNK_ID 0x4D, 0x54, 0x68, 0x64
55#define MIDI_CHUNKSIZE 0, 0, 0, 6
56#define MIDI_FORMAT 0, 0
57#define MIDI_NUMBER_OF_TRACKS 0, 1
58#define MIDI_TIME_DIVISION 0, 96
60#define MIDI_TRACK_CHUNK_ID 0x4D, 0x54, 0x72, 0x6B
61#define MIDI_CHUNK_SIZE 0, 0, 0, sizeof(MIDI_EVENT_NOTE_ON) + sizeof(MIDI_EVENT_NOTE_OFF) + sizeof(MIDI_END_OF_TRACK)
63#define MIDI_EVENT_NOTE_ON 0, (MIDI_NOTE_ON<<4) + MIDI_CHANNEL, MIDI_NOTE_NUMBER, MIDI_INTENSITY
64#define MIDI_EVENT_NOTE_OFF MIDI_NOTE_DURATION, (MIDI_NOTE_OFF<<4) + MIDI_CHANNEL, MIDI_NOTE_NUMBER, MIDI_INTENSITY
66#define MIDI_END_OF_TRACK 0, 0xFF, 0x2F, 0
112#if defined(USE_MP3_REFILL_MEANS) && USE_MP3_REFILL_MEANS == USE_MP3_SimpleTimer
148if (int8_t(
sd.vol()->fatType()) == 0) {
149 Serial.println(F(
"If you get this error, you likely do not have a sd.begin in the main sketch, See Trouble Shooting Guide!"));
150 Serial.println(F(
"http://mpflaga.github.com/Sparkfun-MP3-Player-Shield-Arduino-Library/#Troubleshooting"));
159#if PERF_MON_PIN != -1
175#if defined(USE_MP3_REFILL_MEANS) && USE_MP3_REFILL_MEANS == USE_MP3_Timer1
176 Timer1.initialize(MP3_REFILL_PERIOD);
177#elif defined(USE_MP3_REFILL_MEANS) && USE_MP3_REFILL_MEANS == USE_MP3_SimpleTimer
178 timerId_mp3 = timer.setInterval(MP3_REFILL_PERIOD,
refill);
179 timer.disable(timerId_mp3);
280#if (ARDUINO_ARCH_AVR)
282#elif (ARDUINO_ARCH_RENESAS)
290 if (MP3Clock != 0x6000)
return 5;
343 if(!
track.open(fileName, O_READ))
return 2;
351 if(n.
word & 0x8000U) {
397 Serial.println(F(
"Warning Tests are not available."));
408 for(
int y = 0 ; y <= 1 ; y++) {
424 SPI.endTransaction();
449 Serial.println(F(
"Warning Tests are not available."));
477 SPI.endTransaction();
505 Serial.println(F(
"Warning Tests are not available."));
541 SPI.endTransaction();
715 else if(frequency > 15)
741 else if(amplitude > 7)
769 else if(frequency > 15)
799 else if(amplitude > 15)
899 if(EarSpeaker & 0b01) {
905 if(EarSpeaker & 0b10) {
1035 char trackName[] =
"track001.mp3";
1036 uint8_t trackNumber = 1;
1039 sprintf(trackName,
"track%03d.mp3", trackNo);
1080 if(!
track.open(fileName, O_READ))
return 2;
1083 int len = strlen(fileName);
1087 if (len > 3 && !strcasecmp(fileName + len - 3,
"mp3")) {
1477 uint32_t currentPos =
track.curPosition();
1480 track.seekEnd((-128 + offset));
1483 track.read(infobuffer, 30);
1487 track.seekSet(currentPos);
1514 Serial.print(F(
"HDAT1"));
1515 Serial.print(F(
"\tHDAT0"));
1516 Serial.print(F(
"\tVOL"));
1517 Serial.print(F(
"\tMode"));
1518 Serial.print(F(
"\tStatus"));
1519 Serial.print(F(
"\tClockF"));
1520 Serial.print(F(
"\tpversion"));
1521 Serial.print(F(
"\t[Bytes/S]"));
1522 Serial.print(F(
"\t[KBits/S]"));
1523 Serial.print(F(
"\tPlaySpeed"));
1524 Serial.print(F(
"\tDECODE_TIME"));
1525 Serial.print(F(
"\tCurrentPos"));
1529 Serial.print(F(
"0x"));
1530 Serial.print(MP3HDAT1, HEX);
1533 Serial.print(F(
"\t0x"));
1534 Serial.print(MP3HDAT0, HEX);
1537 Serial.print(F(
"\t0x"));
1538 Serial.print(MP3SCI_VOL, HEX);
1541 Serial.print(F(
"\t0x"));
1542 Serial.print(MP3Mode, HEX);
1545 Serial.print(F(
"\t0x"));
1546 Serial.print(MP3Status, HEX);
1549 Serial.print(F(
"\t0x"));
1550 Serial.print(MP3Clock, HEX);
1553 Serial.print(F(
"\t0x"));
1554 Serial.print(MP3para_version, HEX);
1557 Serial.print(F(
"\t\t"));
1558 Serial.print(MP3ByteRate, HEX);
1560 Serial.print(F(
"\t\t"));
1561 Serial.print((MP3ByteRate>>7), DEC);
1564 Serial.print(F(
"\t\t"));
1565 Serial.print(MP3playSpeed, HEX);
1568 Serial.print(F(
"\t\t"));
1569 Serial.print(MP3SCI_DECODE_TIME, DEC);
1571 Serial.print(F(
"\t\t"));
1598 for(uint16_t i = 0; i<65535; i++) {
1599 if(
track.read() == 0xFF) {
1601 temp =
track.read();
1603 if(((temp & 0b11100000) == 0b11100000) && ((temp & 0b00000110) != 0b00000000)) {
1607 if(!(temp & 0b00001000)) {
1610 else if((temp & 0b00000110) == 0b00000100) {
1613 else if((temp & 0b00000110) == 0b00000010) {
1621 temp =
track.read();
1625 bitrate = pgm_read_word_near ( &(bitrate_table[temp][row_num]) );
1734 SPI.beginTransaction(SPISettings(
spi_Max_Rate, MSBFIRST, SPI_MODE0));
1832 SPI.transfer(addressbyte);
1833 SPI.transfer(highbyte);
1834 SPI.transfer(lowbyte);
1837 SPI.endTransaction();
1877 SPI.transfer(addressbyte);
1879 resultvalue.
byte[1] = SPI.transfer(0xFF);
1881 resultvalue.
byte[0] = SPI.transfer(0xFF);
1885 SPI.endTransaction();
1895 return resultvalue.
word;
1910 unsigned short int tmp1,tmp2;
1921 if(tmp1==tmp2)
return tmp1;
1925 if(tmp1==tmp2)
return tmp1;
1929 if(tmp1==tmp2)
return tmp1;
1957#if defined(USE_MP3_REFILL_MEANS) && USE_MP3_REFILL_MEANS == USE_MP3_SimpleTimer
1959#elif defined(USE_MP3_REFILL_MEANS) && USE_MP3_REFILL_MEANS == USE_MP3_Polled
1981#if PERF_MON_PIN != -1
1986#if !defined(USE_MP3_REFILL_MEANS) || USE_MP3_REFILL_MEANS == irq
2007#if !defined(USE_MP3_REFILL_MEANS) || USE_MP3_REFILL_MEANS == irq
2017 SPI.endTransaction();
2020#if !defined(USE_MP3_REFILL_MEANS) || USE_MP3_REFILL_MEANS == irq
2025#if PERF_MON_PIN != -1
2056#if !defined(USE_MP3_REFILL_MEANS) || USE_MP3_REFILL_MEANS == irq
2069 SPI.endTransaction();
2071#if !defined(USE_MP3_REFILL_MEANS) || USE_MP3_REFILL_MEANS == irq
2089 #if defined(USE_MP3_REFILL_MEANS) && USE_MP3_REFILL_MEANS == USE_MP3_Timer1
2090 Timer1.attachInterrupt(
refill );
2091 #elif defined(USE_MP3_REFILL_MEANS) && USE_MP3_REFILL_MEANS == USE_MP3_SimpleTimer
2092 timer.enable(timerId_mp3);
2093 #elif !defined(USE_MP3_REFILL_MEANS) || USE_MP3_REFILL_MEANS == irq
2108#if defined(USE_MP3_REFILL_MEANS) && USE_MP3_REFILL_MEANS == USE_MP3_Timer1
2109 Timer1.detachInterrupt();
2110#elif defined(USE_MP3_REFILL_MEANS) && USE_MP3_REFILL_MEANS == USE_MP3_SimpleTimer
2111 timer.disable(timerId_mp3);
2112#elif !defined(USE_MP3_REFILL_MEANS) || USE_MP3_REFILL_MEANS == irq
2113 detachInterrupt(
irq);
2137 if((mode ==
post) || (mode ==
both)) {
2140 for(
int y = 0 ; y < 2052 ; y++) {
2142 SPI.transfer(endFillByte);
2145 SPI.endTransaction();
2148 for (
int n = 0; n < 64 ; n++)
2154 for(
int y = 0 ; y < 32 ; y++) {
2156 SPI.transfer(endFillByte);
2159 SPI.endTransaction();
2164 if((mode ==
pre) || (mode ==
both)) {
2166 for(
int y = 0 ; y < 2052 ; y++) {
2168 SPI.transfer(endFillByte);
2171 SPI.endTransaction();
2220#if defined(VS_LINE1_MODE)
2249 if((ADM_volume > -3) || (-31 > ADM_volume)) {
2251 MP3AIADDR.
word = 0x0F01;
2256 MP3AICTRL0.
byte[1] = (uint8_t) ADM_volume;
2257 MP3AICTRL0.
byte[0] = (uint8_t) ADM_volume;
2261 MP3AIADDR.
word = 0x0F00;
2277 for ( ; *s && !isalpha(*s); ++s)
2282 char *tail = s + strlen(s);
2283 for ( ; !isalpha(*tail); --tail)
2299 int8_t len = strlen(filename);
2302 (!strcasecmp(filename + len - 4,
".mp3")
2303 || !strcasecmp(filename + len - 4,
".aac")
2304 || !strcasecmp(filename + len - 4,
".wma")
2305 || !strcasecmp(filename + len - 4,
".wav")
2306 || !strcasecmp(filename + len - 4,
".fla")
2307 || !strcasecmp(filename + len - 4,
".mid"))) {
static void Mp3WriteWRAM(uint16_t, uint16_t)
Write a VS10xx WRAM Location.
static void spiInit()
Initialize the SPI for VS10xx use.
uint8_t getDifferentialOutput()
Get the current SM_DIFF setting from the VS10xx chip.
void resumeDataStream()
Unpause streaming data to the VSdsp.
static void dcs_low()
Select Data Channel.
uint8_t VolL
contains a local value of the VSdsp's master volume left channels
void setDifferentialOutput(uint16_t)
Set the current SM_DIFF setting of the VS10xx chip.
uint16_t getVolume()
Get the current volume from the VS10xx chip.
uint16_t memoryTest()
Perform Memory Test.
static void cs_low()
Select Control Channel.
static void dcs_high()
Deselect Data Channel.
static void Mp3WriteRegister(uint8_t, uint8_t, uint8_t)
Write a value a VSDsp's register.
uint8_t VolR
contains a local value of the VSdsp's master volume Right channels
void trackAlbum(char *)
Get Track's Album.
uint16_t getBassFrequency()
Get the current Bass Frequency limit from the VS10xx chip.
void setBassFrequency(uint16_t)
Set the current Bass Boost Frequency limit cutoff in VS10xx chip.
uint8_t disableTestSineWave()
Disable Test Sine wave.
state_m getState()
Get the current state of the device.
static state_m playing_state
Boolean flag indicating if filehandle is streaming.
void stopTrack()
Gracefully close track and cancel refill.
void setBitRate(uint16_t)
Force bit rate.
uint8_t begin()
Initialize the MP3 Player shield.
static SdFile track
Initializer for the instance of the SdCard's static member.
uint8_t skipTo(uint32_t)
Skips to a certain point in the track.
uint8_t ADMixerLoad(char *)
Initially load ADMixer patch and configure line/mic mode.
uint8_t isPlaying()
Inidicate if a song is playing?
uint8_t playMP3(char *, uint32_t timecode=0)
Begin playing a mp3 file by its filename.
uint8_t playTrack(uint8_t)
Begin playing a mp3 file, just with a number.
void setEarSpeaker(uint16_t)
Set the current Spatial EarSpeaker setting of the VS10xx chip.
void SendSingleMIDInote()
Play hardcoded MIDI file.
int8_t getBassAmplitude()
Get the current Bass boost amplitude from the VS10xx chip.
int8_t setVUmeter(int8_t)
enable VSdsp VU Meter
uint8_t bitrate
contains a local value of the beleived current bit-rate.
void getAudioInfo()
Display various Audio information from the VSdsp.
static void cs_high()
Deselect Control Channel.
int8_t getVUmeter()
get the status of the VSdsp VU Meter
void setTrebleFrequency(uint16_t)
Set the current treble frequency limit in VS10xx chip.
uint32_t currentPosition()
Current timecode in ms.
uint16_t getMonoMode()
Get the current Stereo/Mono setting of the VS10xx output.
void end()
Disables the MP3 Player shield.
static uint16_t Mp3ReadWRAM(uint16_t)
Read a VS10xx WRAM Location.
int8_t getTrebleAmplitude()
Get the current Treble Amplitude from the VS10xx chip.
static uint32_t spi_Max_Rate
Rate of the SPI to be used with communicating to the VSdsp.
void setBassAmplitude(uint8_t)
Set the current Bass Boost amplitude in VS10xx chip.
void setVolume(uint8_t, uint8_t)
Store and Push member volume to VS10xx chip.
uint16_t getTrebleFrequency()
Get the current Treble Frequency limit from the VS10xx chip.
void setTrebleAmplitude(int8_t)
Set the current Treble Amplitude in VS10xx chip.
void getBitRateFromMP3File(char *)
Read the Bit-Rate from the current track's filehandle.
static void refill()
Refill the VS10xx buffer with new data.
uint8_t VSLoadUserCode(char *)
load VS1xxx with patch or plugin from file on SDcard.
static void available()
Public interface of refill.
void pauseDataStream()
Pause streaming data to the VSdsp.
void ADMixerVol(int8_t)
Set ADMixer's attenuation of input to between -3 and -31 dB otherwise disable.
void setMonoMode(uint16_t)
Set the current Stereo/Mono setting of the VS10xx output.
uint8_t vs_init()
Initialize the VS10xx Audio Decoder Chip.
void setPlaySpeed(uint16_t)
Set the current playSpeed of the VS10xx chip.
int16_t getVUlevel()
get current measured VU Meter
uint32_t start_of_music
contains a filehandles offset to the begining of the current file.
static void disableRefill()
Disable the Interrupts for refill.
uint8_t getEarSpeaker()
Get the current Spatial EarSpeaker setting from the VS10xx chip.
void trackTitle(char *)
Get Track's Title.
bool resumeMusic()
Resume music from where it was paused.
static void enableRefill()
Enable the Interrupts for refill.
void pauseMusic()
Pause music.
static uint16_t Mp3ReadRegister(uint8_t)
Read a VS10xx register.
uint8_t enableTestSineWave(uint8_t)
Generate Test Sine wave.
uint8_t skip(int32_t)
Skips to a duration in the track.
void getTrackInfo(uint8_t, char *)
Fetch ID3 Tag information.
uint16_t getPlaySpeed()
Get the current playSpeed from the VS10xx chip.
void trackArtist(char *)
Get Track's Artist.
static void flush_cancel(flush_m)
flush the VSdsp buffer and cancel
static uint8_t mp3DataBuffer[32]
Buffer for moving data between Filehandle and VSdsp.
A handler for accessing bytes of a word.
uint16_t word
whole word value
uint8_t byte[2]
individual bytes
A handler for accessing nibbles of the SCI_BASS word.
struct vs1053::sci_bass_m::@122063340134256071104100347103242272313255100340 nibble
individual Nibbles
uint16_t word
whole word value
#define MIDI_NUMBER_OF_TRACKS
static const uint16_t bitrate_table[15][6] PROGMEM
bitrate lookup table
int8_t irq
External reference to the interrupt identifier for MP3_DREQ.
bool isFnMusic(char *filename)
is the filename music
#define MIDI_EVENT_NOTE_OFF
#define MIDI_EVENT_NOTE_ON
#define MIDI_TIME_DIVISION
#define MIDI_HDR_CHUNK_ID
#define MIDI_END_OF_TRACK
PROGMEM const uint8_t SingleMIDInoteFile[]
a MIDI File of one Note
char * strip_nonalpha_inplace(char *s)
chomp non printable characters out of string.
#define MIDI_TRACK_CHUNK_ID
Header file for the vs1053_avr_renesas_uno library.
#define para_playSpeed
A macro of the WRAM para_playSpeed register's address (R/W)
#define SCI_AICTRL0
A macro of the SCI AICTRL[x] register's address (R/W)
#define SM_LINE1
A macro of the SM_LINE1 bit mask of the SCI_MODE register.
#define para_MonoOutput
A macro of the WRAM para_MonoOutput register's address (R/W)
#define SCI_BASS
A macro of the SCI BASS register's address (R/W)
#define TRACK_TITLE
A macro of the offset for the track's Title.
state_m
State of the vs1053 device.
#define para_byteRate
A macro of the WRAM para_byteRate register's address (R/W)
#define SCI_CLOCKF
A macro of the SCI CLOCKF register's address (R/W)
int8_t irq
External reference to the interrupt identifier for MP3_DREQ.
#define TRACK_ARTIST
A macro of the offset for the track's Artist.
#define SCI_HDAT0
A macro of the SCI HDAT0 register's address (R/W)
#define para_endFillByte
A macro of the WRAM para_endFillByte register's address (R/W)
#define SM_EARSPEAKER_HI
A macro of the SM_EARSPEAKER_HI bit mask of the SCI_MODE register.
#define SCI_AICTRL3
A macro of the SCI AICTRL[x] register (R/W)
#define SS_VU_ENABLE
A macro of the SS_VU_ENABLE bit mask of the SCI_STATUS register.
#define SCI_AIADDR
A macro of the SCI AIADDR register's address (R/W)
#define SCI_HDAT1
A macro of the SCI HDAT1 register's address (R/W)
#define SM_RESET
A macro of the SM_DIFF bit mask of the SM_RESET register.
#define SM_CANCEL
A macro of the SM_DIFF bit mask of the SCI_MODE register.
char * strip_nonalpha_inplace(char *s)
chomp non printable characters out of string.
#define SCI_VOL
A macro of the SCI VOL register's address (R/W)
#define SM_EARSPEAKER_LO
A macro of the SM_EARSPEAKER_LO bit mask of the SCI_MODE register.
#define SM_TESTS
A macro of the SM_TESTS bit mask of the SCI_MODE register.
#define SM_SDINEW
A macro of the SM_SDINEW bit mask of the SCI_MODE register.
flush_m
How to flush the VSdsp's buffer.
@ both
Flush both First and After.
#define para_version
A macro of the WRAM para_version register's address (R/W)
#define SCI_STATUS
A macro of the SCI STATUS register's address (R/W)
#define SCI_DECODE_TIME
A macro of the SCI Decode Time register's address (R/W)
#define SM_DIFF
A macro of the SM_DIFF bit mask of the SCI_MODE register.
#define TRACK_ALBUM
A macro of the offset for the track's Album.
#define SCI_WRAMADDR
A macro of the SCI WRAMADDR register (W)
#define SCI_MODE
A macro of the SCI MODE register's address (R/W)
#define SCI_WRAM
A macro of the SCI WRAM register's address (R/W)
#define PERF_MON_PIN
A macro to configure a Pin to analyze performance.
#define MP3_DREQ
A macro to configure the DREQ pin.
#define MP3_RESET
A macro to configure the RESET pin.
#define MP3_XCS
A macro to configure the XCS pin.
#define MP3_XDCS
A macro to configure the XDCS pin.