Library for VLSI VS1053b - Ogg Vorbis / MP3 / AAC / WMA / FLAC / MIDI Audio Codec Chip for a complete sample see Lib_VS1053b
Dependents: Lab3_1 RTOS-VS1053b-mp3_semaphore RTOS-VS1053b-mp3_v01
Diff: VS1053.h
- Revision:
- 2:5bab956cb59e
- Parent:
- 1:ced2c297cc1b
- Child:
- 3:88a645490529
--- a/VS1053.h Thu Dec 16 21:54:03 2010 +0000 +++ b/VS1053.h Wed Dec 22 18:09:33 2010 +0000 @@ -26,25 +26,28 @@ * 2010-10-16 */ -#ifndef VS1053_H -#define VS1053_H - +#ifndef _VS1053_H +#define _VS1053_H // ---------------------------------------------------------------------------- // Extended settings // ---------------------------------------------------------------------------- // Enable debug output (Output -> printf ...) // -------------------------------------------------------------------------- -#define DEBUG +// #define DEBUG +// #define DEBUGOUT (x,y...) printf(x, ##y); // Patches, Addons // -------------------------------------------------------------------------- -//#define VS1053_PATCH_1_4_FLAC -//#define VS1053_PATCH_1_5 -#define VS1053_PATCH_1_5_FLAC -//#define VS1053_SPECANA -//#define VS1053B_PCM_RECORDER_0_9 +// #define VS1053_PATCH_1_4_FLAC +// #define VS1053_PATCH_1_5 +// #define VS1053_PATCH_1_5_FLAC +// #define VS1053_SPECANA +// #define VS1053B_PCM_RECORDER_0_9 // ---------------------------------------------------------------------------- +#include "defines.h" +#include "mbed.h" + #if defined(VS1053_PATCH_1_4_FLAC) && defined(VS1053_PATCH_1_5) && defined(VS1053_PATCH_1_5_FLAC) && defined(VS1053_SPECANA) && defined(VS1053B_PCM_RECORDER_0_9) #error "VS1053: Exclusive use of patch and app versions." #endif @@ -52,10 +55,17 @@ #define VS_PATCH #endif -#include "mbed.h" +#ifndef DEBUGOUT +#define DEBUGOUT(x,y...) +#endif + -#define DEFAULT_BALANCE_DIFERENCE_LEFT_RIGHT 0.0f -#define DEFAULT_VOLUME -40.0f +#define DEFAULT_BALANCE_DIFERENCE_LEFT_RIGHT 0.0f +#define DEFAULT_VOLUME -40.0f +#define DEFAULT_BASS_AMPLITUDE 5 // 0 - 15 dB +#define DEFAULT_BASS_FREQUENCY 100 // 20 - 150 Hz +#define DEFAULT_TREBLE_AMPLITUDE 0 // -8 - 7 dB +#define DEFAULT_TREBLE_FREQUENCY 15000 //1000 - 15000 Hz // SCI register address assignment #define SCI_MODE 0x0 @@ -95,20 +105,18 @@ #define SM_CLK_RANGE 0x8000 //SCI_CLOCKF register bits as of p.42 of the datasheet -#define SC_MULT_XTALI 0x0000 -#define SC_MULT_XTALIx20 0x2000 -#define SC_MULT_XTALIx25 0x4000 -#define SC_MULT_XTALIx30 0x6000 -#define SC_MULT_XTALIx35 0x8000 -#define SC_MULT_XTALIx40 0xA000 -#define SC_MULT_XTALIx45 0xC000 -#define SC_MULT_XTALIx50 0xE000 -// -#define SC_ADD_NOMOD 0x0000 -#define SC_ADD_10x 0x0800 -#define SC_ADD_15x 0x1000 -#define SC_ADD_20x 0x1800 - +#define SC_ADD_NOMOD 0x0000 +#define SC_ADD_10x 0x0800 +#define SC_ADD_15x 0x1000 +#define SC_ADD_20x 0x1800 +#define SC_MULT_XTALI 0x0000 +#define SC_MULT_XTALIx20 0x2000 +#define SC_MULT_XTALIx25 0x4000 +#define SC_MULT_XTALIx30 0x6000 +#define SC_MULT_XTALIx35 0x8000 +#define SC_MULT_XTALIx40 0xA000 +#define SC_MULT_XTALIx45 0xC000 +#define SC_MULT_XTALIx50 0xE000 // Extra Parameter in X memory (refer to p.58 of the datasheet) #define para_chipID_0 0x1E00 @@ -124,8 +132,41 @@ #define para_resync 0x1E29 -/** Class for VS1053 - Ogg Vorbis / MP3 / AAC / WMA / FLAC / MIDI Audio Codec Chip +/** Class for VS1053 - Ogg Vorbis / MP3 / AAC / WMA / FLAC / MIDI Audio Codec Chip. + * + * This code based on: + * mbeduino_MP3_Shield_MP3Player + * http://mbed.org/users/xshige/programs/mbeduino_MP3_Shield_MP3Player/lgcx63 + * 2010-10-16 + * + * For the use of this class, a file "defines.h" must be created. + * It controls debug output and vs1053 patches. * + * defines.h: + *@code + * #ifndef _DEFINES_H + * #define _DEFINES_H + * // ---------------------------------------------------------------------------- + * // debug output + * // ---------------------------------------------------------------------------- + * // optional + * #define DEBUG + * #ifdef DEBUG + * # define DEBUGOUT(x,y...) printf(x, ##y); + * #else + * # define DEBUGOUT(x,y...) + * #endif + * // ---------------------------------------------------------------------------- + * // VLSI VS1053b library, patch, apps + * // ---------------------------------------------------------------------------- + * // optional, ONLY ONE + * //#define VS1053_PATCH_1_4_FLAC + * //#define VS1053_PATCH_1_5 + * #define VS1053_PATCH_1_5_FLAC + * //#define VS1053_SPECANA + * //#define VS1053B_PCM_RECORDER_0_9 + * + * #endif //_DEFINES_H * */ class VS1053 { @@ -133,13 +174,20 @@ public: /** Create a vs1053b object. * - * @param mosi SPI Master Out, Slave In pin to vs1053b - * @param miso SPI Master In, Slave Out pin to vs1053b - * @param sck SPI Clock pin to vs1053b - * @param cs Pin to vs1053b control chip select - * @param rst Pin to vs1053b reset - * @param dreq Pin to vs1053b data request - * @param dcs Pin to vs1053b data chip select + * @param mosi + * SPI Master Out, Slave In pin to vs1053b. + * @param miso + * SPI Master In, Slave Out pin to vs1053b. + * @param sck + * SPI Clock pin to vs1053b. + * @param cs + * Pin to vs1053b control chip select. + * @param rst + * Pin to vs1053b reset. + * @param dreq + * Pin to vs1053b data request. + * @param dcs + * Pin to vs1053b data chip select. */ VS1053( PinName mosi, @@ -154,37 +202,113 @@ /** Reset the vs1053b. (hardware reset) * */ - void reset(void); - - void power_down(void); + void reset(void); - /** Write data stream to vs1053b + /** Write data stream to vs1053b. * - * @param data Data to be sent to vs1053b - * @param length Length of data + * @param data + * Data to be sent to vs1053b. + * @param length + * Length of data. */ void writeStream(unsigned char* data, unsigned int length); -#if 0 - void putcStream(unsigned char); -#endif //void stop(void); void terminateStream(void); - /** Initialize the vs1053b device + /** Initialize the vs1053b device. * - * @return + * @return + * TRUE on success, FALSE on failure. */ - bool initialize(void); + bool initialize(void); - void setVolume(float); + /** Set the volume. + * + * @param volume + * Volume -0.5dB, -1.0dB, .. -64.0dB. + */ + void setVolume(float volume = DEFAULT_VOLUME); + + /** Get the volume. + * + * @return + * Return the volume in dB. + */ float getVolume(); - void setBalance(float); + /** Set the balance - volume difference between left-right. + * + * @param balance + * Difference in dB. + */ + void setBalance(float balance = DEFAULT_BALANCE_DIFERENCE_LEFT_RIGHT); + + /** Get the balance - volume difference between left-right. + * + * @return + * Difference in dB. + */ float getBalance(); + + /** Get the treble frequency limit. + * + * @return + * Frequenzy 1000, 2000 .. 15000Hz. + */ + int getTrebleFrequency(void); + /** Set the treble frequency limit. + * + * @param frequency + * Frequenzy 1000, 2000, .. 15000Hz. + */ + void setTrebleFrequency(int frequency = DEFAULT_TREBLE_FREQUENCY); + /** Get the treble amplitude. + * + * @return + * Amplitude -8 .. 7dB (in 1.5dB steps); 0 = off. + */ + int getTrebleAmplitude(void); + /** Set the treble amplitude. + * + * @param amplitude + * Amplitude -8 .. 7dB (in 1.5dB steps); 0 = off. + */ + void setTrebleAmplitude(int amplitude = DEFAULT_TREBLE_AMPLITUDE); - void setPlaySpeed(unsigned short speed); + /** Get the bass frequency limit. + * + * @return + * Frequenzy 20, 30, .. 150Hz. + */ + int getBassFrequency(void); + /** Set the bass frequency limit. + * + * @param frequency + * Frequenzy 20, 30, .. 150Hz. + */ + void setBassFrequency(int frequency= DEFAULT_BASS_FREQUENCY); + + /** Get the bass amplitude. + * + * @return + * Amplitude 0 .. 15dB (in 1dB steps); 0 = off. + */ + int getBassAmplitude(void); + /** Set the bass amplitude. + * + * @param amplitude + * Amplitude 0 .. 15dB (in 1dB steps); 0 = off. + */ + void setBassAmplitude(int amplitude = DEFAULT_BASS_AMPLITUDE); + + /** Set the speed of a playback. + * + * @param speed + * Speed 0, 1, .. 4 (0, 1 normal speed). + */ + void setPlaySpeed(unsigned short speed); protected: unsigned short int wram_read(unsigned short int); @@ -212,15 +336,27 @@ void changeVolume(void); - SPI _spi; - DigitalOut _CS; - DigitalOut _DCS; - DigitalIn _DREQ; - DigitalOut _RST; + // TODO + void power_down(void); +#if 0 + void putcStream(unsigned char); +#endif + void changeBass(void); - // variables to save volume, values in db - float _balance; - float _volume; - + SPI _spi; + DigitalOut _CS; + DigitalOut _DCS; + DigitalIn _DREQ; + DigitalOut _RST; + + // variables to save + // volume, values in db + float _balance; + float _volume; + // bass enhancer settings + int _sb_amplitude; + int _sb_freqlimit; + int _st_amplitude; + int _st_freqlimit; }; #endif