Adafruit mp3
Adafruit_mp3.h
1 #ifndef LIB_ADAFRUIT_MP3_H
2 #define LIB_ADAFRUIT_MP3_H
3 
4 #include "Arduino.h"
5 #include "arm_math.h"
6 #include "mp3dec.h"
7 
8 //TODO: decide on a reasonable buffer size
9 #define OUTBUF_SIZE (16 * 1024)
10 #define INBUF_SIZE (16 * 1024)
11 
12 #define BUFFER_LOWER_THRESH (8 * 1024)
13 
14 #define MP3_TC TC2
15 #define MP3_IRQn TC2_IRQn
16 #define MP3_Handler TC2_Handler
17 #define MP3_GCLK_ID TC2_GCLK_ID
18 
20  volatile int count;
21  int16_t buffer[OUTBUF_SIZE];
22 };
23 
24 class Adafruit_mp3 {
25 public:
26  Adafruit_mp3() : hMP3Decoder() { inbufend = (inBuf + INBUF_SIZE); }
27  ~Adafruit_mp3() { MP3FreeDecoder(hMP3Decoder); };
28  bool begin();
29  void setBufferCallback(int (*fun_ptr)(uint8_t *, int));
30  void setSampleReadyCallback(void (*fun_ptr)(int16_t, int16_t));
31 
32  void play();
33  void stop();
34  void resume();
35 
36  int tick();
37 
38 private:
39  Tc *_tc;
40  HMP3Decoder hMP3Decoder;
41 
42  volatile int bytesLeft;
43  uint8_t *readPtr;
44  uint8_t *writePtr;
45  uint8_t inBuf[INBUF_SIZE];
46  uint8_t *inbufend;
47  bool playing = false;
48 
49  int (*bufferCallback)(uint8_t *, int);
50 
51 };
52 
53 #endif
void resume()
Resume playback. This function re-enables the playback timer. If you are starting playback of a new f...
Definition: Adafruit_mp3.cpp:165
void stop()
Stop playback. This function stops the playback timer.
Definition: Adafruit_mp3.cpp:153
Definition: Adafruit_mp3.h:19
Definition: Adafruit_mp3.h:24
int tick()
The main loop of the mp3 player. This function should be called as fast as possible in the loop() fun...
Definition: Adafruit_mp3.cpp:179
void setSampleReadyCallback(void(*fun_ptr)(int16_t, int16_t))
Set the function that the player will call when the playback timer fires. The callback is called insi...
Definition: Adafruit_mp3.cpp:121
void play()
Play an mp3 file. This function resets the buffers and should only be used when beginning playback of...
Definition: Adafruit_mp3.cpp:131
bool begin()
Begin the mp3 player. This initializes the playback timer and necessary interrupts.
Definition: Adafruit_mp3.cpp:61
void setBufferCallback(int(*fun_ptr)(uint8_t *, int))
Set the function the player will call when it's buffers need to be filled. Care must be taken to ensu...
Definition: Adafruit_mp3.cpp:106