VS1053  1.03.00
Arduino Library for VS10xx shield
vs1053_SdFat.h
Go to the documentation of this file.
1 
9 #ifndef vs1053_h
10 #define vs1053_h
11 
12 // include libraries:
13 #include "vs1053_SdFat_config.h"
14 #include "SPI.h"
15 
16 //Not neccessary, but just in case.
17 #if ARDUINO > 22
18 #include "Arduino.h"
19 #else
20 #include "WProgram.h"
21 #endif
22 
23 //Add the SdFat Libraries
24 #include <SdFat.h>
25 //#include <SdFatUtil.h>
26 
27 
33 enum state_m {
44  }; //enum state_m
45 
53 enum flush_m {
54 
61 
67  pre,
68 
75 
82  }; //enum flush_m
83 
84 //------------------------------------------------------------------------------
96 extern SdFat sd;
97 
102 //------------------------------------------------------------------------------
117 #define SCI_MODE 0x00
118 
125 #define SCI_STATUS 0x01
126 
134 #define SCI_BASS 0x02
135 
141 #define SCI_CLOCKF 0x03
142 
155 #define SCI_DECODE_TIME 0x04
156 
166 #define SCI_AUDATA 0x05
167 
178 #define SCI_WRAM 0x06
179 
186 #define SCI_WRAMADDR 0x07
187 
199 #define SCI_HDAT0 0x08
200 
211 #define SCI_HDAT1 0x09
212 
223 #define SCI_AIADDR 0x0A
224 
237 #define SCI_VOL 0x0B
238 
245 #define SCI_AICTRL0 0x0C
246 
253 #define SCI_AICTRL1 0x0D
254 
261 #define SCI_AICTRL2 0x0E
262 
269 #define SCI_AICTRL3 0x0F
270 
275 //------------------------------------------------------------------------------
287 #define SM_DIFF 0x0001
288 
296 #define SM_LAYER12 0x0002
297 
303 #define SM_RESET 0x0004
304 
313 #define SM_CANCEL 0x0008
314 
324 #define SM_EARSPEAKER_LO 0x0010
325 
335 #define SM_TESTS 0x0020
336 
342 #define SM_STREAM 0x0040
343 
354 #define SM_EARSPEAKER_HI 0x0080
355 
362 #define SM_DACT 0x0100
363 
373 #define SM_SDIORD 0x0200
374 
383 #define SM_SDISHARE 0x0400
384 
393 #define SM_SDINEW 0x0800
394 
401 #define SM_ADPCM 0x1000
402 
413 #define SM_PAUSE 0x2000 // note: Only availble with patch. This only quickly pauses the VS's internal buffer, when canceling quickly. It won't unpause.
414 
423 #define SM_LINE1 0x4000
424 
432 #define SM_CLK_RANGE 0x8000
433 
445 // configure Line1 as single ended, otherwise as differential 10x gain for microphones.
446 #define VS_LINE1_MODE
447 
448 
449 
454 //------------------------------------------------------------------------------
468 #define SS_VU_ENABLE 0x0200
469 
474 //------------------------------------------------------------------------------
489 #define para_chipID_0 0x1E00
490 
500 #define para_chipID_1 0x1E01
501 
510 #define para_version 0x1E02
511 
522 #define para_config1 0x1E03
523 
532 #define para_playSpeed 0x1E04
533 
546 #define para_byteRate 0x1E05
547 
561 #define para_endFillByte 0x1E06
562 
575 #define para_MonoOutput 0x1E09
576 
589 #define para_positionMsec_0 0x1E27
590 
602 #define para_positionMsec_1 0x1E28
603 
614 #define para_resync 0x1E29
615 
620 #define TRUE 1
621 #define FALSE 0
622 
623 //------------------------------------------------------------------------------
637 #define TRACK_TITLE 3
638 
646 #define TRACK_ARTIST 33
647 
655 #define TRACK_ALBUM 63
656 
661 //------------------------------------------------------------------------------
666 class vs1053 {
667  public:
668  uint8_t begin();
669  void end();
670  uint8_t vs_init();
671  void setVolume(uint8_t, uint8_t);
672  void setVolume(uint16_t);
673  void setVolume(uint8_t);
674  uint16_t getTrebleFrequency();
675  int8_t getTrebleAmplitude();
676  uint16_t getBassFrequency();
677  int8_t getBassAmplitude();
678  void setTrebleFrequency(uint16_t);
679  void setTrebleAmplitude(int8_t);
680  void setBassFrequency(uint16_t);
681  void setBassAmplitude(uint8_t);
682  void setPlaySpeed(uint16_t);
683  uint16_t getPlaySpeed();
684  uint16_t getVolume();
685  uint8_t getEarSpeaker();
686  state_m getState();
687  void setEarSpeaker(uint16_t);
688  uint16_t getMonoMode();
689  void setMonoMode(uint16_t );
690  void setDifferentialOutput(uint16_t);
691  uint8_t getDifferentialOutput();
692  uint8_t playTrack(uint8_t);
693  uint8_t playMP3(char*, uint32_t timecode = 0);
694  void trackTitle(char*);
695  void trackArtist(char*);
696  void trackAlbum(char*);
697  void stopTrack();
698  uint8_t isPlaying();
699  uint8_t skip(int32_t);
700  uint8_t skipTo(uint32_t);
701  uint32_t currentPosition();
702  void setBitRate(uint16_t);
703  void pauseDataStream();
704  void resumeDataStream();
705  void pauseMusic();
706  bool resumeMusic();
707  uint8_t resumeMusic(uint32_t);
708  static void available();
709  void getAudioInfo();
710  uint8_t enableTestSineWave(uint8_t);
711  uint8_t disableTestSineWave();
712  uint16_t memoryTest();
713  uint8_t ADMixerLoad(char*);
714  void ADMixerVol(int8_t);
715  int8_t getVUmeter();
716  int8_t setVUmeter(int8_t);
717  int16_t getVUlevel();
718  void SendSingleMIDInote();
719 
720  private:
721  static SdFile track;
722  static void refill();
723  static void flush_cancel(flush_m);
724  static void spiInit();
725  static void cs_low();
726  static void cs_high();
727  static void dcs_low();
728  static void dcs_high();
729  static void Mp3WriteRegister(uint8_t, uint8_t, uint8_t);
730  static void Mp3WriteRegister(uint8_t, uint16_t);
731  static uint16_t Mp3ReadRegister (uint8_t);
732  static uint16_t Mp3ReadWRAM(uint16_t);
733  static void Mp3WriteWRAM(uint16_t, uint16_t);
734  void getTrackInfo(uint8_t, char*);
735  static void enableRefill();
736  static void disableRefill();
737  void getBitRateFromMP3File(char*);
738  uint8_t VSLoadUserCode(char*);
739 
740  //Create the variables to be used by SdFat Library
741 
744 
746  static uint16_t spi_Read_Rate;
747  static uint16_t spi_Write_Rate;
748 
750  static uint8_t mp3DataBuffer[32];
751 
753  uint8_t bitrate;
754 
756  uint32_t start_of_music;
757 
759  uint8_t VolL;
760 
762  uint8_t VolR;
763 
770 union sci_bass_m {
771 
777  uint16_t word;
778 
784  struct {
785  uint8_t Bass_Freqlimt : 4; // 0..3
786  uint8_t Bass_Amplitude : 4; // 4..7
787  uint8_t Treble_Freqlimt : 4; // 8..11
788  int8_t Treble_Amplitude : 4; // 12..15
789  }nibble;
790  } ;
791 };
792 
793 //------------------------------------------------------------------------------
794 /*
795  * Global Functions
796  */
797 char* strip_nonalpha_inplace(char *s);
798 bool isFnMusic(char*);
799 
800 //------------------------------------------------------------------------------
801 /*
802  * Global Unions
803  */
804 
819 union twobyte {
820 
826  uint16_t word;
827 
834  uint8_t byte[2];
835 } ;
836 
837 #endif // vs1053_h
void setEarSpeaker(uint16_t)
Set the current Spatial EarSpeaker setting of the VS10xx chip.
uint16_t memoryTest()
Perform Memory Test.
uint8_t VolL
contains a local value of the VSdsp&#39;s master volume left channels
Definition: vs1053_SdFat.h:759
uint8_t playTrack(uint8_t)
Begin playing a mp3 file, just with a number.
uint8_t bitrate
contains a local value of the beleived current bit-rate.
Definition: vs1053_SdFat.h:753
Don&#39;t Flush.
Definition: vs1053_SdFat.h:81
uint16_t word
whole word value
Definition: vs1053_SdFat.h:777
state_m getState()
Get the current state of the device.
void trackArtist(char *)
Get Track&#39;s Artist.
SdFat sd
SdFat sd;.
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.
Definition: vs1053_SdFat.h:743
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.
void setMonoMode(uint16_t)
Set the current Stereo/Mono setting of the VS10xx output.
uint16_t word
whole word value
Definition: vs1053_SdFat.h:826
uint16_t getTrebleFrequency()
Get the current Treble Frequency limit from the VS10xx chip.
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&#39;s buffer.
Definition: vs1053_SdFat.h:53
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.
uint8_t skipTo(uint32_t)
Skips to a certain point in the track.
int16_t getVUlevel()
get current measured VU Meter
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.
void setPlaySpeed(uint16_t)
Set the current playSpeed of the VS10xx chip.
static void dcs_high()
Deselect Data Channel.
void setBitRate(uint16_t)
Force bit rate.
Flush First.
Definition: vs1053_SdFat.h:67
static void dcs_low()
Select Data Channel.
uint32_t start_of_music
contains a filehandles offset to the begining of the current file.
Definition: vs1053_SdFat.h:756
int8_t getVUmeter()
get the status of the VSdsp VU Meter
state_m
State of the vs1053 device.
Definition: vs1053_SdFat.h:33
static uint16_t spi_Read_Rate
Rate of the SPI to be used with communicating to the VSdsp.
Definition: vs1053_SdFat.h:746
static void spiInit()
Initialize the SPI for VS10xx use.
void resumeDataStream()
Unpause streaming data to the VSdsp.
Flush After.
Definition: vs1053_SdFat.h:60
void getBitRateFromMP3File(char *)
Read the Bit-Rate from the current track&#39;s filehandle.
uint8_t VSLoadUserCode(char *)
load VS1xxx with patch or plugin from file on SDcard.
static uint16_t Mp3ReadRegister(uint8_t)
Read a VS10xx register.
bool isFnMusic(char *)
is the filename music
uint8_t VolR
contains a local value of the VSdsp&#39;s master volume Right channels
Definition: vs1053_SdFat.h:762
uint8_t isPlaying()
Inidicate if a song is playing?
uint8_t disableTestSineWave()
Disable Test Sine wave.
static void cs_low()
Select Control Channel.
void pauseDataStream()
Pause streaming data to the VSdsp.
static uint8_t mp3DataBuffer[32]
Buffer for moving data between Filehandle and VSdsp.
Definition: vs1053_SdFat.h:750
Flush both First and After.
Definition: vs1053_SdFat.h:74
void ADMixerVol(int8_t)
Set ADMixer&#39;s attenuation of input to between -3 and -31 dB otherwise disable.
static void enableRefill()
Enable the Interrupts for refill.
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.
void end()
Disables the MP3 Player shield.
void getAudioInfo()
Display various Audio information from the VSdsp.
bool resumeMusic()
Resume music from where it was paused.
static void Mp3WriteWRAM(uint16_t, uint16_t)
Write a VS10xx WRAM Location.
Interface Driver to the VS10xx chip on the SPI.
Definition: vs1053_SdFat.h:666
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.
Definition: vs1053_SdFat.h:819
void trackTitle(char *)
Get Track&#39;s Title.
static SdFile track
Initializer for the instance of the SdCard&#39;s static member.
Definition: vs1053_SdFat.h:721
uint8_t playMP3(char *, uint32_t timecode=0)
Begin playing a mp3 file by its filename.
static uint16_t spi_Write_Rate
Definition: vs1053_SdFat.h:747
uint8_t getEarSpeaker()
Get the current Spatial EarSpeaker setting from the VS10xx chip.
void trackAlbum(char *)
Get Track&#39;s Album.
static void Mp3WriteRegister(uint8_t, uint8_t, uint8_t)
Write a value a VSDsp&#39;s register.
void pauseMusic()
Pause music.
uint8_t ADMixerLoad(char *)
Initially load ADMixer patch and configure line/mic mode.
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.
uint16_t getBassFrequency()
Get the current Bass Frequency limit from the VS10xx chip.
A handler for accessing nibbles of the SCI_BASS word.
Definition: vs1053_SdFat.h:770
char * strip_nonalpha_inplace(char *s)
chomp non printable characters out of string.
void setDifferentialOutput(uint16_t)
Set the current SM_DIFF setting of the VS10xx chip.