Skip to content

Commit a51eca8

Browse files
committed
m4a player example
1 parent 602e57b commit a51eca8

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* @file player-sd-i2s.ino
3+
* @brief example using the SD library that shows how to support m4a
4+
* aac, mp3 and alac files. We provid a MultiDecoder to the ContainerM4A
5+
* so that the container can decode aac and alac. We also provide it to
6+
* the AudioPlayer so that we can play aac, alac, mp4 and m4a files. If
7+
* you only want to play m4a files, you can provide the ContainerM4A directly.
8+
*
9+
* @author Phil Schatzmann
10+
* @copyright GPLv3
11+
*/
12+
13+
#include "AudioTools.h"
14+
#include "AudioTools/Disk/AudioSourceSD.h"
15+
#include "AudioTools/AudioCodecs/CodecALAC.h"
16+
#include "AudioTools/AudioCodecs/CodecAACHelix.h"
17+
#include "AudioTools/AudioCodecs/CodecMP3Helix.h"
18+
#include "AudioTools/AudioCodecs/ContainerM4A.h"
19+
#include "AudioTools/AudioCodecs/MultiDecoder.h"
20+
#include "AudioTools/AudioLibs/AudioBoardStream.h" // install https://github.com/pschatzmann/arduino-audio-driver
21+
22+
23+
const char *startFilePath="/m4a";
24+
const char* ext="m4a";
25+
AudioSourceSD source(startFilePath, ext);
26+
AudioBoardStream i2s(AudioKitEs8388V1); // or e.g. I2SStream i2s;
27+
MultiDecoder multi_decoder;
28+
ContainerM4A dec_m4a(multi_decoder);
29+
AACDecoderHelix dec_aac;
30+
MP3DecoderHelix dec_mp3;
31+
DecoderALAC dec_alac;
32+
AudioPlayer player(source, i2s, multi_decoder);
33+
34+
35+
void setup() {
36+
Serial.begin(115200);
37+
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
38+
39+
// setup multi decoder
40+
multi_decoder.addDecoder(dec_m4a, "audio/m4a");
41+
multi_decoder.addDecoder(dec_alac,"audio/alac");
42+
multi_decoder.addDecoder(dec_aac,"audio/aac");
43+
multi_decoder.addDecoder(dec_mp3,"audio/mp3");
44+
45+
// setup output
46+
auto cfg = i2s.defaultConfig(TX_MODE);
47+
i2s.begin(cfg);
48+
49+
// setup player
50+
//source.setFileFilter("*Bob Dylan*");
51+
player.begin();
52+
}
53+
54+
void loop() {
55+
player.copy();
56+
}

0 commit comments

Comments
 (0)