Skip to content

Commit b8735d8

Browse files
committed
VS1053 AudioPlayer
1 parent 5887076 commit b8735d8

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ void setup() {
3939
vs1053.setVolume(1.0); // full volume
4040

4141
// setup player
42-
player.setVolume(0.7); // we use volume control of the player
4342
player.begin();
4443

4544
// select file with setPath() or setIndex()

src/AudioCodecs/AudioEncoded.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class AudioDecoder : public AudioWriter, public AudioBaseInfoSource {
3131
setNotifyAudioChange(out_stream);
3232
}
3333
virtual void setOutputStream(Print &out_stream) = 0;
34+
// Th decoding result is PCM data
35+
virtual bool isResultPCM() { return true;}
3436
};
3537

3638
/**

src/AudioCodecs/CodecCopy.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ class CopyDecoder : public AudioDecoder {
3434

3535
void setNotifyAudioChange(AudioBaseInfoDependent &bi) {}
3636

37+
// The result is encoded data
38+
virtual bool isResultPCM() { return false;}
39+
3740
protected:
3841
Print *pt_print=nullptr;
3942
};

src/AudioTools/AudioPlayer.h

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,12 @@ namespace audio_tools {
8383
LOGD(LOG_METHOD);
8484
this->p_source = &source;
8585
this->p_decoder = &decoder;
86-
this->volume_out.setTarget(output);
87-
this->p_out_decoding = new EncodedAudioStream(volume_out, decoder);
86+
if (decoder.isResultPCM()){
87+
this->volume_out.setTarget(output);
88+
this->p_out_decoding = new EncodedAudioStream(volume_out, decoder);
89+
} else {
90+
this->p_out_decoding = new EncodedAudioStream(output, decoder);
91+
}
8892
this->p_final_print = &output;
8993

9094
// notification for audio configuration
@@ -104,8 +108,12 @@ namespace audio_tools {
104108
LOGD(LOG_METHOD);
105109
this->p_source = &source;
106110
this->p_decoder = &decoder;
107-
this->volume_out.setTarget(output);
108-
this->p_out_decoding = new EncodedAudioStream(volume_out, decoder);
111+
if (decoder.isResultPCM()){
112+
this->volume_out.setTarget(output);
113+
this->p_out_decoding = new EncodedAudioStream(volume_out, decoder);
114+
} else {
115+
this->p_out_decoding = new EncodedAudioStream(output, decoder);
116+
}
109117
setNotify(notify);
110118
}
111119

@@ -120,8 +128,12 @@ namespace audio_tools {
120128
AudioPlayer(AudioSource& source, AudioStream& output, AudioDecoder& decoder) {
121129
LOGD(LOG_METHOD);
122130
this->p_source = &source;
123-
this->volume_out.setTarget(output);
124-
this->p_out_decoding = new EncodedAudioStream(volume_out, decoder);
131+
if (decoder.isResultPCM()){
132+
this->volume_out.setTarget(output);
133+
this->p_out_decoding = new EncodedAudioStream(volume_out, decoder);
134+
} else {
135+
this->p_out_decoding = new EncodedAudioStream(output, decoder);
136+
}
125137
this->p_final_stream = &output;
126138

127139
// notification for audio configuration

0 commit comments

Comments
 (0)