Skip to content

Commit 15d5426

Browse files
committed
VS1053Stream
1 parent fe9af78 commit 15d5426

File tree

7 files changed

+369
-65
lines changed

7 files changed

+369
-65
lines changed

examples/examples-vs1053/basic-a2dp-vs1053/basic-a2dp-vs1053.ino

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,14 @@
77
* @copyright GPLv3
88
*/
99

10-
// install https://github.com/baldram/ESP_VS1053_Library.git
10+
// install https://github.com/pschatzmann/arduino-vs1053.git
1111

1212
#include "AudioTools.h"
1313
#include "AudioLibs/VS1053Stream.h"
1414
#include "BluetoothA2DPSink.h"
1515

16-
// example pins for an ESP32
17-
#define VS1053_CS 5
18-
#define VS1053_DCS 16
19-
#define VS1053_DREQ 4
20-
21-
2216
BluetoothA2DPSink a2dp_sink;
23-
VS1053Stream vs1053(VS1053_CS,VS1053_DCS, VS1053_DREQ); // final output
24-
EncodedAudioStream out(&vs1053, new WAVEncoder()); // output is WAV file
17+
VS1053Stream out; // final output
2518

2619
// Write data to SPDIF in callback
2720
void read_data_stream(const uint8_t *data, uint32_t length) {
@@ -44,9 +37,13 @@ void setup() {
4437
cfg.sample_rate = a2dp_sink.sample_rate();
4538
cfg.channels = 2;
4639
cfg.bits_per_sample = 16;
47-
out.begin(cfg);
40+
// Use your custom pins
41+
//cfg.cs_pin = VS1053_CS;
42+
//cfg.dcs_pin = VS1053_DCS;
43+
//cfg.dreq_pin = VS1053_DREQ;
44+
//cfg.reset_pin = VS1053_RESET;
4845

49-
vs1053.begin();
46+
out.begin(cfg);
5047
}
5148

5249
void loop() { delay(1000); }

examples/examples-vs1053/player-sd-vs1053/player-sd-vs1053.ino

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,38 @@
66
* @copyright GPLv3
77
*/
88

9-
// install https://github.com/baldram/ESP_VS1053_Library.git
9+
// install https://github.com/pschatzmann/arduino-vs1053.git
1010

1111
#include "AudioTools.h"
1212
#include "AudioLibs/VS1053Stream.h"
1313
#include "AudioLibs/AudioSourceSdFat.h"
1414
#include "AudioCodecs/CodecCopy.h"
1515

16-
#define VS1053_CS 5
17-
#define VS1053_DCS 16
18-
#define VS1053_DREQ 4
19-
#define SD_CARD_CS 13
20-
#define SD_CARD_MISO 2
21-
#define SD_CARD_MOSI 15
22-
#define SD_CARD_CLK 14
16+
#define SD_CARD_CS 13
2317

2418
const char *startFilePath="/";
2519
const char* ext="mp3";
2620
SdSpiConfig sdcfg(SD_CARD_CS, DEDICATED_SPI, SD_SCK_MHZ(10) , &SPI);
2721
AudioSourceSdFat source(startFilePath, ext, sdcfg);
28-
VS1053Stream vs1053(VS1053_CS,VS1053_DCS, VS1053_DREQ); // final output
29-
AudioPlayer player(source, vs1053, *new CodecCopy());
22+
VS1053Stream vs1053; // final output
23+
AudioPlayer player(source, vs1053, *new CopyDecoder());
3024

3125

3226
void setup() {
3327
Serial.begin(115200);
3428
AudioLogger::instance().begin(Serial, AudioLogger::Info);
3529

36-
SPI.begin(SD_CARD_CLK, SD_CARD_MISO, SD_CARD_MOSI, SD_CARD_CS);
30+
SPI.begin(SD_CARD_CS);
3731

3832
// setup output
39-
vs1053.begin();
33+
auto cfg = vs1053.defaultConfig();
34+
cfg.is_encoded_data = true; // vs1053 is accepting encoded data
35+
// Use your custom pins
36+
//cfg.cs_pin = VS1053_CS;
37+
//cfg.dcs_pin = VS1053_DCS;
38+
//cfg.dreq_pin = VS1053_DREQ;
39+
//cfg.reset_pin = VS1053_RESET;
40+
vs1053.begin(cfg);
4041

4142
// setup player
4243
player.setVolume(0.7);

examples/examples-vs1053/streams-generator-vs1053/streams-generator-vs1053.ino

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,17 @@
99
*
1010
*/
1111

12-
// install https://github.com/baldram/ESP_VS1053_Library.git
12+
// install https://github.com/pschatzmann/arduino-vs1053.git
1313

1414
#include "AudioTools.h"
1515
#include "AudioLibs/VS1053Stream.h"
1616

17-
// example pins for an ESP32
18-
#define VS1053_CS 5
19-
#define VS1053_DCS 16
20-
#define VS1053_DREQ 4
21-
2217
uint16_t sample_rate=44100;
2318
uint8_t channels = 2; // The stream will have 2 channels
2419
uint8_t bits_per_sample = 16; // 2 bytes
2520
SineWaveGenerator<int16_t> sineWave(32000); // subclass of SoundGenerator with max amplitude of 32000
2621
GeneratedSoundStream<int16_t> sound(sineWave); // Stream generated from sine wave
27-
VS1053Stream vs1053(VS1053_CS,VS1053_DCS, VS1053_DREQ); // final output
28-
EncodedAudioStream out(&vs1053, new WAVEncoder()); // output is WAV file
22+
VS1053Stream out; // VS1053 output
2923
StreamCopy copier(out, sound); // copy sound to decoder
3024

3125

@@ -41,10 +35,13 @@ void setup(){
4135
cfg.sample_rate = sample_rate;
4236
cfg.channels = channels;
4337
cfg.bits_per_sample = bits_per_sample;
38+
// Use your custom pins
39+
//cfg.cs_pin = VS1053_CS;
40+
//cfg.dcs_pin = VS1053_DCS;
41+
//cfg.dreq_pin = VS1053_DREQ;
42+
//cfg.reset_pin = VS1053_RESET;
4443
out.begin(cfg);
4544

46-
// setup vs1053
47-
vs1053.begin();
4845
}
4946

5047
void loop(){

examples/examples-vs1053/streams-url_mp3-vs1053/streams-url_mp3-vs1053.ino

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@
88
* @copyright Copyright (c) 2021
99
*/
1010

11-
// install https://github.com/baldram/ESP_VS1053_Library.git
11+
// install https://github.com/pschatzmann/arduino-vs1053.git
1212

1313
#include "AudioTools.h"
1414
#include "AudioLibs/VS1053Stream.h"
1515

16-
// example pins for an ESP32
17-
#define VS1053_CS 5
18-
#define VS1053_DCS 16
19-
#define VS1053_DREQ 4
20-
21-
2216
URLStream url("ssid","password"); // or replace with ICYStream to get metadata
2317
VS1053Stream vs1053(VS1053_CS,VS1053_DCS, VS1053_DREQ); // final output
2418
StreamCopy copier(vs1053, url); // copy url to decoder
2519

26-
2720
void setup(){
2821
Serial.begin(115200);
2922
AudioLogger::instance().begin(Serial, AudioLogger::Info);
3023

3124
// setup vs1053
32-
vs1053.begin();
25+
auto cfg = vs1053.defaultConfig();
26+
cfg.is_encoded_data = true; // vs1053 is accepting encoded data
27+
// Use your custom pins
28+
//cfg.cs_pin = VS1053_CS;
29+
//cfg.dcs_pin = VS1053_DCS;
30+
//cfg.dreq_pin = VS1053_DREQ;
31+
//cfg.reset_pin = VS1053_RESET;
32+
vs1053.begin(cfg);
3333

3434
// mp3 radio
3535
url.begin("http://stream.srg-ssr.ch/m/rsj/mp3_128","audio/mp3");

src/AudioCodecs/CodecCopy.h

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ namespace audio_tools {
1010
* @author Phil Schatzmann
1111
* @copyright GPLv3
1212
*/
13-
class CodecCopy : public AudioDecoder {
13+
class CopyDecoder : public AudioDecoder {
1414
public:
15-
CodecCopy() { LOGD(LOG_METHOD); }
15+
CopyDecoder() { LOGD(LOG_METHOD); }
1616

17-
CodecCopy(Print &out_stream) { LOGD(LOG_METHOD); pt_print=&out_stream; }
17+
CopyDecoder(Print &out_stream) { LOGD(LOG_METHOD); pt_print=&out_stream; }
1818

19-
CodecCopy(Print &out_stream, AudioBaseInfoDependent &bi) {pt_print=&out_stream;}
19+
CopyDecoder(Print &out_stream, AudioBaseInfoDependent &bi) {pt_print=&out_stream;}
2020

21-
~CodecCopy() {}
21+
~CopyDecoder() {}
2222

2323
virtual void setOutputStream(Print &out_stream) {pt_print=&out_stream;}
2424

@@ -38,5 +38,44 @@ class CodecCopy : public AudioDecoder {
3838
Print *pt_print=nullptr;
3939
};
4040

41+
/**
42+
* @brief Dummy Encoder which just copies the provided data to the output
43+
* @author Phil Schatzmann
44+
* @copyright GPLv3
45+
*/
46+
class CopyEncoder : public AudioEncoder {
47+
public:
48+
CopyEncoder() { LOGD(LOG_METHOD); }
49+
50+
CopyEncoder(Print &out_stream) { LOGD(LOG_METHOD); pt_print=&out_stream; }
51+
52+
CopyEncoder(Print &out_stream, AudioBaseInfoDependent &bi) {pt_print=&out_stream;}
53+
54+
~CopyEncoder() {}
55+
56+
virtual void setOutputStream(Print &out_stream) {pt_print=&out_stream;}
57+
58+
void begin() {}
59+
60+
void end() {}
61+
62+
AudioBaseInfo audioInfo() { return info; }
63+
void setAudioInfo(AudioBaseInfo ai) { info = ai; }
64+
65+
size_t write(const void *data, size_t len) { return pt_print->write((uint8_t*)data,len); }
66+
67+
operator bool() { return true; }
68+
69+
void setNotifyAudioChange(AudioBaseInfoDependent &bi) {}
70+
71+
const char *mime() {return nullptr;}
72+
73+
74+
protected:
75+
Print *pt_print=nullptr;
76+
AudioBaseInfo info;
77+
};
78+
79+
4180
} // namespace audio_tools
4281

src/AudioConfig.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,10 +428,18 @@ typedef uint32_t eps32_i2s_sample_rate_type;
428428
#define SOFT_MUTE_VALUE LOW
429429
#endif
430430

431-
//----------------
431+
//------ VS1053 ----------
432+
433+
#define VS1053_CS 27
434+
#define VS1053_DCS 14
435+
#define VS1053_DREQ 26
436+
#define VS1053_RESET -1
437+
#define VS1053_CS_SD 13
432438

433439

434-
#ifdef IS_DESKTOP
440+
//----------------
441+
442+
#ifdef IS_DESKTO
435443
#define USE_URL_ARDUINO
436444
#define FLUSH_OVERRIDE override
437445
#endif

0 commit comments

Comments
 (0)