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
13
14namespace audio_tools {
22template <class T>
24 public:
29 void begin(T *transform, Stream *source) {
30 TRACED();
31 active = true;
32 p_stream = source;
33 p_transform = transform;
34 if (transform == nullptr) {
35 LOGE("transform is NULL");
36 active = false;
37 }
38 if (p_stream == nullptr) {
39 LOGE("p_stream is NULL");
40 active = false;
41 }
42 }
43
45 void resizeReadBuffer(int size) {
46 buffer.resize(size);
47 }
49 void resizeResultQueue(int size) {
50 result_queue_buffer.resize(size);
51 result_queue.begin();
52 }
53
54
55 size_t readBytes(uint8_t *data, size_t len) {
56 LOGD("TransformationReader::readBytes: %d", (int)len);
57 if (!active) {
58 LOGE("inactive");
59 return 0;
60 }
61 if (p_stream == nullptr) {
62 LOGE("p_stream is NULL");
63 return 0;
64 }
65
66 // we read half the necessary bytes
67 if (buffer.size() == 0) {
68 int size = (0.5f / p_transform->getByteFactor() * len);
69 // process full samples/frames
70 size = size / 4 * 4;
71 LOGI("read size: %d", size);
72 buffer.resize(size);
73 }
74
75 if (result_queue_buffer.size() == 0) {
76 // make sure that the ring buffer is big enough
77 int rb_size = len * result_queue_factor;
78 LOGI("buffer size: %d", rb_size);
79 result_queue_buffer.resize(rb_size);
80 result_queue.begin();
81 }
82
83 if (result_queue.available() < len) {
84 Print *tmp = setupOutput();
85 int zero_count = 0;
86 while (result_queue.available() < len) {
87 int read_eff = p_stream->readBytes(buffer.data(), buffer.size());
88 if (read_eff > 0) {
89 zero_count = 0; // reset 0 count
90 if (read_eff != buffer.size()){
91 LOGD("readBytes %d -> %d", buffer.size(), read_eff);
92 }
93 int write_eff = p_transform->write(buffer.data(), read_eff);
94 if (write_eff != read_eff){
95 LOGE("TransformationReader::write %d -> %d", read_eff, write_eff);
96 }
97 } else {
98 // limit the number of reads which provide 0;
99 if (++zero_count > MAX_ZERO_READ_COUNT){
100 break;
101 }
102 // wait for some more data
103 delay(5);
104 }
105 }
106 restoreOutput(tmp);
107 }
108
109 int result_len = min((int)len, result_queue.available());
110 result_len = result_queue.readBytes(data, result_len);
111 LOGD("TransformationReader::readBytes: %d -> %d", (int)len,
112 result_len);
113
114 return result_len;
115 }
116
117 void end() {
118 result_queue_buffer.resize(0);
119 buffer.resize(0);
120 }
121
123 void setResultQueueFactor(int factor) { result_queue_factor = factor; }
124
125 protected:
126 RingBuffer<uint8_t> result_queue_buffer{0};
127 QueueStream<uint8_t> result_queue{result_queue_buffer}; //
128 Stream *p_stream = nullptr;
129 Vector<uint8_t> buffer{0}; // we allocate memory only when needed
130 T *p_transform = nullptr;
131 bool active = false;
132 int result_queue_factor = 5;
133
138 Print *result = p_transform->getPrint();
139 p_transform->setOutput((Print &)result_queue);
140
141 return result;
142 }
145 void restoreOutput(Print *out) {
146 if (out) p_transform->setOutput(*out);
147 }
148};
149
157 public:
158 virtual void setStream(Stream &stream) override {
159 TRACED();
160 p_stream = &stream;
161 p_print = &stream;
162 }
163
164 virtual void setStream(AudioStream &stream) {
165 TRACED();
166 p_stream = &stream;
167 p_print = &stream;
168 //setNotifyOnOutput(stream);
169 addNotifyAudioChange(stream);
170 }
171
172 virtual void setOutput(AudioOutput &print) {
173 TRACED();
174 p_print = &print;
176 }
177
178 virtual void setOutput(Print &print) override {
179 TRACED();
180 p_print = &print;
181 }
182
183 virtual Print *getPrint() { return p_print; }
184
185 virtual Stream *getStream() { return p_stream; }
186
187 size_t readBytes(uint8_t *data, size_t len) override {
188 LOGD("ReformatBaseStream::readBytes: %d", (int)len);
189 return reader.readBytes(data, len);
190 }
191
192 int available() override {
193 return DEFAULT_BUFFER_SIZE; // reader.availableForWrite();
194 }
195
196 int availableForWrite() override {
197 return DEFAULT_BUFFER_SIZE; // reader.availableForWrite();
198 }
199
200 virtual float getByteFactor() = 0;
201
202 void end() override {
203 TRACED();
204 AudioStream::end();
205 reader.end();
206 }
207
209 void resizeReadResultQueue(int size) { reader.resizeResultQueue(size);}
210
213
214
215 protected:
217 Stream *p_stream = nullptr;
218 Print *p_print = nullptr;
219
220 void setupReader() {
221 if (getStream() != nullptr) {
222 reader.begin(this, getStream());
223 }
224 }
225};
226
232
238 public:
239 AdapterPrintToAudioOutput() = default;
240 AdapterPrintToAudioOutput(Print &print) { setStream(print); }
241 void setStream(Print& out) { p_print = &out; }
242 void setAudioInfo(AudioInfo info) { cfg = info;}
243 size_t write(const uint8_t *data, size_t len) {
244 return p_print->write(data, len);
245 }
247 virtual bool isDeletable() { return true; }
248
249 AudioInfo audioInfo() {return cfg; }
250
251 protected:
252 Print *p_print = nullptr;
253 AudioInfo cfg;
254};
255
261 public:
263
264 AdapterAudioStreamToAudioOutput(AudioStream &stream) { setStream(stream); }
265
266 void setStream(AudioStream &stream) { p_stream = &stream; }
267
268 void setAudioInfo(AudioInfo info) override { p_stream->setAudioInfo(info); }
269
270 AudioInfo audioInfo() override { return p_stream->audioInfo(); }
271
272 size_t write(const uint8_t *data, size_t len) override {
273 return p_stream->write(data, len);
274 }
275
276 int availableForWrite() override { return p_stream->availableForWrite(); }
277
278 bool begin() override { return p_stream->begin(); }
279
280 void end() override { p_stream->end(); }
281
283 virtual bool isDeletable() override { return true; }
284
285 operator bool() override { return *p_stream; }
286
287 protected:
288 AudioStream *p_stream = nullptr;
289};
290
296 public:
298
299 AdapterAudioOutputToAudioStream(AudioOutput &stream) { setOutput(stream); }
300
301 void setOutput(AudioOutput &stream) { p_stream = &stream; }
302
303 void setAudioInfo(AudioInfo info) override { p_stream->setAudioInfo(info); }
304
305 AudioInfo audioInfo() override { return p_stream->audioInfo(); }
306
307 size_t write(const uint8_t *data, size_t len) override {
308 return p_stream->write(data, len);
309 }
310
311 bool begin() override { return p_stream->begin(); }
312
313 void end() override { p_stream->end(); }
314
316 virtual bool isDeletable() { return true; }
317
318 operator bool() override { return *p_stream; }
319
320 protected:
321 AudioOutput *p_stream = nullptr;
322};
323
331 public:
333 MultiOutput() = default;
334
335 MultiOutput(Print &out) { add(out); }
336
339
340 MultiOutput(AudioStream &out) { add(out); }
341
344 add(out1);
345 add(out2);
346 }
347
350 add(out1);
351 add(out2);
352 }
353
356 MultiOutput(Print &out1, Print &out2) {
357 add(out1);
358 add(out2);
359 }
360
361 virtual ~MultiOutput() {
362 clear();
363 }
364
366 void add(AudioOutput &out) { vector.push_back(&out); }
367
369 void add(AudioStream &stream) {
372 vector.push_back(out);
373 }
374
375 void add(Print &print) {
377 vector.push_back(out);
378 }
379
380 void flush() {
381 for (int j = 0; j < vector.size(); j++) {
382 vector[j]->flush();
383 }
384 }
385
387 for (int j = 0; j < vector.size(); j++) {
388 vector[j]->setAudioInfo(info);
389 }
390 }
391
392 size_t write(const uint8_t *data, size_t len) {
393 for (int j = 0; j < vector.size(); j++) {
394 int open = len;
395 int start = 0;
396 while (open > 0) {
397 int written = vector[j]->write(data + start, open);
398 open -= written;
399 start += written;
400 }
401 }
402 return len;
403 }
404
405 size_t write(uint8_t ch) {
406 for (int j = 0; j < vector.size(); j++) {
407 int open = 1;
408 while (open > 0) {
409 open -= vector[j]->write(ch);
410 }
411 }
412 return 1;
413 }
414
416 void clear() {
417 for (auto &tmp : vector) {
418 if (tmp != nullptr && tmp->isDeletable()) {
419 delete tmp;
420 }
421 }
422 vector.clear();
423 }
424
425 protected:
427
429 void setOutput(Print &out) { add(out); }
430};
431
442 public:
443 TimedStream() = default;
444
445 TimedStream(AudioStream &io, long startSeconds = 0, long endSeconds = -1) {
446 p_stream = &io;
447 p_print = &io;
448 p_info = &io;
449 setStartSec(startSeconds);
450 setEndSec(endSeconds);
451 }
452
453 TimedStream(AudioOutput &o, long startSeconds = 0, long endSeconds = -1) {
454 p_print = &o;
455 p_info = &o;
456 setStartSec(startSeconds);
457 setEndSec(endSeconds);
458 }
459
460 TimedStream(Stream &io, long startSeconds = 0, long endSeconds = -1) {
461 p_stream = &io;
462 p_print = &io;
463 setStartSec(startSeconds);
464 setEndSec(endSeconds);
465 }
466
467 TimedStream(Print &o, long startSeconds = 0, long endSeconds = -1) {
468 p_print = &o;
469 setStartSec(startSeconds);
470 setEndSec(endSeconds);
471 }
472
475 void setStartSec(uint32_t startSeconds) {
476 start_ms = startSeconds * 1000;
477 calculateByteLimits();
478 }
479
481 void setStartMs(uint32_t ms) {
482 start_ms = ms;
483 calculateByteLimits();
484 }
485
488 void setEndSec(uint32_t endSeconds) {
489 end_ms = endSeconds * 1000;
490 calculateByteLimits();
491 }
492
494 void setEndMs(uint32_t ms) {
495 end_ms = ms;
496 calculateByteLimits();
497 }
498
500 bool isPlaying() {
501 if (current_bytes < start_bytes) return false;
502 if (end_bytes > 0 && current_bytes > end_bytes) return false;
503 return true;
504 }
505
507 bool isActive() {
508 return (current_bytes < end_bytes && current_bytes >= start_bytes);
509 }
510
511 bool begin(AudioInfo info) {
512 setAudioInfo(info);
513 return begin();
514 }
515
516 bool begin() override {
517 calculateByteLimits();
518 current_bytes = 0;
519 LOGI("byte range %u - %u",(unsigned) start_bytes,(unsigned) end_bytes);
520 return true;
521 }
522
523 operator bool() override { return isActive(); }
524
528 size_t readBytes(uint8_t *data, size_t len) override {
529 // if reading is not supported we stop
530 if (p_stream == nullptr) return 0;
531 // Positioin to start
532 if (start_bytes > current_bytes){
533 consumeBytes(start_bytes - current_bytes);
534 }
535 // if we are past the end we stop
536 if (!isActive()) return 0;
537 // read the data now
538 size_t result = 0;
539 do {
540 result = p_stream->readBytes(data, len);
541 current_bytes += len;
542 // ignore data before start time
543 } while (result > 0 && current_bytes < start_bytes);
544 return isPlaying() ? result : 0;
545 }
546
548 size_t write(const uint8_t *data, size_t len) override {
549 if (current_bytes >= end_bytes) return 0;
550 current_bytes += len;
551 if (current_bytes < start_bytes) return len;
552 return p_print->write(data, len);
553 }
554
556 int available() override {
557 if (p_stream == nullptr) return 0;
558 return current_bytes < end_bytes ? p_stream->available() : 0;
559 }
560
562 void setAudioInfo(AudioInfo info) override {
564 if (p_info) p_info->setAudioInfo(info);
565 calculateByteLimits();
566 }
567
568 int availableForWrite() override {
569 return current_bytes < end_bytes ? p_print->availableForWrite() : 0;
570 }
571
574 void setCompressionRatio(float ratio) { compression_ratio = ratio; }
575
578 return info.sample_rate * info.channels * info.bits_per_sample / 8;
579 }
580
581 void setOutput(Print &out) override { p_print = &out; }
582
583 void setStream(Stream &stream) override {
584 p_print = &stream;
585 p_stream = &stream;
586 }
587
588 void setOutput(AudioOutput &out) {
589 p_print = &out;
590 p_info = &out;
591 }
592
593 void setStream(AudioOutput &out) {
594 p_print = &out;
595 p_info = &out;
596 }
597
598 void setStream(AudioStream &stream) {
599 p_print = &stream;
600 p_stream = &stream;
601 p_info = &stream;
602 }
603
604 size_t size() {
605 return end_bytes - start_bytes;
606 }
607
608 protected:
609 Stream *p_stream = nullptr;
610 Print *p_print = nullptr;
611 AudioInfoSupport *p_info = nullptr;
612 uint32_t start_ms = 0;
613 uint32_t end_ms = UINT32_MAX;
614 uint32_t start_bytes = 0;
615 uint32_t end_bytes = UINT32_MAX;
616 uint32_t current_bytes = 0;
617 float compression_ratio = 1.0;
618
619 void consumeBytes(uint32_t len){
620 int open = len;
621 uint8_t buffer[1024];
622 while (open > 0){
623 int toread = min(1024, open);
624 p_stream->readBytes(buffer, toread);
625 open -= toread;
626 }
627 current_bytes += len;
628 LOGD("consumed %u -> %u",(unsigned) len, (unsigned)current_bytes);
629 }
630
631 void calculateByteLimits() {
632 float bytes_per_second = bytesPerSecond();
633 if (bytes_per_second > 0) {
634 start_bytes = bytes_per_second * start_ms / compression_ratio / 1000;
635 end_bytes = bytes_per_second * end_ms / compression_ratio / 1000;
636 } else {
637 LOGE("AudioInfo not defined");
638 }
639 }
640};
641
652 public:
653 ChannelsSelectOutput() = default;
654
655 bool begin(AudioInfo info) override {
656 setAudioInfo(info);
657 return begin();
658 }
659
660 bool begin() override {
661 AudioOutput::begin();
662 // make sure that selected channels are valid
663 for (auto &out : out_channels) {
664 for (auto &ch : out.channels) {
665 if (ch > cfg.channels - 1) {
666 LOGE("Channel '%d' not valid for max %d channels", ch, cfg.channels);
667 return false;
668 }
669 }
670 }
671 return true;
672 }
673
676 void addOutput(AudioOutput &out, uint16_t channel) {
677 Vector<uint16_t> channels;
678 channels.push_back(channel);
680 def.channels = channels;
681 def.p_out = &out;
682 def.p_audio_info = &out;
683 out_channels.push_back(def);
684 }
685
688 void addOutput(AudioStream &out, uint16_t channel) {
689 Vector<uint16_t> channels;
690 channels.push_back(channel);
692 def.channels = channels;
693 def.p_out = &out;
694 def.p_audio_info = &out;
695 out_channels.push_back(def);
696 }
697
700 void addOutput(Print &out, uint16_t channel) {
701 Vector<uint16_t> channels;
702 channels.push_back(channel);
704 def.channels = channels;
705 def.p_out = &out;
706 out_channels.push_back(def);
707 }
708
711 void addOutput(Print &out, uint16_t left, uint16_t right) {
712 Vector<uint16_t> channels;
713 channels.push_back(left);
714 channels.push_back(right);
716 def.channels = channels;
717 def.p_out = &out;
718 out_channels.push_back(def);
719 }
720
723 void addOutput(AudioOutput &out, uint16_t left, uint16_t right) {
724 Vector<uint16_t> channels;
725 channels.push_back(left);
726 channels.push_back(right);
728 def.channels = channels;
729 def.p_out = &out;
730 def.p_audio_info = &out;
731 out_channels.push_back(def);
732 }
733
736 void addOutput(AudioStream &out, uint16_t left, uint16_t right) {
737 Vector<uint16_t> channels;
738 channels.push_back(left);
739 channels.push_back(right);
741 def.channels = channels;
742 def.p_out = &out;
743 def.p_audio_info = &out;
744 out_channels.push_back(def);
745 }
746
747 size_t write(const uint8_t *data, size_t len) override {
748 if (!is_active) return false;
749 LOGD("write %d", (int)len);
750 switch (cfg.bits_per_sample) {
751 case 16:
752 return writeT<int16_t>(data, len);
753 case 24:
754 return writeT<int24_t>(data, len);
755 case 32:
756 return writeT<int32_t>(data, len);
757 default:
758 return 0;
759 }
760 }
761
762 void setAudioInfo(AudioInfo ai) override {
763 this->cfg = ai;
764 //notifyAudioChange(ai);
765 for (auto &info : out_channels) {
766 auto p_notify = info.p_audio_info;
767 if (p_notify != nullptr) {
768 AudioInfo result{ai};
769 result.channels = info.channels.size();
770 p_notify->setAudioInfo(result);
771 }
772 }
773 }
774
775 protected:
777 Print *p_out = nullptr;
778 AudioInfoSupport *p_audio_info = nullptr;
779 SingleBuffer<uint8_t> buffer{CHANNEL_SELECT_BUFFER_SIZE};
780 Vector<uint16_t> channels{0};
781 };
782 Vector<ChannelSelectionOutputDef> out_channels{0};
783
784 template <typename T>
785 size_t writeT(const uint8_t *buffer, size_t size) {
786 if (!is_active) return 0;
787 int sample_count = size / sizeof(T);
788 //int result_size = sample_count / cfg.channels;
789 T *data = (T *)buffer;
790
791 for (int i = 0; i < sample_count; i += cfg.channels) {
792 T *frame = data + i;
793 for (auto &out : out_channels) {
794 T out_frame[out.channels.size()];
795 int ch_out = 0;
796 for (auto &ch : out.channels) {
797 // make sure we have a valid channel
798 int channel = (ch < cfg.channels) ? ch : cfg.channels - 1;
799 out_frame[ch_out++] = frame[channel];
800 }
801 // write to buffer
802 size_t written = out.buffer.writeArray((const uint8_t *)&out_frame, sizeof(out_frame));
803 // write buffer to final output
804 if (out.buffer.availableForWrite()<sizeof(out_frame)){
805 out.p_out->write(out.buffer.data(), out.buffer.available());
806 out.buffer.reset();
807 }
808 // if (written != sizeof(out_frame)) {
809 // LOGW("Could not write all samples %d -> %d", sizeof(out_frame), written);
810 // }
811 }
812 }
813 return size;
814 }
815
817 int getChannels(Print *out, int defaultChannels) {
818 for (auto &channels_select : out_channels) {
819 if (channels_select.p_out == out) return channels_select.channels.size();
820 }
821 return defaultChannels;
822 }
823};
824
825} // namespace audio_tools
Wrapper which converts a AudioStream to a AudioOutput.
Definition AudioIO.h:295
virtual bool isDeletable()
If true we need to release the related memory in the destructor.
Definition AudioIO.h:316
void setAudioInfo(AudioInfo info) override
Defines the input AudioInfo.
Definition AudioIO.h:303
AudioInfo audioInfo() override
provides the actual input AudioInfo
Definition AudioIO.h:305
Wrapper which converts a AudioStream to a AudioOutput.
Definition AudioIO.h:260
virtual bool isDeletable() override
If true we need to release the related memory in the destructor.
Definition AudioIO.h:283
void setAudioInfo(AudioInfo info) override
Defines the input AudioInfo.
Definition AudioIO.h:268
AudioInfo audioInfo() override
provides the actual input AudioInfo
Definition AudioIO.h:270
Wrapper which converts a Print to a AudioOutput.
Definition AudioIO.h:237
virtual bool isDeletable()
If true we need to release the related memory in the destructor.
Definition AudioIO.h:247
void setAudioInfo(AudioInfo info)
Defines the input AudioInfo.
Definition AudioIO.h:242
AudioInfo audioInfo()
provides the actual input AudioInfo
Definition AudioIO.h:249
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:231
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:651
void addOutput(Print &out, uint16_t left, uint16_t right)
Definition AudioIO.h:711
void setAudioInfo(AudioInfo ai) override
Defines the input AudioInfo.
Definition AudioIO.h:762
void addOutput(Print &out, uint16_t channel)
Definition AudioIO.h:700
void addOutput(AudioOutput &out, uint16_t channel)
Definition AudioIO.h:676
int getChannels(Print *out, int defaultChannels)
Determine number of channels for destination.
Definition AudioIO.h:817
void addOutput(AudioStream &out, uint16_t channel)
Definition AudioIO.h:688
void addOutput(AudioStream &out, uint16_t left, uint16_t right)
Definition AudioIO.h:736
void addOutput(AudioOutput &out, uint16_t left, uint16_t right)
Definition AudioIO.h:723
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:330
void add(AudioOutput &out)
Add an additional AudioOutput output.
Definition AudioIO.h:366
void setAudioInfo(AudioInfo info)
Defines the input AudioInfo.
Definition AudioIO.h:386
void add(AudioStream &stream)
Add an AudioStream to the output.
Definition AudioIO.h:369
MultiOutput(AudioStream &out1, AudioStream &out2)
Defines a MultiOutput with 2 final outputs.
Definition AudioIO.h:349
MultiOutput(AudioOutput &out1, AudioOutput &out2)
Defines a MultiOutput with 2 final outputs.
Definition AudioIO.h:343
MultiOutput(AudioOutput &out)
Defines a MultiOutput with a single final outputs,.
Definition AudioIO.h:338
void clear()
Removes all output components.
Definition AudioIO.h:416
void setOutput(Print &out)
support for Pipleline
Definition AudioIO.h:429
MultiOutput(Print &out1, Print &out2)
Definition AudioIO.h:356
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:156
virtual void setStream(Stream &stream) override
Defines/Changes the input & output.
Definition AudioIO.h:158
virtual void setOutput(Print &print) override
Defines/Changes the output target.
Definition AudioIO.h:178
virtual TransformationReader< ReformatBaseStream > & transformationReader()
Provides access to the TransformationReader.
Definition AudioIO.h:212
void resizeReadResultQueue(int size)
Define the size of the interal read result queue: same as transformationReader().resizeResultQueue(si...
Definition AudioIO.h:209
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:441
void setOutput(Print &out) override
Defines/Changes the output target.
Definition AudioIO.h:581
void setStream(Stream &stream) override
Defines/Changes the input & output.
Definition AudioIO.h:583
void setEndSec(uint32_t endSeconds)
Definition AudioIO.h:488
void setEndMs(uint32_t ms)
Defines the (optional) end time in milliseconds.
Definition AudioIO.h:494
void setCompressionRatio(float ratio)
Definition AudioIO.h:574
size_t readBytes(uint8_t *data, size_t len) override
Definition AudioIO.h:528
void setStartSec(uint32_t startSeconds)
Definition AudioIO.h:475
int available() override
Provides the available bytes until the end time has reached.
Definition AudioIO.h:556
size_t write(const uint8_t *data, size_t len) override
Plays only data for the indiated start and end time.
Definition AudioIO.h:548
void setStartMs(uint32_t ms)
Defines the start time in milliseconds.
Definition AudioIO.h:481
bool isPlaying()
Returns true if we are in a valid time range and are still playing sound.
Definition AudioIO.h:500
bool isActive()
Returns true if we are not past the end time;.
Definition AudioIO.h:507
void setAudioInfo(AudioInfo info) override
Updates the AudioInfo in the current object and in the source or target.
Definition AudioIO.h:562
int bytesPerSecond()
Calculates the bytes per second from the AudioInfo.
Definition AudioIO.h:577
ConverterStream Helper class which implements the readBytes with the help of write.
Definition AudioIO.h:23
void begin(T *transform, Stream *source)
setup of the TransformationReader class
Definition AudioIO.h:29
void resizeReadBuffer(int size)
Defines the read buffer size for individual reads.
Definition AudioIO.h:45
void restoreOutput(Print *out)
restores the original output in the converter class
Definition AudioIO.h:145
Print * setupOutput()
Definition AudioIO.h:137
void resizeResultQueue(int size)
Defines the queue size for result.
Definition AudioIO.h:49
void setResultQueueFactor(int factor)
Defines the queue size dependent on the read size.
Definition AudioIO.h:123
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