arduino-audio-tools
Loading...
Searching...
No Matches
AudioPlayer.h
Go to the documentation of this file.
1#pragma once
2
3#include "AudioToolsConfig.h"
16
23namespace audio_tools {
24
52 public:
55
65 AudioPlayer(AudioSource& source, AudioOutput& output, AudioDecoder& decoder) {
66 TRACED();
67 this->p_source = &source;
68 this->p_decoder = &decoder;
69 setOutput(output);
70 // notification for audio configuration
71 decoder.addNotifyAudioChange(*this);
72 }
73
84 AudioPlayer(AudioSource& source, Print& output, AudioDecoder& decoder,
85 AudioInfoSupport* notify = nullptr) {
86 TRACED();
87 this->p_source = &source;
88 this->p_decoder = &decoder;
89 setOutput(output);
91 }
92
102 AudioPlayer(AudioSource& source, AudioStream& output, AudioDecoder& decoder) {
103 TRACED();
104 this->p_source = &source;
105 this->p_decoder = &decoder;
106 setOutput(output);
107 // notification for audio configuration
108 decoder.addNotifyAudioChange(*this);
109 }
110
112 AudioPlayer(AudioPlayer const&) = delete;
113
116
118 void setOutput(AudioOutput& output) {
119 if (p_decoder->isResultPCM()) {
120 this->fade.setOutput(output);
124 } else {
125 out_decoding.setOutput(&output);
127 }
128 this->p_final_print = &output;
129 this->p_final_stream = nullptr;
130 }
131
133 void setOutput(Print& output) {
134 if (p_decoder->isResultPCM()) {
135 this->fade.setOutput(output);
139 } else {
140 out_decoding.setOutput(&output);
142 }
143 this->p_final_print = nullptr;
144 this->p_final_stream = nullptr;
145 }
146
148 void setOutput(AudioStream& output) {
149 if (p_decoder->isResultPCM()) {
150 this->fade.setOutput(output);
154 } else {
155 out_decoding.setOutput(&output);
157 }
158 this->p_final_print = nullptr;
159 this->p_final_stream = &output;
160 }
161
163 void setBufferSize(int size) { copier.resize(size); }
164
166 bool begin(int index = 0, bool isActive = true) {
167 TRACED();
168 bool result = false;
169 // initilaize volume
170 if (current_volume == -1.0f) {
171 setVolume(1.0f);
172 } else {
174 }
175
176 // take definition from source
178
179 // initial audio info for fade from output when not defined yet
180 setupFade();
181
182 // start dependent objects
184
185 if (!p_source->begin()) {
186 LOGE("Could not start audio source");
187 return false;
188 }
189 if (!meta_out.begin()) {
190 LOGE("Could not start metadata output");
191 return false;
192 }
193 if (!volume_out.begin()) {
194 LOGE("Could not start volume control");
195 return false;
196 }
197
198 if (index >= 0) {
200 if (p_input_stream != nullptr) {
201 if (meta_active) {
203 }
207 result = true;
208 } else {
209 LOGW("-> begin: no data found");
210 active = false;
211 result = false;
212 }
213 } else {
214 LOGW("-> begin: no stream selected");
216 result = false;
217 }
218 return result;
219 }
220
222 void end() {
223 TRACED();
224 active = false;
225 eof_called = false;
227 meta_out.end();
228 // remove any data in the decoder
229 if (p_decoder != nullptr) {
230 LOGI("reset codec");
231 p_decoder->end();
232 p_decoder->begin();
233 }
234 }
235
238
240 void setAudioSource(AudioSource& source) { this->p_source = &source; }
241
243 void setDecoder(AudioDecoder& decoder) {
244 this->p_decoder = &decoder;
246 }
247
250 this->p_final_notify = notify;
251 // notification for audio configuration
252 if (p_decoder != nullptr) {
254 }
255 }
256
258 void setAudioInfo(AudioInfo info) override {
259 TRACED();
260 LOGI("sample_rate: %d", (int)info.sample_rate);
261 LOGI("bits_per_sample: %d", (int)info.bits_per_sample);
262 LOGI("channels: %d", (int)info.channels);
263 this->info = info;
264 // notifiy volume
267 // notifiy final ouput: e.g. i2s
271 };
272
274 AudioInfo audioInfo() override { return info; }
275
278 void play() {
279 TRACED();
280 setActive(true);
281 }
282
286 bool playPath(const char* path) {
287 TRACED();
288 if (!setPath(path)) {
289 LOGW("Could not open file: %s", path);
290 return false;
291 }
292
293 LOGI("Playing %s", path);
294 // start if inactive
295 play();
296 // process all data
297 copyAll();
298
299 LOGI("%s has finished playing", path);
300 return true;
301 }
302
304 bool playFile(const char* path) { return playPath(path); }
305
307 void stop() {
308 TRACED();
309 setActive(false);
310 }
311
331 void clearBuffers(bool drainSource = false) {
332 TRACED();
333 if (drainSource && p_input_stream != nullptr) {
334 // Snapshot once: a live source keeps receiving new bytes
335 // continuously, so re-checking available() after every read could
336 // never terminate - only discard what had already piled up up to
337 // this point. Anything that arrives during the drain is fresh
338 // ("now") data anyway, so leaving it for normal playback after
339 // resuming is correct, not a bug.
340 int remaining = p_input_stream->available();
341 uint8_t tmp[256];
342 while (remaining > 0) {
343 int to_read = min(remaining, (int)sizeof(tmp));
344 int got = p_input_stream->readBytes(tmp, to_read);
345 if (got <= 0) break; // stream stalled - stop rather than spin
346 remaining -= got;
347 }
348 }
349 if (p_decoder != nullptr) {
350 p_decoder->end();
351 p_decoder->begin();
352 }
353 }
354
356 bool next(int offset = 1) {
357 TRACED();
358 writeEnd();
359 stream_increment = offset >= 0 ? 1 : -1;
361 return active;
362 }
363
365 bool setIndex(int idx) {
366 TRACED();
367 writeEnd();
370 return active;
371 }
372
374 bool setPath(const char* path) {
375 TRACED();
376 writeEnd();
379 return active;
380 }
381
383 bool previous(int offset = 1) {
384 TRACED();
385 writeEnd();
386 stream_increment = -1;
387 active = setStream(p_source->previousStream(abs(offset)));
388 return active;
389 }
390
392 bool setStream(Stream* input) {
393 end();
395 p_input_stream = input;
396 eof_called = false; // reset EOF state for new stream
397 if (p_input_stream != nullptr) {
398 LOGD("open selected stream");
399 meta_out.begin();
401 }
402 // execute callback if defined
403 if (on_stream_change_callback != nullptr)
405 return p_input_stream != nullptr;
406 }
407
410
412 bool isActive() { return active; }
413
415 operator bool() { return isActive(); }
416
418 void setActive(bool isActive) {
419 if (is_auto_fade) {
420 if (isActive) {
421 fade.setFadeInActive(true);
422 } else {
424 copier.copy();
425 writeSilence(2048);
426 }
427 }
429 }
430
432 bool setVolume(float volume) override {
433 bool result = true;
434 if (volume >= 0.0f && volume <= 1.0f) {
435 if (abs(volume - current_volume) > 0.01f) {
436 LOGI("setVolume(%f)", volume);
439 }
440 } else {
441 LOGE("setVolume value '%f' out of range (0.0 -1.0)", volume);
442 result = false;
443 }
444 return result;
445 }
446
448 bool setVolume(float volume, int channel) {
449 return volume_out.setVolume(volume, channel);
450 }
451
453 float volume() override { return current_volume; }
454
456 float volume(int channel) { return volume_out.volume(channel); }
457
459 void setAutoNext(bool next) { autonext = next; }
460
462 void setDelayIfOutputFull(int delayMs) { delay_if_full = delayMs; }
463
466 size_t copy() { return copy(copier.bufferSize()); }
467
469 size_t copyAll() {
470 size_t result = 0;
471 size_t step = copy();
472 while (step > 0) {
473 result += step;
474 step = copy();
475 }
476 return result;
477 }
478
480 size_t copy(size_t bytes) {
481 size_t result = 0;
482 if (active) {
483 if (delay_if_full != 0 && ((p_final_print != nullptr &&
485 (p_final_stream != nullptr &&
487 // not ready to do anything - so we wait a bit
489 LOGD("copy: %d -> 0", (int)bytes);
490 return 0;
491 }
492
493 // handle sound
494 result = copier.copyBytes(bytes);
495 if (result > 0 || timeout == 0) {
496 // reset timeout if we had any data
498 }
499
500 // move to next stream after timeout
502
503 // return silence when there was no data
504 if (result < bytes && silence_on_inactive) {
505 writeSilence(bytes - result);
506 }
507
508 } else {
509 // e.g. A2DP should still receive data to keep the connection open
511 writeSilence(bytes);
512 }
513 }
514 LOGD("copy: %d -> %d", (int)bytes, (int)result);
515 return result;
516 }
517
520
524
527
530
532 void writeSilence(size_t bytes) {
533 TRACEI();
534 if (p_final_print != nullptr) {
536 } else if (p_final_stream != nullptr) {
538 }
539 }
540
543
546
548 bool isAutoFade() { return is_auto_fade; }
549
551 void setMetaDataSize(int size) { meta_out.resize(size); }
552
554 void setReference(void* ref) { p_reference = ref; }
555
557 void setMetadataCallback(void (*callback)(MetaDataType type, const char* str,
558 int len),
560 TRACEI();
561 // setup metadata.
562 if (p_source->setMetadataCallback(callback)) {
563 // metadata is handled by source
564 LOGI("Using ICY Metadata");
565 meta_active = false;
566 } else {
567 // metadata is handled here
568 meta_out.setCallback(callback);
569 meta_out.setFilter(sel);
570 meta_active = true;
571 }
572 }
573
575 void setOnStreamChangeCallback(void (*callback)(Stream* stream_ptr,
576 void* reference)) {
577 on_stream_change_callback = callback;
578 if (p_input_stream != nullptr) callback(p_input_stream, p_reference);
579 }
580
584 void setOnEOFCallback(void (*callback)(AudioPlayer& player)) {
585 on_eof_callback = callback;
586 }
587
589 bool setMuted(bool muted) {
590 if (muted) {
591 if (current_volume > 0.0f) {
593 setVolume(0.0f);
594 }
595 } else {
596 if (muted_volume > 0.0f) {
598 muted_volume = 0.0f;
599 }
600 }
601 return true;
602 }
603
605 bool isMuted() { return current_volume == 0.0f; }
606
607 protected:
608 bool active = false;
609 bool autonext = true;
612 VolumeStream volume_out; // Volume control
613 FadeStream fade; // Phase in / Phase Out to avoid popping noise
614 MetaDataID3 meta_out; // Metadata parser
622 StreamCopy copier; // copies sound into i2s
624 bool meta_active = false;
625 uint32_t timeout = 0;
626 int stream_increment = 1; // +1 moves forward; -1 moves backward
627 float current_volume = -1.0f; // illegal value which will trigger an update
628 float muted_volume = 0.0f;
629 int delay_if_full = 100;
630 bool is_auto_fade = true;
631 void* p_reference = nullptr;
633 void* reference) = nullptr;
634 // EOF callback and guard (invoked once when current stream reaches end)
635 void (*on_eof_callback)(AudioPlayer& player) = nullptr;
636 bool eof_called = false;
637
638 void setupFade() {
639 if (p_final_print != nullptr) {
641 } else if (p_final_stream != nullptr) {
643 }
644 }
645
647 if (p_final_stream != nullptr && p_final_stream->availableForWrite() == 0)
648 return;
649 if (p_input_stream == nullptr || millis() > timeout) {
651
652 // EOF callback: trigger once per stream
653 if (!eof_called) {
654 eof_called = true;
655 if (on_eof_callback != nullptr) {
656 on_eof_callback(*this);
657 }
658 }
659
660 if (autonext) {
661 LOGI("-> timeout - moving by %d", stream_increment);
662 // open next stream
663 if (!next(stream_increment)) {
664 LOGD("stream is null");
665 }
666 } else {
667 active = false;
668 }
670 }
671 }
672
673 void writeEnd() {
674 // end silently
675 TRACEI();
676 if (is_auto_fade) {
678 copier.copy();
679 // start by fading in
680 fade.setFadeInActive(true);
681 }
682 // restart the decoder to make sure it does not contain any audio when we
683 // continue
684 p_decoder->begin();
685 eof_called = false; // prepare for next stream
686 // Discard whatever of the just-faded-out stream is still sitting in the
687 // output's own buffer (e.g. an I2S DMA buffer) but not yet physically
688 // played. Without this, opening the next stream below can block for a
689 // while (file/network I/O), during which that leftover old-stream audio
690 // keeps playing out on its own - heard as a chunk of the previous track
691 // after the switch instead of a clean cut to the new one. No-op for
692 // outputs that don't support it.
693 if (p_final_print != nullptr) {
695 } else if (p_final_stream != nullptr) {
697 }
698 }
699
701 static void decodeMetaData(void* obj, void* data, size_t len) {
702 LOGD("%s, %zu", LOG_METHOD, len);
703 AudioPlayer* p = (AudioPlayer*)obj;
704 if (p->meta_active) {
705 p->meta_out.write((const uint8_t*)data, len);
706 }
707 }
708};
709
710} // namespace audio_tools
#define LOGW(...)
Definition AudioLoggerIDF.h:29
#define TRACEI()
Definition AudioLoggerIDF.h:32
#define TRACED()
Definition AudioLoggerIDF.h:31
#define LOGI(...)
Definition AudioLoggerIDF.h:28
#define LOGD(...)
Definition AudioLoggerIDF.h:27
#define LOGE(...)
Definition AudioLoggerIDF.h:30
#define LOG_METHOD
Definition AudioToolsConfig.h:69
Definition Arduino.h:56
Definition Arduino.h:136
virtual size_t readBytes(uint8_t *data, size_t len)
Definition Arduino.h:140
virtual int available()
Definition Arduino.h:139
Decoding of encoded audio into PCM data.
Definition AudioCodecsBase.h:19
virtual bool isResultPCM()
Returns true to indicate that the decoding result is PCM data.
Definition AudioCodecsBase.h:57
virtual bool begin(AudioInfo info) override
Definition AudioCodecsBase.h:58
void end() override
Definition AudioCodecsBase.h:63
virtual void addNotifyAudioChange(AudioInfoSupport &bi)
Adds target to be notified about audio changes.
Definition AudioTypes.h:150
Supports changes to the sampling rate, bits and channels.
Definition AudioTypes.h:132
virtual void setAudioInfo(AudioInfo info)=0
Defines the input AudioInfo.
Abstract Audio Ouptut class.
Definition AudioOutput.h:25
virtual int availableForWrite() override
Definition AudioOutput.h:38
virtual void setAudioInfo(AudioInfo newInfo) override
Defines the input AudioInfo.
Definition AudioOutput.h:49
virtual void flush()
Definition AudioOutput.h:42
virtual void writeSilence(size_t len)
Definition AudioOutput.h:66
virtual AudioInfo audioInfo() override
provides the actual input AudioInfo
Definition AudioOutput.h:62
High-level audio playback pipeline and controller.
Definition AudioPlayer.h:51
void setupFade()
Definition AudioPlayer.h:638
bool active
Definition AudioPlayer.h:608
void writeEnd()
Definition AudioPlayer.h:673
static void decodeMetaData(void *obj, void *data, size_t len)
Callback implementation which writes to metadata.
Definition AudioPlayer.h:701
void setOutput(Print &output)
Sets the final output to a Print (adds Volume/Fade for PCM)
Definition AudioPlayer.h:133
bool meta_active
Definition AudioPlayer.h:624
void setAudioSource(AudioSource &source)
Sets or replaces the AudioSource.
Definition AudioPlayer.h:240
int delay_if_full
Definition AudioPlayer.h:629
void writeSilence(size_t bytes)
Writes the requested number of zero bytes to the output.
Definition AudioPlayer.h:532
AudioOutput * p_final_print
Definition AudioPlayer.h:619
AudioPlayer(AudioSource &source, AudioStream &output, AudioDecoder &decoder)
Construct a new Audio Player object. The processing chain is AudioSource -> Stream-copy -> EncodedAud...
Definition AudioPlayer.h:102
AudioSource & audioSource()
Returns the active AudioSource.
Definition AudioPlayer.h:237
CopyDecoder no_decoder
Definition AudioPlayer.h:616
bool eof_called
Definition AudioPlayer.h:636
size_t copy(size_t bytes)
Copies the requested bytes from source to decoder (call in loop)
Definition AudioPlayer.h:480
int stream_increment
Definition AudioPlayer.h:626
size_t copyAll()
Copies until source is exhausted (blocking)
Definition AudioPlayer.h:469
void setSilenceOnInactive(bool active)
When enabled, writes zeros while inactive to keep sinks alive.
Definition AudioPlayer.h:526
bool isMuted()
Returns true if the player is currently muted.
Definition AudioPlayer.h:605
void moveToNextFileOnTimeout()
Definition AudioPlayer.h:646
void setOnEOFCallback(void(*callback)(AudioPlayer &player))
Definition AudioPlayer.h:584
bool isSilenceOnInactive()
Returns whether silence-on-inactive is enabled.
Definition AudioPlayer.h:529
void(* on_stream_change_callback)(Stream *stream_ptr, void *reference)
Definition AudioPlayer.h:632
void setOnStreamChangeCallback(void(*callback)(Stream *stream_ptr, void *reference))
Defines a callback that is called when the stream is changed.
Definition AudioPlayer.h:575
void(* on_eof_callback)(AudioPlayer &player)
Definition AudioPlayer.h:635
void setDelayIfOutputFull(int delayMs)
Sets delay (ms) to wait when output is full.
Definition AudioPlayer.h:462
void setMetaDataSize(int size)
Sets the maximum ID3 metadata buffer size (default 256)
Definition AudioPlayer.h:551
bool setStream(Stream *input)
Activates the provided Stream as current input.
Definition AudioPlayer.h:392
void setDecoder(AudioDecoder &decoder)
Sets or replaces the AudioDecoder.
Definition AudioPlayer.h:243
StreamCopy & getStreamCopy()
Definition AudioPlayer.h:523
bool isAutoFade()
Checks whether automatic fade in/out is enabled.
Definition AudioPlayer.h:548
AudioInfo info
Definition AudioPlayer.h:623
AudioStream * p_final_stream
Definition AudioPlayer.h:620
bool playFile(const char *path)
Obsolete: use PlayPath!
Definition AudioPlayer.h:304
VolumeStream volume_out
Definition AudioPlayer.h:612
FadeStream fade
Definition AudioPlayer.h:613
bool setVolume(float volume) override
Sets volume in range [0.0, 1.0]; updates VolumeStream.
Definition AudioPlayer.h:432
Stream * getStream()
Returns the currently active input Stream (e.g., file)
Definition AudioPlayer.h:409
void play()
Definition AudioPlayer.h:278
AudioSource * p_source
Definition AudioPlayer.h:611
bool next(int offset=1)
Moves to the next/previous stream by offset (negative supported)
Definition AudioPlayer.h:356
void clearBuffers(bool drainSource=false)
Definition AudioPlayer.h:331
float volume() override
Returns the current volume [0.0, 1.0].
Definition AudioPlayer.h:453
bool playPath(const char *path)
Definition AudioPlayer.h:286
bool silence_on_inactive
Definition AudioPlayer.h:610
EncodedAudioOutput out_decoding
Definition AudioPlayer.h:615
bool autonext
Definition AudioPlayer.h:609
void addNotifyAudioChange(AudioInfoSupport *notify)
Adds/updates a listener notified on audio info changes.
Definition AudioPlayer.h:249
void stop()
Halts playback; equivalent to setActive(false)
Definition AudioPlayer.h:307
AudioDecoder * p_decoder
Definition AudioPlayer.h:617
StreamCopy copier
Definition AudioPlayer.h:622
void setAutoNext(bool next)
Enables/disables auto-advance at end/timeout (overrides AudioSource)
Definition AudioPlayer.h:459
void setReference(void *ref)
Sets a user reference passed to the stream-change callback.
Definition AudioPlayer.h:554
AudioInfoSupport * p_final_notify
Definition AudioPlayer.h:621
AudioPlayer()
Default constructor.
Definition AudioPlayer.h:54
void setAutoFade(bool active)
Enables/disables automatic fade in/out to prevent pops.
Definition AudioPlayer.h:545
void setMetadataCallback(void(*callback)(MetaDataType type, const char *str, int len), ID3TypeSelection sel=SELECT_ID3)
Defines the metadata callback.
Definition AudioPlayer.h:557
void setOutput(AudioOutput &output)
Sets the final output to an AudioOutput (adds Volume/Fade for PCM)
Definition AudioPlayer.h:118
bool isActive()
Checks whether playback is active.
Definition AudioPlayer.h:412
bool previous(int offset=1)
Moves back by offset streams (defaults to 1)
Definition AudioPlayer.h:383
void end()
Ends playback and resets decoder/intermediate stages.
Definition AudioPlayer.h:222
bool is_auto_fade
Definition AudioPlayer.h:630
uint32_t timeout
Definition AudioPlayer.h:625
VolumeStream & getVolumeStream()
Returns the VolumeStream used by the player.
Definition AudioPlayer.h:542
bool setPath(const char *path)
Selects stream by path without changing the source iterator.
Definition AudioPlayer.h:374
bool begin(int index=0, bool isActive=true)
Starts or restarts playback from the first or given stream index.
Definition AudioPlayer.h:166
MetaDataID3 meta_out
Definition AudioPlayer.h:614
Stream * p_input_stream
Definition AudioPlayer.h:618
void setAudioInfo(AudioInfo info) override
Receives and forwards updated AudioInfo to the chain.
Definition AudioPlayer.h:258
void setActive(bool isActive)
Toggles playback activity; triggers fade and optional silence.
Definition AudioPlayer.h:418
void setBufferSize(int size)
Sets the internal copy buffer size (bytes)
Definition AudioPlayer.h:163
float muted_volume
Definition AudioPlayer.h:628
AudioPlayer & operator=(AudioPlayer const &)=delete
Non-assignable: assignment operator is deleted.
void * p_reference
Definition AudioPlayer.h:631
void setOutput(AudioStream &output)
Sets the final output to an AudioStream (adds Volume/Fade for PCM)
Definition AudioPlayer.h:148
size_t copy()
Definition AudioPlayer.h:466
AudioInfo audioInfo() override
Returns the current AudioInfo of the playback chain.
Definition AudioPlayer.h:274
bool setIndex(int idx)
Selects stream by absolute index in the source.
Definition AudioPlayer.h:365
AudioPlayer(AudioSource &source, AudioOutput &output, AudioDecoder &decoder)
Construct a new Audio Player object. The processing chain is AudioSource -> Stream-copy -> EncodedAud...
Definition AudioPlayer.h:65
bool setMuted(bool muted)
Mutes or unmutes the audio player.
Definition AudioPlayer.h:589
bool setVolume(float volume, int channel)
Defines the volume for the indicated channel.
Definition AudioPlayer.h:448
float current_volume
Definition AudioPlayer.h:627
void setVolumeControl(VolumeControl &vc)
Sets a custom VolumeControl implementation.
Definition AudioPlayer.h:519
float volume(int channel)
Returns the current volume for the indicated channel.
Definition AudioPlayer.h:456
AudioPlayer(AudioSource &source, Print &output, AudioDecoder &decoder, AudioInfoSupport *notify=nullptr)
Construct a new Audio Player object. The processing chain is AudioSource -> Stream-copy -> EncodedAud...
Definition AudioPlayer.h:84
AudioPlayer(AudioPlayer const &)=delete
Non-copyable: copy constructor is deleted.
Abstract Audio Data Source for the AudioPlayer which is used by the Audio Players.
Definition AudioSource.h:17
virtual Stream * selectStream(int index)
Definition AudioSource.h:30
virtual Stream * previousStream(int offset)
Returns previous audio stream.
Definition AudioSource.h:26
virtual bool isAutoNext()
Returns default setting go to the next.
Definition AudioSource.h:64
virtual bool setMetadataCallback(void(*fn)(MetaDataType info, const char *str, int len), ID3TypeSelection sel=SELECT_ICY)
Definition AudioSource.h:54
virtual Stream * nextStream(int offset)=0
Returns next audio stream.
virtual int timeoutAutoNext()
Provides the timeout which is triggering to move to the next stream.
Definition AudioSource.h:51
virtual bool begin()=0
Reset actual stream and move to root.
Base class for all Audio Streams. It support the boolean operator to test if the object is ready with...
Definition BaseStream.h:120
virtual void setAudioInfo(AudioInfo newInfo) override
Defines the input AudioInfo.
Definition BaseStream.h:128
virtual void writeSilence(size_t len)
Writes len bytes of silence (=0).
Definition BaseStream.h:157
virtual AudioInfo audioInfo() override
provides the actual input AudioInfo
Definition BaseStream.h:151
virtual int availableForWrite() override
Definition BaseStream.h:57
virtual void flush() override
Definition BaseStream.h:59
Dummy Decoder which just copies the provided data to the output. You can define if it is PCM data.
Definition CodecCopy.h:18
A more natural Print class to process encoded data (aac, wav, mp3...). Just define the output and the...
Definition AudioEncoded.h:21
void end() override
Ends the processing.
Definition AudioEncoded.h:189
bool begin() override
Starts the processing - sets the status to active.
Definition AudioEncoded.h:161
void setDecoder(AudioDecoder *decoder)
Definition AudioEncoded.h:144
void setOutput(Print *outputStream)
Defines the output.
Definition AudioEncoded.h:107
Stream which can be used to manage fade in and fade out. Before you read or write data you need to ca...
Definition Fade.h:241
void setOutput(Print &out) override
Defines/Changes the output target.
Definition Fade.h:252
void setAudioInfo(AudioInfo info) override
Defines the input AudioInfo.
Definition Fade.h:268
void setFadeOutActive(bool flag)
Definition Fade.h:313
void setFadeInActive(bool flag)
Definition Fade.h:309
Simple ID3 Meta Data Parser which supports ID3 V1 and V2 and implements the Stream interface....
Definition MetaDataID3.h:570
void setFilter(ID3TypeSelection sel)
Definition MetaDataID3.h:584
void setCallback(void(*fn)(MetaDataType info, const char *str, int len))
Definition MetaDataID3.h:579
bool begin()
Definition MetaDataID3.h:588
virtual size_t write(const uint8_t *data, size_t len)
Provide tha audio data to the API to parse for Meta Data.
Definition MetaDataID3.h:602
void end()
Definition MetaDataID3.h:595
bool resize(size_t size)
Defines the ID3V3 result buffer size (default is 256);.
Definition MetaDataID3.h:612
size_t copyBytes(size_t bytes)
Definition StreamCopy.h:114
void setCallbackOnWrite(void(*onWrite)(void *obj, void *buffer, size_t len), void *obj)
Defines a callback that is notified with the wirtten data.
Definition StreamCopy.h:275
void begin()
(Re)starts the processing
Definition StreamCopy.h:56
int bufferSize()
Provides the buffer size.
Definition StreamCopy.h:291
bool resize(size_t len)
resizes the copy buffer
Definition StreamCopy.h:309
size_t copy()
Definition StreamCopy.h:100
Abstract class for handling of the linear input volume to determine the multiplication factor which s...
Definition VolumeControl.h:19
Adjust the volume of the related input or output: To work properly the class needs to know the bits p...
Definition VolumeStream.h:35
void setOutput(Print &out) override
Defines/Changes the output target.
Definition VolumeStream.h:71
float volume() override
Provides the current (avg) volume accross all channels.
Definition VolumeStream.h:232
bool begin() override
Definition VolumeStream.h:91
bool setVolume(float vol) override
Defines the volume for all channels: needs to be in the range of 0 to 1.0 (if allow boost has not bee...
Definition VolumeStream.h:192
void setAudioInfo(AudioInfo cfg) override
Detines the Audio info - The bits_per_sample are critical to work properly!
Definition VolumeStream.h:170
void setVolumeControl(VolumeControl &vc)
Defines the volume control logic.
Definition VolumeStream.h:123
Supports the setting and getting of the volume.
Definition AudioTypes.h:188
ID3TypeSelection
Enum to filter by type of metadata.
Definition AbstractMetaData.h:8
MetaDataType
Type of meta info.
Definition AbstractMetaData.h:11
@ SELECT_ID3
Definition AbstractMetaData.h:8
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition LMSEchoCancellationStream.h:6
void delay(uint32_t ms)
Definition Arduino.h:259
uint32_t millis()
Returns the milliseconds since the start.
Definition Arduino.h:260
Basic Audio information which drives e.g. I2S.
Definition AudioTypes.h:51
sample_rate_t sample_rate
Sample Rate: e.g 44100.
Definition AudioTypes.h:53
uint16_t channels
Number of channels: 2=stereo, 1=mono.
Definition AudioTypes.h:55
uint8_t bits_per_sample
Number of bits per sample (int16_t = 16 bits)
Definition AudioTypes.h:57