arduino-audio-tools
Loading...
Searching...
No Matches
AudioIO.h
1#pragma once
2#include "AudioTools/CoreAudio/AudioOutput.h"
3#include "AudioTools/CoreAudio/AudioStreams.h"
4
5#ifndef MAX_ZERO_READ_COUNT
6#define MAX_ZERO_READ_COUNT 3
7#endif
8
9#ifndef CHANNEL_SELECT_BUFFER_SIZE
10#define CHANNEL_SELECT_BUFFER_SIZE 256
11#endif
12
13namespace audio_tools {
21template <class T>
23 public:
28 void begin(T* transform, Stream* source) {
29 TRACED();
30 active = true;
31 p_stream = source;
32 p_transform = transform;
33 if (transform == nullptr) {
34 LOGE("transform is NULL");
35 active = false;
36 }
37 if (p_stream == nullptr) {
38 LOGE("p_stream is NULL");
39 active = false;
40 }
41 }
42
44 void resizeReadBuffer(int size) { buffer.resize(size); }
46 void resizeResultQueue(int size) {
47 result_queue_buffer.resize(size);
48 result_queue.begin();
49 }
50
51 size_t readBytes(uint8_t* data, size_t len) {
52 LOGD("TransformationReader::readBytes: %d", (int)len);
53 if (!active) {
54 LOGE("inactive");
55 return 0;
56 }
57 if (p_stream == nullptr) {
58 LOGE("p_stream is NULL");
59 return 0;
60 }
61
62 // we read half the necessary bytes
63 if (buffer.size() == 0) {
64 int size = (0.5f / p_transform->getByteFactor() * len);
65 // process full samples/frames
66 size = size / 4 * 4;
67 LOGI("read size: %d", size);
68 buffer.resize(size);
69 }
70
71 if (result_queue_buffer.size() == 0) {
72 // make sure that the ring buffer is big enough
73 int rb_size = len * result_queue_factor;
74 LOGI("buffer size: %d", rb_size);
75 result_queue_buffer.resize(rb_size);
76 result_queue.begin();
77 }
78
79 if (result_queue.available() < len) {
80 Print* tmp = setupOutput();
81 int zero_count = 0;
82 while (result_queue.available() < len) {
83 int read_eff = p_stream->readBytes(buffer.data(), buffer.size());
84 if (read_eff > 0) {
85 zero_count = 0; // reset 0 count
86 if (read_eff != buffer.size()) {
87 LOGD("readBytes %d -> %d", buffer.size(), read_eff);
88 }
89 int write_eff = p_transform->write(buffer.data(), read_eff);
90 if (write_eff != read_eff) {
91 LOGE("TransformationReader::write %d -> %d", read_eff, write_eff);
92 }
93 } else {
94 // limit the number of reads which provide 0;
95 if (++zero_count > MAX_ZERO_READ_COUNT) {
96 break;
97 }
98 // wait for some more data
99 delay(5);
100 }
101 }
102 restoreOutput(tmp);
103 }
104
105 int result_len = min((int)len, result_queue.available());
106 result_len = result_queue.readBytes(data, result_len);
107 LOGD("TransformationReader::readBytes: %d -> %d", (int)len, result_len);
108
109 return result_len;
110 }
111
112 void end() {
113 result_queue_buffer.resize(0);
114 buffer.resize(0);
115 }
116
118 void setResultQueueFactor(int factor) { result_queue_factor = factor; }
119
120 protected:
121 RingBuffer<uint8_t> result_queue_buffer{0};
122 QueueStream<uint8_t> result_queue{result_queue_buffer}; //
123 Stream* p_stream = nullptr;
124 Vector<uint8_t> buffer{0}; // we allocate memory only when needed
125 T* p_transform = nullptr;
126 bool active = false;
127 int result_queue_factor = 5;
128
133 Print* result = p_transform->getPrint();
134 p_transform->setOutput((Print&)result_queue);
135
136 return result;
137 }
140 void restoreOutput(Print* out) {
141 if (out) p_transform->setOutput(*out);
142 }
143};
144
152 public:
153 virtual void setStream(Stream& stream) override {
154 TRACED();
155 p_stream = &stream;
156 p_print = &stream;
157 }
158
159 virtual void setStream(AudioStream& stream) {
160 TRACED();
161 p_stream = &stream;
162 p_print = &stream;
163 // setNotifyOnOutput(stream);
164 addNotifyAudioChange(stream);
165 }
166
167 virtual void setOutput(AudioOutput& print) {
168 TRACED();
169 p_print = &print;
171 }
172
173 virtual void setOutput(Print& print) override {
174 TRACED();
175 p_print = &print;
176 }
177
178 virtual Print* getPrint() { return p_print; }
179
180 virtual Stream* getStream() { return p_stream; }
181
182 size_t readBytes(uint8_t* data, size_t len) override {
183 LOGD("ReformatBaseStream::readBytes: %d", (int)len);
184 return reader.readBytes(data, len);
185 }
186
187 int available() override {
188 return DEFAULT_BUFFER_SIZE; // reader.availableForWrite();
189 }
190
191 int availableForWrite() override {
192 return DEFAULT_BUFFER_SIZE; // reader.availableForWrite();
193 }
194
195 virtual float getByteFactor() = 0;
196
197 void end() override {
198 TRACED();
199 AudioStream::end();
200 reader.end();
201 }
202
205 void resizeReadResultQueue(int size) { reader.resizeResultQueue(size); }
206
211
212 protected:
214 Stream* p_stream = nullptr;
215 Print* p_print = nullptr;
216
217 void setupReader() {
218 if (getStream() != nullptr) {
219 reader.begin(this, getStream());
220 }
221 }
222};
223
229
235 public:
236 AdapterPrintToAudioOutput() = default;
237 AdapterPrintToAudioOutput(Print& print) { setStream(print); }
238 void setStream(Print& out) { p_print = &out; }
239 void setAudioInfo(AudioInfo info) { cfg = info; }
240 size_t write(const uint8_t* data, size_t len) {
241 return p_print->write(data, len);
242 }
244 virtual bool isDeletable() { return true; }
245
246 AudioInfo audioInfo() { return cfg; }
247
248 protected:
249 Print* p_print = nullptr;
250 AudioInfo cfg;
251};
252
258 public:
260
261 AdapterAudioStreamToAudioOutput(AudioStream& stream) { setStream(stream); }
262
263 void setStream(AudioStream& stream) { p_stream = &stream; }
264
265 void setAudioInfo(AudioInfo info) override { p_stream->setAudioInfo(info); }
266
267 AudioInfo audioInfo() override { return p_stream->audioInfo(); }
268
269 size_t write(const uint8_t* data, size_t len) override {
270 return p_stream->write(data, len);
271 }
272
273 int availableForWrite() override { return p_stream->availableForWrite(); }
274
275 bool begin() override { return p_stream->begin(); }
276
277 void end() override { p_stream->end(); }
278
280 virtual bool isDeletable() override { return true; }
281
282 operator bool() override { return *p_stream; }
283
284 protected:
285 AudioStream* p_stream = nullptr;
286};
287
293 public:
295
296 AdapterAudioOutputToAudioStream(AudioOutput& stream) { setOutput(stream); }
297
298 void setOutput(AudioOutput& stream) { p_stream = &stream; }
299
300 void setAudioInfo(AudioInfo info) override { p_stream->setAudioInfo(info); }
301
302 AudioInfo audioInfo() override { return p_stream->audioInfo(); }
303
304 size_t write(const uint8_t* data, size_t len) override {
305 return p_stream->write(data, len);
306 }
307
308 bool begin() override { return p_stream->begin(); }
309
310 void end() override { p_stream->end(); }
311
313 virtual bool isDeletable() { return true; }
314
315 operator bool() override { return *p_stream; }
316
317 protected:
318 AudioOutput* p_stream = nullptr;
319};
320
328 public:
330 MultiOutput() = default;
331
332 MultiOutput(Print& out) { add(out); }
333
336
337 MultiOutput(AudioStream& out) { add(out); }
338
341 add(out1);
342 add(out2);
343 }
344
347 add(out1);
348 add(out2);
349 }
350
353 MultiOutput(Print& out1, Print& out2) {
354 add(out1);
355 add(out2);
356 }
357
358 virtual ~MultiOutput() { clear(); }
359
361 void add(AudioOutput& out) { vector.push_back(&out); }
362
364 void add(AudioStream& stream) {
367 vector.push_back(out);
368 }
369
370 void add(Print& print) {
372 vector.push_back(out);
373 }
374
375 void flush() {
376 for (int j = 0; j < vector.size(); j++) {
377 vector[j]->flush();
378 }
379 }
380
382 for (int j = 0; j < vector.size(); j++) {
383 vector[j]->setAudioInfo(info);
384 }
385 }
386
387 size_t write(const uint8_t* data, size_t len) override {
388 for (auto& out : vector) {
389 int open = len;
390 int start = 0;
391 // create copy of data to avoid that one output changes the data for the
392 // other outputs
393 uint8_t copy[len];
394 memcpy(copy, data, len);
395 while (open > 0) {
396 int written = out->write(copy + start, open);
397 open -= written;
398 start += written;
399 }
400 }
401 return len;
402 }
403
404 size_t write(uint8_t ch) override {
405 for (int j = 0; j < vector.size(); j++) {
406 int open = 1;
407 while (open > 0) {
408 open -= vector[j]->write(ch);
409 }
410 }
411 return 1;
412 }
413
415 void clear() {
416 for (auto& tmp : vector) {
417 if (tmp != nullptr && tmp->isDeletable()) {
418 delete tmp;
419 }
420 }
421 vector.clear();
422 }
423
424 protected:
426
428 void setOutput(Print& out) { add(out); }
429};
430
441 public:
442 TimedStream() = default;
443
444 TimedStream(AudioStream& io, long startSeconds = 0, long endSeconds = -1) {
445 p_stream = &io;
446 p_print = &io;
447 p_info = &io;
448 setStartSec(startSeconds);
449 setEndSec(endSeconds);
450 }
451
452 TimedStream(AudioOutput& o, long startSeconds = 0, long endSeconds = -1) {
453 p_print = &o;
454 p_info = &o;
455 setStartSec(startSeconds);
456 setEndSec(endSeconds);
457 }
458
459 TimedStream(Stream& io, long startSeconds = 0, long endSeconds = -1) {
460 p_stream = &io;
461 p_print = &io;
462 setStartSec(startSeconds);
463 setEndSec(endSeconds);
464 }
465
466 TimedStream(Print& o, long startSeconds = 0, long endSeconds = -1) {
467 p_print = &o;
468 setStartSec(startSeconds);
469 setEndSec(endSeconds);
470 }
471
474 void setStartSec(uint32_t startSeconds) {
475 start_ms = startSeconds * 1000;
476 calculateByteLimits();
477 }
478
480 void setStartMs(uint32_t ms) {
481 start_ms = ms;
482 calculateByteLimits();
483 }
484
487 void setEndSec(uint32_t endSeconds) {
488 end_ms = endSeconds * 1000;
489 calculateByteLimits();
490 }
491
493 void setEndMs(uint32_t ms) {
494 end_ms = ms;
495 calculateByteLimits();
496 }
497
499 bool isPlaying() {
500 if (current_bytes < start_bytes) return false;
501 if (end_bytes > 0 && current_bytes > end_bytes) return false;
502 return true;
503 }
504
506 bool isActive() {
507 return (current_bytes < end_bytes && current_bytes >= start_bytes);
508 }
509
510 bool begin(AudioInfo info) {
511 setAudioInfo(info);
512 return begin();
513 }
514
515 bool begin() override {
516 calculateByteLimits();
517 current_bytes = 0;
518 LOGI("byte range %u - %u", (unsigned)start_bytes, (unsigned)end_bytes);
519 return true;
520 }
521
522 operator bool() override { return isActive(); }
523
527 size_t readBytes(uint8_t* data, size_t len) override {
528 // if reading is not supported we stop
529 if (p_stream == nullptr) return 0;
530 // Positioin to start
531 if (start_bytes > current_bytes) {
532 consumeBytes(start_bytes - current_bytes);
533 }
534 // if we are past the end we stop
535 if (!isActive()) return 0;
536 // read the data now
537 size_t result = 0;
538 do {
539 result = p_stream->readBytes(data, len);
540 current_bytes += len;
541 // ignore data before start time
542 } while (result > 0 && current_bytes < start_bytes);
543 return isPlaying() ? result : 0;
544 }
545
547 size_t write(const uint8_t* data, size_t len) override {
548 if (current_bytes >= end_bytes) return 0;
549 current_bytes += len;
550 if (current_bytes < start_bytes) return len;
551 return p_print->write(data, len);
552 }
553
555 int available() override {
556 if (p_stream == nullptr) return 0;
557 return current_bytes < end_bytes ? p_stream->available() : 0;
558 }
559
561 void setAudioInfo(AudioInfo info) override {
563 if (p_info) p_info->setAudioInfo(info);
564 calculateByteLimits();
565 }
566
567 int availableForWrite() override {
568 return current_bytes < end_bytes ? p_print->availableForWrite() : 0;
569 }
570
573 void setCompressionRatio(float ratio) { compression_ratio = ratio; }
574
577 return info.sample_rate * info.channels * info.bits_per_sample / 8;
578 }
579
580 void setOutput(Print& out) override { p_print = &out; }
581
582 void setStream(Stream& stream) override {
583 p_print = &stream;
584 p_stream = &stream;
585 }
586
587 void setOutput(AudioOutput& out) {
588 p_print = &out;
589 p_info = &out;
590 }
591
592 void setStream(AudioOutput& out) {
593 p_print = &out;
594 p_info = &out;
595 }
596
597 void setStream(AudioStream& stream) {
598 p_print = &stream;
599 p_stream = &stream;
600 p_info = &stream;
601 }
602
603 size_t size() { return end_bytes - start_bytes; }
604
605 protected:
606 Stream* p_stream = nullptr;
607 Print* p_print = nullptr;
608 AudioInfoSupport* p_info = nullptr;
609 uint32_t start_ms = 0;
610 uint32_t end_ms = UINT32_MAX;
611 uint32_t start_bytes = 0;
612 uint32_t end_bytes = UINT32_MAX;
613 uint32_t current_bytes = 0;
614 float compression_ratio = 1.0;
615
616 void consumeBytes(uint32_t len) {
617 int open = len;
618 uint8_t buffer[1024];
619 while (open > 0) {
620 int toread = min(1024, open);
621 p_stream->readBytes(buffer, toread);
622 open -= toread;
623 }
624 current_bytes += len;
625 LOGD("consumed %u -> %u", (unsigned)len, (unsigned)current_bytes);
626 }
627
628 void calculateByteLimits() {
629 float bytes_per_second = bytesPerSecond();
630 if (bytes_per_second > 0) {
631 start_bytes = bytes_per_second * start_ms / compression_ratio / 1000;
632 end_bytes = bytes_per_second * end_ms / compression_ratio / 1000;
633 } else {
634 LOGE("AudioInfo not defined");
635 }
636 }
637};
638
649 public:
650 ChannelsSelectOutput() = default;
651
652 bool begin(AudioInfo info) override {
653 setAudioInfo(info);
654 return begin();
655 }
656
657 bool begin() override {
658 AudioOutput::begin();
659 // make sure that selected channels are valid
660 for (auto& out : out_channels) {
661 for (auto& ch : out.channels) {
662 if (ch > cfg.channels - 1) {
663 LOGE("Channel '%d' not valid for max %d channels", ch, cfg.channels);
664 return false;
665 }
666 }
667 }
668 return true;
669 }
670
673 void addOutput(AudioOutput& out, uint16_t channel) {
674 Vector<uint16_t> channels;
675 channels.push_back(channel);
677 def.channels = channels;
678 def.p_out = &out;
679 def.p_audio_info = &out;
680 out_channels.push_back(def);
681 }
682
685 void addOutput(AudioStream& out, uint16_t channel) {
686 Vector<uint16_t> channels;
687 channels.push_back(channel);
689 def.channels = channels;
690 def.p_out = &out;
691 def.p_audio_info = &out;
692 out_channels.push_back(def);
693 }
694
697 void addOutput(Print& out, uint16_t channel) {
698 Vector<uint16_t> channels;
699 channels.push_back(channel);
701 def.channels = channels;
702 def.p_out = &out;
703 out_channels.push_back(def);
704 }
705
708 void addOutput(Print& out, uint16_t left, uint16_t right) {
709 Vector<uint16_t> channels;
710 channels.push_back(left);
711 channels.push_back(right);
713 def.channels = channels;
714 def.p_out = &out;
715 out_channels.push_back(def);
716 }
717
720 void addOutput(AudioOutput& out, uint16_t left, uint16_t right) {
721 Vector<uint16_t> channels;
722 channels.push_back(left);
723 channels.push_back(right);
725 def.channels = channels;
726 def.p_out = &out;
727 def.p_audio_info = &out;
728 out_channels.push_back(def);
729 }
730
733 void addOutput(AudioStream& out, uint16_t left, uint16_t right) {
734 Vector<uint16_t> channels;
735 channels.push_back(left);
736 channels.push_back(right);
738 def.channels = channels;
739 def.p_out = &out;
740 def.p_audio_info = &out;
741 out_channels.push_back(def);
742 }
743
744 size_t write(const uint8_t* data, size_t len) override {
745 if (!is_active) return false;
746 LOGD("write %d", (int)len);
747 switch (cfg.bits_per_sample) {
748 case 16:
749 return writeT<int16_t>(data, len);
750 case 24:
751 return writeT<int24_t>(data, len);
752 case 32:
753 return writeT<int32_t>(data, len);
754 default:
755 return 0;
756 }
757 }
758
759 void setAudioInfo(AudioInfo ai) override {
760 this->cfg = ai;
761 // notifyAudioChange(ai);
762 for (auto& info : out_channels) {
763 auto p_notify = info.p_audio_info;
764 if (p_notify != nullptr) {
765 AudioInfo result{ai};
766 result.channels = info.channels.size();
767 p_notify->setAudioInfo(result);
768 }
769 }
770 }
771
772 protected:
774 Print* p_out = nullptr;
775 AudioInfoSupport* p_audio_info = nullptr;
776 SingleBuffer<uint8_t> buffer{CHANNEL_SELECT_BUFFER_SIZE};
777 Vector<uint16_t> channels{0};
778 };
779 Vector<ChannelSelectionOutputDef> out_channels{0};
780
781 template <typename T>
782 size_t writeT(const uint8_t* buffer, size_t size) {
783 if (!is_active) return 0;
784 int sample_count = size / sizeof(T);
785 // int result_size = sample_count / cfg.channels;
786 T* data = (T*)buffer;
787
788 for (int i = 0; i < sample_count; i += cfg.channels) {
789 T* frame = data + i;
790 for (auto& out : out_channels) {
791 T out_frame[out.channels.size()];
792 int ch_out = 0;
793 for (auto& ch : out.channels) {
794 // make sure we have a valid channel
795 int channel = (ch < cfg.channels) ? ch : cfg.channels - 1;
796 out_frame[ch_out++] = frame[channel];
797 }
798 // write to buffer
799 size_t written = out.buffer.writeArray((const uint8_t*)&out_frame,
800 sizeof(out_frame));
801 // write buffer to final output
802 if (out.buffer.availableForWrite() < sizeof(out_frame)) {
803 out.p_out->write(out.buffer.data(), out.buffer.available());
804 out.buffer.reset();
805 }
806 // if (written != sizeof(out_frame)) {
807 // LOGW("Could not write all samples %d -> %d", sizeof(out_frame),
808 // written);
809 // }
810 }
811 }
812 return size;
813 }
814
816 int getChannels(Print* out, int defaultChannels) {
817 for (auto& channels_select : out_channels) {
818 if (channels_select.p_out == out) return channels_select.channels.size();
819 }
820 return defaultChannels;
821 }
822};
823
824} // namespace audio_tools
Wrapper which converts a AudioStream to a AudioOutput.
Definition AudioIO.h:292
virtual bool isDeletable()
If true we need to release the related memory in the destructor.
Definition AudioIO.h:313
void setAudioInfo(AudioInfo info) override
Defines the input AudioInfo.
Definition AudioIO.h:300
AudioInfo audioInfo() override
provides the actual input AudioInfo
Definition AudioIO.h:302
Wrapper which converts a AudioStream to a AudioOutput.
Definition AudioIO.h:257
virtual bool isDeletable() override
If true we need to release the related memory in the destructor.
Definition AudioIO.h:280
void setAudioInfo(AudioInfo info) override
Defines the input AudioInfo.
Definition AudioIO.h:265
AudioInfo audioInfo() override
provides the actual input AudioInfo
Definition AudioIO.h:267
Wrapper which converts a Print to a AudioOutput.
Definition AudioIO.h:234
virtual bool isDeletable()
If true we need to release the related memory in the destructor.
Definition AudioIO.h:244
void setAudioInfo(AudioInfo info)
Defines the input AudioInfo.
Definition AudioIO.h:239
AudioInfo audioInfo()
provides the actual input AudioInfo
Definition AudioIO.h:246
virtual void addNotifyAudioChange(AudioInfoSupport &bi)
Adds target to be notified about audio changes.
Definition AudioTypes.h:153
Supports changes to the sampling rate, bits and channels.
Definition AudioTypes.h:135
virtual void setAudioInfo(AudioInfo info)=0
Defines the input AudioInfo.
Base class for Output Adpapters.
Definition AudioIO.h:228
Abstract Audio Ouptut class.
Definition AudioOutput.h:25
Base class for all Audio Streams. It support the boolean operator to test if the object is ready with...
Definition BaseStream.h:122
virtual void setAudioInfo(AudioInfo newInfo) override
Defines the input AudioInfo.
Definition BaseStream.h:130
Flexible functionality to extract one or more channels from a multichannel signal....
Definition AudioIO.h:648
void addOutput(Print &out, uint16_t left, uint16_t right)
Definition AudioIO.h:708
void setAudioInfo(AudioInfo ai) override
Defines the input AudioInfo.
Definition AudioIO.h:759
void addOutput(Print &out, uint16_t channel)
Definition AudioIO.h:697
void addOutput(AudioOutput &out, uint16_t channel)
Definition AudioIO.h:673
int getChannels(Print *out, int defaultChannels)
Determine number of channels for destination.
Definition AudioIO.h:816
void addOutput(AudioStream &out, uint16_t channel)
Definition AudioIO.h:685
void addOutput(AudioStream &out, uint16_t left, uint16_t right)
Definition AudioIO.h:733
void addOutput(AudioOutput &out, uint16_t left, uint16_t right)
Definition AudioIO.h:720
Abstract class: Objects can be put into a pipleline.
Definition AudioOutput.h:100
Abstract class: Objects can be put into a pipleline.
Definition AudioStreams.h:68
Replicates the output to multiple destinations.
Definition AudioIO.h:327
void add(AudioOutput &out)
Add an additional AudioOutput output.
Definition AudioIO.h:361
void setAudioInfo(AudioInfo info)
Defines the input AudioInfo.
Definition AudioIO.h:381
void add(AudioStream &stream)
Add an AudioStream to the output.
Definition AudioIO.h:364
MultiOutput(AudioStream &out1, AudioStream &out2)
Defines a MultiOutput with 2 final outputs.
Definition AudioIO.h:346
MultiOutput(AudioOutput &out1, AudioOutput &out2)
Defines a MultiOutput with 2 final outputs.
Definition AudioIO.h:340
MultiOutput(AudioOutput &out)
Defines a MultiOutput with a single final outputs,.
Definition AudioIO.h:335
void clear()
Removes all output components.
Definition AudioIO.h:415
void setOutput(Print &out)
support for Pipleline
Definition AudioIO.h:428
MultiOutput(Print &out1, Print &out2)
Definition AudioIO.h:353
MultiOutput()=default
Defines a MultiOutput with no final output: Define your outputs with add()
Definition NoArduino.h:62
virtual bool begin() override
Activates the output.
Definition BaseStream.h:339
Base class for chained converting streams.
Definition AudioIO.h:151
virtual void setStream(Stream &stream) override
Defines/Changes the input & output.
Definition AudioIO.h:153
virtual void setOutput(Print &print) override
Defines/Changes the output target.
Definition AudioIO.h:173
virtual TransformationReader< ReformatBaseStream > & transformationReader()
Provides access to the TransformationReader.
Definition AudioIO.h:208
void resizeReadResultQueue(int size)
Definition AudioIO.h:205
Implements a typed Ringbuffer.
Definition Buffers.h:341
virtual size_t size() override
Returns the maximum capacity of the buffer.
Definition Buffers.h:428
virtual bool resize(int len)
Resizes the buffer if supported: returns false if not supported.
Definition Buffers.h:418
A simple Buffer implementation which just uses a (dynamically sized) array.
Definition Buffers.h:172
Definition NoArduino.h:142
AudioStream class that can define a start and (an optional) stop time Usually it is used to wrap an A...
Definition AudioIO.h:440
void setOutput(Print &out) override
Defines/Changes the output target.
Definition AudioIO.h:580
void setStream(Stream &stream) override
Defines/Changes the input & output.
Definition AudioIO.h:582
void setEndSec(uint32_t endSeconds)
Definition AudioIO.h:487
void setEndMs(uint32_t ms)
Defines the (optional) end time in milliseconds.
Definition AudioIO.h:493
void setCompressionRatio(float ratio)
Definition AudioIO.h:573
size_t readBytes(uint8_t *data, size_t len) override
Definition AudioIO.h:527
void setStartSec(uint32_t startSeconds)
Definition AudioIO.h:474
int available() override
Provides the available bytes until the end time has reached.
Definition AudioIO.h:555
size_t write(const uint8_t *data, size_t len) override
Plays only data for the indiated start and end time.
Definition AudioIO.h:547
void setStartMs(uint32_t ms)
Defines the start time in milliseconds.
Definition AudioIO.h:480
bool isPlaying()
Returns true if we are in a valid time range and are still playing sound.
Definition AudioIO.h:499
bool isActive()
Returns true if we are not past the end time;.
Definition AudioIO.h:506
void setAudioInfo(AudioInfo info) override
Updates the AudioInfo in the current object and in the source or target.
Definition AudioIO.h:561
int bytesPerSecond()
Calculates the bytes per second from the AudioInfo.
Definition AudioIO.h:576
ConverterStream Helper class which implements the readBytes with the help of write.
Definition AudioIO.h:22
void begin(T *transform, Stream *source)
setup of the TransformationReader class
Definition AudioIO.h:28
void resizeReadBuffer(int size)
Defines the read buffer size for individual reads.
Definition AudioIO.h:44
void restoreOutput(Print *out)
restores the original output in the converter class
Definition AudioIO.h:140
Print * setupOutput()
Definition AudioIO.h:132
void resizeResultQueue(int size)
Defines the queue size for result.
Definition AudioIO.h:46
void setResultQueueFactor(int factor)
Defines the queue size dependent on the read size.
Definition AudioIO.h:118
Vector implementation which provides the most important methods as defined by std::vector....
Definition Vector.h:21
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition AudioCodecsBase.h:10
Basic Audio information which drives e.g. I2S.
Definition AudioTypes.h:55
sample_rate_t sample_rate
Sample Rate: e.g 44100.
Definition AudioTypes.h:57
uint16_t channels
Number of channels: 2=stereo, 1=mono.
Definition AudioTypes.h:59
uint8_t bits_per_sample
Number of bits per sample (int16_t = 16 bits)
Definition AudioTypes.h:61