arduino-audio-tools
Loading...
Searching...
No Matches
AudioIO.h
Go to the documentation of this file.
1#pragma once
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) {
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);
77 }
78
79 if (result_queue.available() < len) {
80 Print* tmp = setupOutput();
81 int zero_count = 0;
82 while (result_queue.available() < len) {
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;
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());
107 LOGD("TransformationReader::readBytes: %d -> %d", (int)len, result_len);
108
109 return result_len;
110 }
111
112 void end() {
114 buffer.resize(0);
115 }
116
118 void setResultQueueFactor(int factor) { result_queue_factor = factor; }
119
120 protected:
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;
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();
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:
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;
251};
252
258 public:
260
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:
286};
287
293 public:
295
297
298 void setOutput(AudioOutput& stream) { p_stream = &stream; }
299
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:
319};
320
328 public:
330 MultiOutput() = default;
331
332 MultiOutput(Print& out) { add(out); }
333
336
338
344
350
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;
450 }
451
453 p_print = &o;
454 p_info = &o;
457 }
458
459 TimedStream(Stream& io, long startSeconds = 0, long endSeconds = -1) {
460 p_stream = &io;
461 p_print = &io;
464 }
465
466 TimedStream(Print& o, long startSeconds = 0, long endSeconds = -1) {
467 p_print = &o;
470 }
471
478
481 start_ms = ms;
483 }
484
491
494 end_ms = ms;
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
509
512 return begin();
513 }
514
515 bool begin() override {
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
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
566
567 int availableForWrite() override {
569 }
570
573 void setCompressionRatio(float ratio) { compression_ratio = ratio; }
574
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
588 p_print = &out;
589 p_info = &out;
590 }
591
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;
614 float compression_ratio = 1.0;
615
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
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:
651
652 bool begin(AudioInfo info) override {
653 setAudioInfo(info);
654 return begin();
655 }
656
657 bool begin() override {
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:
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
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
#define CHANNEL_SELECT_BUFFER_SIZE
Definition AudioIO.h:10
#define MAX_ZERO_READ_COUNT
Definition AudioIO.h:6
#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 DEFAULT_BUFFER_SIZE
Definition avr.h:20
Wrapper which converts a AudioStream to a AudioOutput.
Definition AudioIO.h:292
void setOutput(AudioOutput &stream)
Definition AudioIO.h:298
virtual bool isDeletable()
If true we need to release the related memory in the destructor.
Definition AudioIO.h:313
AdapterAudioOutputToAudioStream(AudioOutput &stream)
Definition AudioIO.h:296
void end() override
Definition AudioIO.h:310
size_t write(const uint8_t *data, size_t len) override
Definition AudioIO.h:304
AudioOutput * p_stream
Definition AudioIO.h:318
bool begin() override
Definition AudioIO.h:308
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
void setStream(AudioStream &stream)
Definition AudioIO.h:263
virtual bool isDeletable() override
If true we need to release the related memory in the destructor.
Definition AudioIO.h:280
void end() override
Definition AudioIO.h:277
size_t write(const uint8_t *data, size_t len) override
Definition AudioIO.h:269
AdapterAudioStreamToAudioOutput(AudioStream &stream)
Definition AudioIO.h:261
int availableForWrite() override
Definition AudioIO.h:273
AudioStream * p_stream
Definition AudioIO.h:285
bool begin() override
Definition AudioIO.h:275
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
AdapterPrintToAudioOutput(Print &print)
Definition AudioIO.h:237
AudioInfo cfg
Definition AudioIO.h:250
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
void setStream(Print &out)
Definition AudioIO.h:238
AudioInfo audioInfo()
provides the actual input AudioInfo
Definition AudioIO.h:246
Print * p_print
Definition AudioIO.h:249
size_t write(const uint8_t *data, size_t len)
Definition AudioIO.h:240
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
SingleBuffer< uint8_t > tmp
Definition AudioOutput.h:89
AudioInfo cfg
Definition AudioOutput.h:88
bool is_active
Definition AudioOutput.h:90
virtual bool begin(AudioInfo info)
Definition AudioOutput.h:73
virtual bool begin()
Definition AudioOutput.h:78
virtual void setAudioInfo(AudioInfo newInfo) override
Defines the input AudioInfo.
Definition AudioOutput.h:49
virtual void end()
Definition AudioOutput.h:82
virtual size_t write(const uint8_t *data, size_t len) override=0
virtual AudioInfo audioInfo() override
provides the actual input AudioInfo
Definition AudioOutput.h:62
Base class for all Audio Streams. It support the boolean operator to test if the object is ready with...
Definition BaseStream.h:123
virtual size_t write(const uint8_t *data, size_t len) override
Definition BaseStream.h:149
AudioInfo info
Definition BaseStream.h:174
virtual void setAudioInfo(AudioInfo newInfo) override
Defines the input AudioInfo.
Definition BaseStream.h:131
virtual AudioInfo audioInfo() override
provides the actual input AudioInfo
Definition BaseStream.h:154
void clear()
same as reset
Definition Buffers.h:95
virtual bool begin()
Definition BaseStream.h:43
virtual int availableForWrite() override
Definition BaseStream.h:60
virtual void end()
Definition BaseStream.h:44
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
Vector< ChannelSelectionOutputDef > out_channels
Definition AudioIO.h:779
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
size_t write(const uint8_t *data, size_t len) override
Definition AudioIO.h:744
size_t writeT(const uint8_t *buffer, size_t size)
Definition AudioIO.h:782
bool begin(AudioInfo info) override
Definition AudioIO.h:652
bool begin() override
Definition AudioIO.h:657
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
MultiOutput(Print &out)
Definition AudioIO.h:332
Vector< AudioOutput * > vector
Definition AudioIO.h:425
size_t write(uint8_t ch) override
Definition AudioIO.h:404
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
size_t write(const uint8_t *data, size_t len) override
Definition AudioIO.h:387
void add(Print &print)
Definition AudioIO.h:370
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
MultiOutput(AudioStream &out)
Definition AudioIO.h:337
virtual ~MultiOutput()
Definition AudioIO.h:358
void clear()
Removes all output components.
Definition AudioIO.h:415
void flush()
Definition AudioIO.h:375
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 int availableForWrite()
Definition NoArduino.h:134
virtual size_t write(const uint8_t *data, size_t len)
Definition NoArduino.h:126
Stream class which stores the data in a temporary queue buffer. The queue can be consumed e....
Definition BaseStream.h:312
virtual bool begin() override
Activates the output.
Definition BaseStream.h:340
virtual size_t readBytes(uint8_t *data, size_t len) override
Definition BaseStream.h:398
int available() override
Definition BaseStream.h:364
Base class for chained converting streams.
Definition AudioIO.h:151
virtual void setStream(AudioStream &stream)
Definition AudioIO.h:159
virtual void setStream(Stream &stream) override
Defines/Changes the input & output.
Definition AudioIO.h:153
TransformationReader< ReformatBaseStream > reader
Definition AudioIO.h:213
virtual float getByteFactor()=0
virtual void setOutput(Print &print) override
Defines/Changes the output target.
Definition AudioIO.h:173
size_t readBytes(uint8_t *data, size_t len) override
Definition AudioIO.h:182
void end() override
Definition AudioIO.h:197
int available() override
Definition AudioIO.h:187
virtual Stream * getStream()
Definition AudioIO.h:180
virtual void setOutput(AudioOutput &print)
Definition AudioIO.h:167
Stream * p_stream
Definition AudioIO.h:214
virtual TransformationReader< ReformatBaseStream > & transformationReader()
Provides access to the TransformationReader.
Definition AudioIO.h:208
int availableForWrite() override
Definition AudioIO.h:191
virtual Print * getPrint()
Definition AudioIO.h:178
Print * p_print
Definition AudioIO.h:215
void setupReader()
Definition AudioIO.h:217
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
virtual size_t readBytes(uint8_t *data, size_t len)
Definition NoArduino.h:147
virtual int available()
Definition NoArduino.h:146
AudioStream class that can define a start and (an optional) stop time Usually it is used to wrap an A...
Definition AudioIO.h:440
TimedStream(Print &o, long startSeconds=0, long endSeconds=-1)
Definition AudioIO.h:466
void setOutput(Print &out) override
Defines/Changes the output target.
Definition AudioIO.h:580
size_t size()
Definition AudioIO.h:603
void setStream(Stream &stream) override
Defines/Changes the input & output.
Definition AudioIO.h:582
uint32_t end_ms
Definition AudioIO.h:610
void setEndSec(uint32_t endSeconds)
Definition AudioIO.h:487
uint32_t start_bytes
Definition AudioIO.h:611
void setEndMs(uint32_t ms)
Defines the (optional) end time in milliseconds.
Definition AudioIO.h:493
uint32_t current_bytes
Definition AudioIO.h:613
void setStream(AudioOutput &out)
Definition AudioIO.h:592
void setCompressionRatio(float ratio)
Definition AudioIO.h:573
uint32_t start_ms
Definition AudioIO.h:609
void setOutput(AudioOutput &out)
Definition AudioIO.h:587
size_t readBytes(uint8_t *data, size_t len) override
Definition AudioIO.h:527
void setStartSec(uint32_t startSeconds)
Definition AudioIO.h:474
TimedStream(Stream &io, long startSeconds=0, long endSeconds=-1)
Definition AudioIO.h:459
void setStream(AudioStream &stream)
Definition AudioIO.h:597
TimedStream(AudioStream &io, long startSeconds=0, long endSeconds=-1)
Definition AudioIO.h:444
void consumeBytes(uint32_t len)
Definition AudioIO.h:616
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
Stream * p_stream
Definition AudioIO.h:606
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
int availableForWrite() override
Definition AudioIO.h:567
AudioInfoSupport * p_info
Definition AudioIO.h:608
bool isActive()
Returns true if we are not past the end time;.
Definition AudioIO.h:506
void calculateByteLimits()
Definition AudioIO.h:628
bool begin() override
Definition AudioIO.h:515
Print * p_print
Definition AudioIO.h:607
uint32_t end_bytes
Definition AudioIO.h:612
TimedStream(AudioOutput &o, long startSeconds=0, long endSeconds=-1)
Definition AudioIO.h:452
void setAudioInfo(AudioInfo info) override
Updates the AudioInfo in the current object and in the source or target.
Definition AudioIO.h:561
float compression_ratio
Definition AudioIO.h:614
bool begin(AudioInfo info)
Definition AudioIO.h:510
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
bool active
Definition AudioIO.h:126
QueueStream< uint8_t > result_queue
Definition AudioIO.h:122
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
RingBuffer< uint8_t > result_queue_buffer
Definition AudioIO.h:121
T * p_transform
Definition AudioIO.h:125
void restoreOutput(Print *out)
restores the original output in the converter class
Definition AudioIO.h:140
Stream * p_stream
Definition AudioIO.h:123
size_t readBytes(uint8_t *data, size_t len)
Definition AudioIO.h:51
Print * setupOutput()
Definition AudioIO.h:132
void end()
Definition AudioIO.h:112
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
int result_queue_factor
Definition AudioIO.h:127
Vector< uint8_t > buffer
Definition AudioIO.h:124
Vector implementation which provides the most important methods as defined by std::vector....
Definition Vector.h:21
void push_back(T &&value)
Definition Vector.h:182
bool resize(int newSize, T value)
Definition Vector.h:266
T * data()
Definition Vector.h:316
int size()
Definition Vector.h:178
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition AudioCodecsBase.h:10
void delay(unsigned long ms)
Definition Time.h:23
size_t writeData(Print *p_out, T *data, int samples, int maxSamples=512)
Definition AudioTypes.h:512
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
AudioInfoSupport * p_audio_info
Definition AudioIO.h:775
Vector< uint16_t > channels
Definition AudioIO.h:777
SingleBuffer< uint8_t > buffer
Definition AudioIO.h:776