13 #include <avr/pgmspace.h> 25 static const uint16_t bitrate_table[15][6]
PROGMEM = {
27 { 32, 32, 32, 32, 8, 8},
28 { 64, 48, 40, 48, 16, 16},
29 { 96, 56, 48, 56, 24, 24},
30 {128, 64, 56, 64, 32, 32},
31 {160, 80, 64, 80, 40, 40},
32 {192, 96, 80, 96, 48, 48},
33 {224,112, 96,112, 56, 56},
34 {256,128,112,128, 64, 64},
35 {288,160,128,144, 80, 80},
36 {320,192,160,160, 96, 69},
37 {352,224,192,176,112,112},
38 {384,256,224,192,128,128},
39 {416,320,256,224,144,144},
40 {448,384,320,256,160,160}
47 #define MIDI_NOTE_ON 9 48 #define MIDI_NOTE_OFF 8 52 #define MIDI_HDR_CHUNK_ID 0x4D, 0x54, 0x68, 0x64 // const for MIDI 53 #define MIDI_CHUNKSIZE 0, 0, 0, 6 54 #define MIDI_FORMAT 0, 0 // VSdsp only support Format 0! 55 #define MIDI_NUMBER_OF_TRACKS 0, 1 // ergo must be 1 track 56 #define MIDI_TIME_DIVISION 0, 96 58 #define MIDI_TRACK_CHUNK_ID 0x4D, 0x54, 0x72, 0x6B // const for MIDI 59 #define MIDI_CHUNK_SIZE 0, 0, 0, sizeof(MIDI_EVENT_NOTE_ON) + sizeof(MIDI_EVENT_NOTE_OFF) + sizeof(MIDI_END_OF_TRACK) // hard coded with zero padded 61 #define MIDI_EVENT_NOTE_ON 0, (MIDI_NOTE_ON<<4) + MIDI_CHANNEL, MIDI_NOTE_NUMBER, MIDI_INTENSITY 62 #define MIDI_EVENT_NOTE_OFF MIDI_NOTE_DURATION, (MIDI_NOTE_OFF<<4) + MIDI_CHANNEL, MIDI_NOTE_NUMBER, MIDI_INTENSITY 64 #define MIDI_END_OF_TRACK 0, 0xFF, 0x2F, 0 105 #if defined(USE_MP3_REFILL_MEANS) && USE_MP3_REFILL_MEANS == USE_MP3_SimpleTimer 141 if (int8_t(
sd.vol()->fatType()) == 0) {
142 Serial.println(F(
"If you get this error, you likely do not have a sd.begin in the main sketch, See Trouble Shooting Guide!"));
143 Serial.println(F(
"http://mpflaga.github.com/Sparkfun-MP3-Player-Shield-Arduino-Library/#Troubleshooting"));
152 #if PERF_MON_PIN != -1 168 #if defined(USE_MP3_REFILL_MEANS) && USE_MP3_REFILL_MEANS == USE_MP3_Timer1 169 Timer1.initialize(MP3_REFILL_PERIOD);
170 #elif defined(USE_MP3_REFILL_MEANS) && USE_MP3_REFILL_MEANS == USE_MP3_SimpleTimer 171 timerId_mp3 = timer.setInterval(MP3_REFILL_PERIOD,
refill);
172 timer.disable(timerId_mp3);
272 #if (F_CPU == 16000000 ) 285 if(MP3Clock != 0x6000)
return 5;
338 if(!
track.open(fileName, O_READ))
return 2;
346 if(n.
word & 0x8000U) {
392 Serial.println(F(
"Warning Tests are not available."));
403 for(
int y = 0 ; y <= 1 ; y++) {
443 Serial.println(F(
"Warning Tests are not available."));
498 Serial.println(F(
"Warning Tests are not available."));
707 else if(frequency > 15)
734 else if(amplitude > 7)
762 else if(frequency > 15)
792 else if(amplitude > 15)
892 if(EarSpeaker & 0b01) {
898 if(EarSpeaker & 0b10) {
1028 char trackName[] =
"track001.mp3";
1029 uint8_t trackNumber = 1;
1032 sprintf(trackName,
"track%03d.mp3", trackNo);
1072 if(!
track.open(fileName, O_READ))
return 2;
1075 int fileNamefileName_length = 0;
1076 while(*(fileName + fileNamefileName_length))
1077 fileNamefileName_length++;
1081 if(strstr(strlwr(fileName),
"mp3") ) {
1471 uint32_t currentPos =
track.curPosition();
1474 track.seekEnd((-128 + offset));
1477 track.read(infobuffer, 30);
1481 track.seekSet(currentPos);
1508 Serial.print(F(
"HDAT1"));
1509 Serial.print(F(
"\tHDAT0"));
1510 Serial.print(F(
"\tVOL"));
1511 Serial.print(F(
"\tMode"));
1512 Serial.print(F(
"\tStatus"));
1513 Serial.print(F(
"\tClockF"));
1514 Serial.print(F(
"\tpversion"));
1515 Serial.print(F(
"\t[Bytes/S]"));
1516 Serial.print(F(
"\t[KBits/S]"));
1517 Serial.print(F(
"\tPlaySpeed"));
1518 Serial.print(F(
"\tDECODE_TIME"));
1519 Serial.print(F(
"\tCurrentPos"));
1524 Serial.print(F(
"0x"));
1525 Serial.print(MP3HDAT1, HEX);
1528 Serial.print(F(
"\t0x"));
1529 Serial.print(MP3HDAT0, HEX);
1532 Serial.print(F(
"\t0x"));
1533 Serial.print(MP3SCI_VOL, HEX);
1536 Serial.print(F(
"\t0x"));
1537 Serial.print(MP3Mode, HEX);
1540 Serial.print(F(
"\t0x"));
1541 Serial.print(MP3Status, HEX);
1544 Serial.print(F(
"\t0x"));
1545 Serial.print(MP3Clock, HEX);
1548 Serial.print(F(
"\t0x"));
1549 Serial.print(MP3para_version, HEX);
1552 Serial.print(F(
"\t\t"));
1553 Serial.print(MP3ByteRate, HEX);
1555 Serial.print(F(
"\t\t"));
1556 Serial.print((MP3ByteRate>>7), DEC);
1559 Serial.print(F(
"\t\t"));
1560 Serial.print(MP3playSpeed, HEX);
1563 Serial.print(F(
"\t\t"));
1564 Serial.print(MP3SCI_DECODE_TIME, DEC);
1566 Serial.print(F(
"\t\t"));
1593 for(uint16_t i = 0; i<65535; i++) {
1594 if(
track.read() == 0xFF) {
1596 temp =
track.read();
1598 if(((temp & 0b11100000) == 0b11100000) && ((temp & 0b00000110) != 0b00000000)) {
1602 if(!(temp & 0b00001000)) {
1605 else if((temp & 0b00000110) == 0b00000100) {
1608 else if((temp & 0b00000110) == 0b00000010) {
1616 temp =
track.read();
1620 bitrate = pgm_read_word_near ( &(bitrate_table[temp][row_num]) );
1729 SPI.setBitOrder(MSBFIRST);
1730 SPI.setDataMode(SPI_MODE0);
1829 SPI.transfer(addressbyte);
1830 SPI.transfer(highbyte);
1831 SPI.transfer(lowbyte);
1874 SPI.transfer(addressbyte);
1876 resultvalue.
byte[1] = SPI.transfer(0xFF);
1878 resultvalue.
byte[0] = SPI.transfer(0xFF);
1891 return resultvalue.
word;
1906 unsigned short int tmp1,tmp2;
1918 if(tmp1==tmp2)
return tmp1;
1922 if(tmp1==tmp2)
return tmp1;
1926 if(tmp1==tmp2)
return tmp1;
1954 #if defined(USE_MP3_REFILL_MEANS) && USE_MP3_REFILL_MEANS == USE_MP3_SimpleTimer 1956 #elif defined(USE_MP3_REFILL_MEANS) && USE_MP3_REFILL_MEANS == USE_MP3_Polled 1978 #if PERF_MON_PIN != -1 1983 #if !defined(USE_MP3_REFILL_MEANS) || USE_MP3_REFILL_MEANS == USE_MP3_INTx 2005 #if !defined(USE_MP3_REFILL_MEANS) || USE_MP3_REFILL_MEANS == USE_MP3_INTx 2016 #if !defined(USE_MP3_REFILL_MEANS) || USE_MP3_REFILL_MEANS == USE_MP3_INTx 2021 #if PERF_MON_PIN != -1 2052 #if !defined(USE_MP3_REFILL_MEANS) || USE_MP3_REFILL_MEANS == USE_MP3_INTx 2066 #if !defined(USE_MP3_REFILL_MEANS) || USE_MP3_REFILL_MEANS == USE_MP3_INTx 2084 #if defined(USE_MP3_REFILL_MEANS) && USE_MP3_REFILL_MEANS == USE_MP3_Timer1 2085 Timer1.attachInterrupt(
refill );
2086 #elif defined(USE_MP3_REFILL_MEANS) && USE_MP3_REFILL_MEANS == USE_MP3_SimpleTimer 2087 timer.enable(timerId_mp3);
2088 #elif !defined(USE_MP3_REFILL_MEANS) || USE_MP3_REFILL_MEANS == USE_MP3_INTx 2102 #if defined(USE_MP3_REFILL_MEANS) && USE_MP3_REFILL_MEANS == USE_MP3_Timer1 2103 Timer1.detachInterrupt();
2104 #elif defined(USE_MP3_REFILL_MEANS) && USE_MP3_REFILL_MEANS == USE_MP3_SimpleTimer 2105 timer.disable(timerId_mp3);
2106 #elif !defined(USE_MP3_REFILL_MEANS) || USE_MP3_REFILL_MEANS == USE_MP3_INTx 2131 if((mode ==
post) || (mode ==
both)) {
2134 for(
int y = 0 ; y < 2052 ; y++) {
2136 SPI.transfer(endFillByte);
2141 for (
int n = 0; n < 64 ; n++)
2147 for(
int y = 0 ; y < 32 ; y++) {
2149 SPI.transfer(endFillByte);
2156 if((mode ==
pre) || (mode ==
both)) {
2158 for(
int y = 0 ; y < 2052 ; y++) {
2160 SPI.transfer(endFillByte);
2212 #if defined(VS_LINE1_MODE) 2241 if((ADM_volume > -3) || (-31 > ADM_volume)) {
2243 MP3AIADDR.
word = 0x0F01;
2248 MP3AICTRL0.
byte[1] = (uint8_t) ADM_volume;
2249 MP3AICTRL0.
byte[0] = (uint8_t) ADM_volume;
2253 MP3AIADDR.
word = 0x0F00;
2270 for ( ; *s && !isalpha(*s); ++s)
2275 char *tail = s + strlen(s);
2276 for ( ; !isalpha(*tail); --tail)
2292 int8_t len = strlen(filename);
2294 if ( strstr(strlwr(filename + (len - 4)),
".mp3")
2295 || strstr(strlwr(filename + (len - 4)),
".aac")
2296 || strstr(strlwr(filename + (len - 4)),
".wma")
2297 || strstr(strlwr(filename + (len - 4)),
".wav")
2298 || strstr(strlwr(filename + (len - 4)),
".fla")
2299 || strstr(strlwr(filename + (len - 4)),
".mid")
#define para_MonoOutput
A macro of the WRAM para_MonoOutput register's address (R/W)
bool isFnMusic(char *filename)
is the filename music
#define para_playSpeed
A macro of the WRAM para_playSpeed register's address (R/W)
void setEarSpeaker(uint16_t)
Set the current Spatial EarSpeaker setting of the VS10xx chip.
uint16_t memoryTest()
Perform Memory Test.
#define SCI_AICTRL3
A macro of the SCI AICTRL[x] register (R/W)
uint8_t VolL
contains a local value of the VSdsp's master volume left channels
uint8_t playTrack(uint8_t)
Begin playing a mp3 file, just with a number.
#define TRACK_TITLE
A macro of the offset for the track's Title.
#define SM_CANCEL
A macro of the SM_DIFF bit mask of the SCI_MODE register.
#define MP3_XCS
A macro to configure the XCS pin.
uint8_t bitrate
contains a local value of the beleived current bit-rate.
static const uint16_t bitrate_table [15][6] PROGMEM
bitrate lookup table
#define SCI_WRAMADDR
A macro of the SCI WRAMADDR register (W)
uint16_t word
whole word value
state_m getState()
Get the current state of the device.
void trackArtist(char *)
Get Track's Artist.
#define MIDI_TRACK_CHUNK_ID
#define SCI_AIADDR
A macro of the SCI AIADDR register's address (R/W)
uint8_t getDifferentialOutput()
Get the current SM_DIFF setting from the VS10xx chip.
void SendSingleMIDInote()
Play hardcoded MIDI file.
struct vs1053::sci_bass_m::@0 nibble
individual Nibbles
static state_m playing_state
Boolean flag indicating if filehandle is streaming.
void setBassAmplitude(uint8_t)
Set the current Bass Boost amplitude in VS10xx chip.
static void available()
Public interface of refill.
uint8_t skip(int32_t)
Skips to a duration in the track.
void setBassFrequency(uint16_t)
Set the current Bass Boost Frequency limit cutoff in VS10xx chip.
void getTrackInfo(uint8_t, char *)
Fetch ID3 Tag information.
PROGMEM const uint8_t SingleMIDInoteFile[]
a MIDI File of one Note
#define para_endFillByte
A macro of the WRAM para_endFillByte register's address (R/W)
void setMonoMode(uint16_t)
Set the current Stereo/Mono setting of the VS10xx output.
uint16_t word
whole word value
uint16_t getTrebleFrequency()
Get the current Treble Frequency limit from the VS10xx chip.
#define SM_TESTS
A macro of the SM_TESTS bit mask of the SCI_MODE register.
uint16_t getVolume()
Get the current volume from the VS10xx chip.
static void disableRefill()
Disable the Interrupts for refill.
static uint16_t Mp3ReadWRAM(uint16_t)
Read a VS10xx WRAM Location.
flush_m
How to flush the VSdsp's buffer.
#define SCI_WRAM
A macro of the SCI WRAM register's address (R/W)
int8_t setVUmeter(int8_t)
enable VSdsp VU Meter
void setTrebleAmplitude(int8_t)
Set the current Treble Amplitude in VS10xx chip.
uint8_t vs_init()
Initialize the VS10xx Audio Decoder Chip.
#define MIDI_NUMBER_OF_TRACKS
uint8_t skipTo(uint32_t)
Skips to a certain point in the track.
int16_t getVUlevel()
get current measured VU Meter
#define SM_LINE1
A macro of the SM_LINE1 bit mask of the SCI_MODE register.
uint16_t getPlaySpeed()
Get the current playSpeed from the VS10xx chip.
uint32_t currentPosition()
Current timecode in ms.
uint8_t enableTestSineWave(uint8_t)
Generate Test Sine wave.
#define SCI_DECODE_TIME
A macro of the SCI Decode Time register's address (R/W)
void setPlaySpeed(uint16_t)
Set the current playSpeed of the VS10xx chip.
#define SM_EARSPEAKER_HI
A macro of the SM_EARSPEAKER_HI bit mask of the SCI_MODE register.
#define MIDI_EVENT_NOTE_OFF
static void dcs_high()
Deselect Data Channel.
void setBitRate(uint16_t)
Force bit rate.
#define SCI_MODE
A macro of the SCI MODE register's address (R/W)
#define SCI_STATUS
A macro of the SCI STATUS register's address (R/W)
static void dcs_low()
Select Data Channel.
uint32_t start_of_music
contains a filehandles offset to the begining of the current file.
int8_t getVUmeter()
get the status of the VSdsp VU Meter
#define PERF_MON_PIN
A macro to configure a Pin to analyze performance.
state_m
State of the vs1053 device.
static uint16_t spi_Read_Rate
Rate of the SPI to be used with communicating to the VSdsp.
static void spiInit()
Initialize the SPI for VS10xx use.
void resumeDataStream()
Unpause streaming data to the VSdsp.
void getBitRateFromMP3File(char *)
Read the Bit-Rate from the current track's filehandle.
#define para_byteRate
A macro of the WRAM para_byteRate register's address (R/W)
uint8_t VSLoadUserCode(char *)
load VS1xxx with patch or plugin from file on SDcard.
static uint16_t Mp3ReadRegister(uint8_t)
Read a VS10xx register.
#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.
uint8_t VolR
contains a local value of the VSdsp's master volume Right channels
uint8_t isPlaying()
Inidicate if a song is playing?
uint8_t disableTestSineWave()
Disable Test Sine wave.
static void cs_low()
Select Control Channel.
#define SCI_AICTRL0
A macro of the SCI AICTRL[x] register's address (R/W)
void pauseDataStream()
Pause streaming data to the VSdsp.
static uint8_t mp3DataBuffer[32]
Buffer for moving data between Filehandle and VSdsp.
#define MIDI_TIME_DIVISION
Flush both First and After.
void ADMixerVol(int8_t)
Set ADMixer's attenuation of input to between -3 and -31 dB otherwise disable.
static void enableRefill()
Enable the Interrupts for refill.
#define para_version
A macro of the WRAM para_version register's address (R/W)
void setTrebleFrequency(uint16_t)
Set the current treble frequency limit in VS10xx chip.
uint16_t getMonoMode()
Get the current Stereo/Mono setting of the VS10xx output.
#define MIDI_EVENT_NOTE_ON
void end()
Disables the MP3 Player shield.
char * strip_nonalpha_inplace(char *s)
chomp non printable characters out of string.
void getAudioInfo()
Display various Audio information from the VSdsp.
#define SM_EARSPEAKER_LO
A macro of the SM_EARSPEAKER_LO bit mask of the SCI_MODE register.
bool resumeMusic()
Resume music from where it was paused.
static void Mp3WriteWRAM(uint16_t, uint16_t)
Write a VS10xx WRAM Location.
#define MP3_DREQINT
A macro to configure the DREQINT pin.
static void cs_high()
Deselect Control Channel.
static void flush_cancel(flush_m)
flush the VSdsp buffer and cancel
int8_t getTrebleAmplitude()
Get the current Treble Amplitude from the VS10xx chip.
A handler for accessing bytes of a word.
#define MP3_RESET
A macro to configure the RESET pin.
#define MIDI_HDR_CHUNK_ID
#define SS_VU_ENABLE
A macro of the SS_VU_ENABLE bit mask of the SCI_STATUS register.
#define SCI_BASS
A macro of the SCI BASS register's address (R/W)
void trackTitle(char *)
Get Track's Title.
static SdFile track
Initializer for the instance of the SdCard's static member.
uint8_t byte[2]
individual bytes
#define SM_DIFF
A macro of the SM_DIFF bit mask of the SCI_MODE register.
uint8_t playMP3(char *, uint32_t timecode=0)
Begin playing a mp3 file by its filename.
static uint16_t spi_Write_Rate
#define MP3_XDCS
A macro to configure the XDCS pin.
uint8_t getEarSpeaker()
Get the current Spatial EarSpeaker setting from the VS10xx chip.
#define TRACK_ALBUM
A macro of the offset for the track's Album.
#define MIDI_END_OF_TRACK
void trackAlbum(char *)
Get Track's Album.
static void Mp3WriteRegister(uint8_t, uint8_t, uint8_t)
Write a value a VSDsp's register.
void pauseMusic()
Pause music.
#define SM_SDINEW
A macro of the SM_SDINEW bit mask of the SCI_MODE register.
uint8_t ADMixerLoad(char *)
Initially load ADMixer patch and configure line/mic mode.
#define SCI_VOL
A macro of the SCI VOL register's address (R/W)
void setVolume(uint8_t, uint8_t)
Store and Push member volume to VS10xx chip.
static void refill()
Refill the VS10xx buffer with new data.
void stopTrack()
Gracefully close track and cancel refill.
int8_t getBassAmplitude()
Get the current Bass boost amplitude from the VS10xx chip.
uint8_t begin()
Initialize the MP3 Player shield.
#define TRACK_ARTIST
A macro of the offset for the track's Artist.
#define MP3_DREQ
A macro to configure the DREQ pin.
uint16_t getBassFrequency()
Get the current Bass Frequency limit from the VS10xx chip.
A handler for accessing nibbles of the SCI_BASS word.
#define SCI_CLOCKF
A macro of the SCI CLOCKF register's address (R/W)
void setDifferentialOutput(uint16_t)
Set the current SM_DIFF setting of the VS10xx chip.
#define SCI_HDAT0
A macro of the SCI HDAT0 register's address (R/W)