diff --git a/_audio_encoded_8h_source.html b/_audio_encoded_8h_source.html index 74f93de07..2c2bea50e 100644 --- a/_audio_encoded_8h_source.html +++ b/_audio_encoded_8h_source.html @@ -514,7 +514,7 @@
audio_tools::AudioEncoder::setAudioInfo
void setAudioInfo(AudioInfo from) override
Defines the sample rate, number of channels and bits per sample.
Definition: AudioCodecsBase.h:93
audio_tools::AudioInfoSource::addNotifyAudioChange
virtual void addNotifyAudioChange(AudioInfoSupport &bi)
Adds target to be notified about audio changes.
Definition: AudioTypes.h:162
audio_tools::AudioInfoSupport
Supports changes to the sampling rate, bits and channels.
Definition: AudioTypes.h:139
-
audio_tools::AudioOutputAdapter
Base class for Output Adpapters.
Definition: AudioIO.h:226
+
audio_tools::AudioOutputAdapter
Base class for Output Adpapters.
Definition: AudioIO.h:225
audio_tools::AudioOutput
Abstract Audio Ouptut class.
Definition: AudioOutput.h:22
audio_tools::AudioStream
Base class for all Audio Streams. It support the boolean operator to test if the object is ready with...
Definition: BaseStream.h:109
audio_tools::AudioStream::setAudioInfo
virtual void setAudioInfo(AudioInfo newInfo) override
Defines the input AudioInfo.
Definition: BaseStream.h:117
@@ -548,8 +548,8 @@
audio_tools::EncodedAudioStream::setOutput
void setOutput(Print &out)
Defines/Changes the output target.
Definition: AudioEncoded.h:332
audio_tools::ModifyingOutput
Abstract class: Objects can be put into a pipleline.
Definition: AudioOutput.h:97
audio_tools::Print
Definition: NoArduino.h:58
-
audio_tools::ReformatBaseStream
Base class for chained converting streams.
Definition: AudioIO.h:155
-
audio_tools::ReformatBaseStream::setStream
virtual void setStream(Stream &stream) override
Defines/Changes the input & output.
Definition: AudioIO.h:157
+
audio_tools::ReformatBaseStream
Base class for chained converting streams.
Definition: AudioIO.h:154
+
audio_tools::ReformatBaseStream::setStream
virtual void setStream(Stream &stream) override
Defines/Changes the input & output.
Definition: AudioIO.h:156
audio_tools::Stream
Definition: NoArduino.h:125
audio_tools
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition: AudioConfig.h:868
audio_tools::AudioInfo
Basic Audio information which drives e.g. I2S.
Definition: AudioTypes.h:52
diff --git a/_audio_i_o_8h_source.html b/_audio_i_o_8h_source.html index 7e397eb4a..163cb5190 100644 --- a/_audio_i_o_8h_source.html +++ b/_audio_i_o_8h_source.html @@ -184,648 +184,647 @@
127  Vector<uint8_t> buffer{0}; // we allocate memory only when needed
128  T *p_transform = nullptr;
129  bool active = false;
-
130  int result_queue_factor = 10;
-
131  int result_queue_size = 0;
-
132 
-
136  Print *setupOutput() {
-
137  Print *result = p_transform->getPrint();
-
138  p_transform->setOutput((Print &)result_queue);
-
139 
-
140  return result;
-
141  }
-
144  void restoreOutput(Print *out) {
-
145  if (out) p_transform->setOutput(*out);
-
146  }
-
147 };
-
148 
-
155 class ReformatBaseStream : public ModifyingStream {
-
156  public:
-
157  virtual void setStream(Stream &stream) override {
-
158  TRACED();
-
159  p_stream = &stream;
-
160  p_print = &stream;
-
161  }
-
162 
-
163  virtual void setStream(AudioStream &stream) {
-
164  TRACED();
-
165  p_stream = &stream;
-
166  p_print = &stream;
-
167  //setNotifyOnOutput(stream);
-
168  addNotifyAudioChange(stream);
-
169  }
-
170 
-
171  virtual void setOutput(AudioOutput &print) {
-
172  TRACED();
-
173  p_print = &print;
-
174  addNotifyAudioChange(print);
-
175  }
-
176 
-
177  virtual void setOutput(Print &print) override {
-
178  TRACED();
-
179  p_print = &print;
-
180  }
-
181 
-
182  virtual Print *getPrint() { return p_print; }
-
183 
-
184  virtual Stream *getStream() { return p_stream; }
-
185 
-
186  size_t readBytes(uint8_t *data, size_t len) override {
-
187  LOGD("ReformatBaseStream::readBytes: %d", (int)len);
-
188  return reader.readBytes(data, len);
-
189  }
-
190 
-
191  int available() override {
-
192  return DEFAULT_BUFFER_SIZE; // reader.availableForWrite();
-
193  }
-
194 
-
195  int availableForWrite() override {
-
196  return DEFAULT_BUFFER_SIZE; // reader.availableForWrite();
-
197  }
-
198 
-
199  virtual float getByteFactor() = 0;
-
200 
-
201  void end() override {
-
202  TRACED();
-
203  AudioStream::end();
-
204  reader.end();
-
205  }
-
206 
-
208  virtual TransformationReader<ReformatBaseStream> &transformationReader() {return reader;}
-
209 
-
210  protected:
-
211  TransformationReader<ReformatBaseStream> reader;
-
212  Stream *p_stream = nullptr;
-
213  Print *p_print = nullptr;
-
214 
-
215  void setupReader() {
-
216  if (getStream() != nullptr) {
-
217  reader.begin(this, getStream());
-
218  }
-
219  }
-
220 };
-
221 
-
226 class AudioOutputAdapter : public AudioOutput {};
-
227 
-
232 class AdapterPrintToAudioOutput : public AudioOutputAdapter {
-
233  public:
-
234  AdapterPrintToAudioOutput(Print &print) { p_print = &print; }
-
235  void setAudioInfo(AudioInfo info) {}
-
236  size_t write(const uint8_t *data, size_t len) {
-
237  return p_print->write(data, len);
-
238  }
-
240  virtual bool isDeletable() { return true; }
-
241 
-
242  protected:
-
243  Print *p_print = nullptr;
-
244 };
-
245 
-
250 class AdapterAudioStreamToAudioOutput : public AudioOutputAdapter {
-
251  public:
-
252  AdapterAudioStreamToAudioOutput() = default;
-
253 
-
254  AdapterAudioStreamToAudioOutput(AudioStream &stream) { setStream(stream); }
-
255 
-
256  void setStream(AudioStream &stream) { p_stream = &stream; }
-
257 
-
258  void setAudioInfo(AudioInfo info) override { p_stream->setAudioInfo(info); }
-
259 
-
260  AudioInfo audioInfo() override { return p_stream->audioInfo(); }
-
261 
-
262  size_t write(const uint8_t *data, size_t len) override {
-
263  return p_stream->write(data, len);
-
264  }
-
265 
-
266  int availableForWrite() override { return p_stream->availableForWrite(); }
-
267 
-
268  bool begin() override { return p_stream->begin(); }
-
269 
-
270  void end() override { p_stream->end(); }
-
271 
-
273  virtual bool isDeletable() { return true; }
-
274 
-
275  operator bool() override { return *p_stream; }
-
276 
-
277  protected:
-
278  AudioStream *p_stream = nullptr;
-
279 };
-
280 
-
285 class AdapterAudioOutputToAudioStream : public AudioStream {
-
286  public:
-
287  AdapterAudioOutputToAudioStream() = default;
-
288 
-
289  AdapterAudioOutputToAudioStream(AudioOutput &stream) { setOutput(stream); }
-
290 
-
291  void setOutput(AudioOutput &stream) { p_stream = &stream; }
-
292 
-
293  void setAudioInfo(AudioInfo info) override { p_stream->setAudioInfo(info); }
-
294 
-
295  AudioInfo audioInfo() override { return p_stream->audioInfo(); }
-
296 
-
297  size_t write(const uint8_t *data, size_t len) override {
-
298  return p_stream->write(data, len);
-
299  }
-
300 
-
301  bool begin() override { return p_stream->begin(); }
-
302 
-
303  void end() override { p_stream->end(); }
-
304 
-
306  virtual bool isDeletable() { return true; }
-
307 
-
308  operator bool() override { return *p_stream; }
-
309 
-
310  protected:
-
311  AudioOutput *p_stream = nullptr;
-
312 };
-
313 
-
320 class MultiOutput : public ModifyingOutput {
-
321  public:
-
323  MultiOutput() = default;
-
324 
-
325  MultiOutput(Print &out) { add(out); }
-
326 
-
328  MultiOutput(AudioOutput &out) { add(out); }
-
329 
-
330  MultiOutput(AudioStream &out) { add(out); }
-
331 
-
333  MultiOutput(AudioOutput &out1, AudioOutput &out2) {
-
334  add(out1);
-
335  add(out2);
-
336  }
-
337 
-
339  MultiOutput(AudioStream &out1, AudioStream &out2) {
-
340  add(out1);
-
341  add(out2);
-
342  }
-
343 
-
346  MultiOutput(Print &out1, Print &out2) {
-
347  add(out1);
-
348  add(out2);
-
349  }
-
350 
-
351  virtual ~MultiOutput() {
-
352  for (int j = 0; j < vector.size(); j++) {
-
353  if (vector[j]->isDeletable()) {
-
354  delete vector[j];
-
355  }
-
356  }
-
357  }
-
358 
-
360  void add(AudioOutput &out) { vector.push_back(&out); }
-
361 
-
363  void add(AudioStream &stream) {
-
364  AdapterAudioStreamToAudioOutput *out =
-
365  new AdapterAudioStreamToAudioOutput(stream);
-
366  vector.push_back(out);
-
367  }
-
368 
-
369  void add(Print &print) {
-
370  AdapterPrintToAudioOutput *out = new AdapterPrintToAudioOutput(print);
-
371  vector.push_back(out);
-
372  }
-
373 
-
374  void flush() {
-
375  for (int j = 0; j < vector.size(); j++) {
-
376  vector[j]->flush();
-
377  }
-
378  }
-
379 
-
380  void setAudioInfo(AudioInfo info) {
-
381  for (int j = 0; j < vector.size(); j++) {
-
382  vector[j]->setAudioInfo(info);
-
383  }
-
384  }
-
385 
-
386  size_t write(const uint8_t *data, size_t len) {
-
387  for (int j = 0; j < vector.size(); j++) {
-
388  int open = len;
-
389  int start = 0;
-
390  while (open > 0) {
-
391  int written = vector[j]->write(data + start, open);
-
392  open -= written;
-
393  start += written;
-
394  }
-
395  }
-
396  return len;
-
397  }
-
398 
-
399  size_t write(uint8_t ch) {
-
400  for (int j = 0; j < vector.size(); j++) {
-
401  int open = 1;
-
402  while (open > 0) {
-
403  open -= vector[j]->write(ch);
-
404  }
-
405  }
-
406  return 1;
-
407  }
-
408 
-
409  protected:
-
410  Vector<AudioOutput *> vector;
-
412  void setOutput(Print &out) { add(out); }
-
413 };
-
414 
-
424 class TimedStream : public ModifyingStream {
-
425  public:
-
426  TimedStream() = default;
-
427 
-
428  TimedStream(AudioStream &io, long startSeconds = 0, long endSeconds = -1) {
-
429  p_stream = &io;
-
430  p_print = &io;
-
431  p_info = &io;
-
432  setStartSec(startSeconds);
-
433  setEndSec(endSeconds);
-
434  }
-
435 
-
436  TimedStream(AudioOutput &o, long startSeconds = 0, long endSeconds = -1) {
-
437  p_print = &o;
-
438  p_info = &o;
-
439  setStartSec(startSeconds);
-
440  setEndSec(endSeconds);
-
441  }
-
442 
-
445  void setStartSec(uint32_t startSeconds) {
-
446  start_ms = startSeconds * 1000;
-
447  calculateByteLimits();
-
448  }
-
449 
-
451  void setStartMs(uint32_t ms) {
-
452  start_ms = ms;
-
453  calculateByteLimits();
-
454  }
-
455 
-
458  void setEndSec(uint32_t endSeconds) {
-
459  end_ms = endSeconds * 1000;
-
460  calculateByteLimits();
-
461  }
-
462 
-
464  void setEndMs(uint32_t ms) {
-
465  end_ms = ms;
-
466  calculateByteLimits();
-
467  }
-
468 
-
470  bool isPlaying() {
-
471  if (current_bytes < start_bytes) return false;
-
472  if (end_bytes > 0 && current_bytes > end_bytes) return false;
-
473  return true;
-
474  }
-
475 
-
477  bool isActive() {
-
478  return (current_bytes < end_bytes && current_bytes >= start_bytes);
-
479  }
-
480 
-
481  bool begin(AudioInfo info) {
-
482  setAudioInfo(info);
-
483  return begin();
-
484  }
-
485 
-
486  bool begin() override {
-
487  calculateByteLimits();
-
488  current_bytes = 0;
-
489  LOGI("byte range %u - %u",(unsigned) start_bytes,(unsigned) end_bytes);
-
490  return true;
-
491  }
-
492 
-
493  operator bool() { return isActive(); }
-
494 
-
498  size_t readBytes(uint8_t *data, size_t len) override {
-
499  // if reading is not supported we stop
-
500  if (p_stream == nullptr) return 0;
-
501  // Positioin to start
-
502  if (start_bytes > current_bytes){
-
503  consumeBytes(start_bytes - current_bytes);
-
504  }
-
505  // if we are past the end we stop
-
506  if (!isActive()) return 0;
-
507  // read the data now
-
508  size_t result = 0;
-
509  do {
-
510  result = p_stream->readBytes(data, len);
-
511  current_bytes += len;
-
512  // ignore data before start time
-
513  } while (result > 0 && current_bytes < start_bytes);
-
514  return isPlaying() ? result : 0;
-
515  }
-
516 
-
518  size_t write(const uint8_t *data, size_t len) override {
-
519  if (current_bytes >= end_bytes) return 0;
-
520  current_bytes += len;
-
521  if (current_bytes < start_bytes) return len;
-
522  return p_print->write(data, len);
-
523  }
-
524 
-
526  int available() override {
-
527  if (p_stream == nullptr) return 0;
-
528  return current_bytes < end_bytes ? p_stream->available() : 0;
-
529  }
-
530 
-
532  void setAudioInfo(AudioInfo info) override {
-
533  AudioStream::setAudioInfo(info);
-
534  if (p_info) p_info->setAudioInfo(info);
-
535  calculateByteLimits();
-
536  }
-
537 
-
538  int availableForWrite() override {
-
539  return current_bytes < end_bytes ? p_print->availableForWrite() : 0;
-
540  }
-
541 
-
544  void setCompressionRatio(float ratio) { compression_ratio = ratio; }
-
545 
-
547  int bytesPerSecond() {
-
548  return info.sample_rate * info.channels * info.bits_per_sample / 8;
-
549  }
-
550 
-
551  void setOutput(Print &out) { p_print = &out; }
-
552 
-
553  void setStream(Stream &stream) {
-
554  p_print = &stream;
-
555  p_stream = &stream;
-
556  }
-
557 
-
558  void setOutput(AudioOutput &out) {
-
559  p_print = &out;
-
560  p_info = &out;
-
561  }
-
562 
-
563  void setStream(AudioOutput &out) {
-
564  p_print = &out;
-
565  p_info = &out;
-
566  }
-
567 
-
568  void setStream(AudioStream &stream) {
-
569  p_print = &stream;
-
570  p_stream = &stream;
-
571  p_info = &stream;
-
572  }
-
573 
-
574  size_t size() {
-
575  return end_bytes - start_bytes;
-
576  }
-
577 
-
578  protected:
-
579  Stream *p_stream = nullptr;
-
580  Print *p_print = nullptr;
-
581  AudioInfoSupport *p_info = nullptr;
-
582  uint32_t start_ms = 0;
-
583  uint32_t end_ms = UINT32_MAX;
-
584  uint32_t start_bytes = 0;
-
585  uint32_t end_bytes = UINT32_MAX;
-
586  uint32_t current_bytes = 0;
-
587  float compression_ratio = 1.0;
-
588 
-
589  void consumeBytes(uint32_t len){
-
590  int open = len;
-
591  uint8_t buffer[1024];
-
592  while (open > 0){
-
593  int toread = min(1024, open);
-
594  p_stream->readBytes(buffer, toread);
-
595  open -= toread;
-
596  }
-
597  current_bytes += len;
-
598  LOGD("consumed %u -> %u",(unsigned) len, (unsigned)current_bytes);
-
599  }
-
600 
-
601  void calculateByteLimits() {
-
602  float bytes_per_second = bytesPerSecond();
-
603  if (bytes_per_second > 0) {
-
604  start_bytes = bytes_per_second * start_ms / compression_ratio / 1000;
-
605  end_bytes = bytes_per_second * end_ms / compression_ratio / 1000;
-
606  } else {
-
607  LOGE("AudioInfo not defined");
-
608  }
-
609  }
-
610 };
-
611 
-
621 class ChannelsSelectOutput : public AudioOutput {
-
622  public:
-
623  ChannelsSelectOutput() = default;
-
624 
-
625  bool begin(AudioInfo info) {
-
626  setAudioInfo(info);
-
627  return begin();
-
628  }
-
629 
-
630  bool begin() {
-
631  AudioOutput::begin();
-
632  // make sure that selected channels are valid
-
633  for (auto &out : out_channels) {
-
634  for (auto &ch : out.channels) {
-
635  if (ch > cfg.channels - 1) {
-
636  LOGE("Channel '%d' not valid for max %d channels", ch, cfg.channels);
-
637  return false;
-
638  }
-
639  }
-
640  }
-
641  return true;
-
642  }
-
643 
-
646  void addOutput(AudioOutput &out, uint16_t channel) {
-
647  Vector<uint16_t> channels;
-
648  channels.push_back(channel);
-
649  ChannelSelectionOutputDef def;
-
650  def.channels = channels;
-
651  def.p_out = &out;
-
652  def.p_audio_info = &out;
-
653  out_channels.push_back(def);
-
654  }
-
655 
-
658  void addOutput(AudioStream &out, uint16_t channel) {
-
659  Vector<uint16_t> channels;
-
660  channels.push_back(channel);
-
661  ChannelSelectionOutputDef def;
-
662  def.channels = channels;
-
663  def.p_out = &out;
-
664  def.p_audio_info = &out;
-
665  out_channels.push_back(def);
-
666  }
-
667 
-
670  void addOutput(Print &out, uint16_t channel) {
-
671  Vector<uint16_t> channels;
-
672  channels.push_back(channel);
-
673  ChannelSelectionOutputDef def;
-
674  def.channels = channels;
-
675  def.p_out = &out;
-
676  out_channels.push_back(def);
-
677  }
-
678 
-
681  void addOutput(Print &out, uint16_t left, uint16_t right) {
-
682  Vector<uint16_t> channels;
-
683  channels.push_back(left);
-
684  channels.push_back(right);
-
685  ChannelSelectionOutputDef def;
-
686  def.channels = channels;
-
687  def.p_out = &out;
-
688  out_channels.push_back(def);
-
689  }
-
690 
-
693  void addOutput(AudioOutput &out, uint16_t left, uint16_t right) {
-
694  Vector<uint16_t> channels;
-
695  channels.push_back(left);
-
696  channels.push_back(right);
-
697  ChannelSelectionOutputDef def;
-
698  def.channels = channels;
-
699  def.p_out = &out;
-
700  def.p_audio_info = &out;
-
701  out_channels.push_back(def);
-
702  }
-
703 
-
706  void addOutput(AudioStream &out, uint16_t left, uint16_t right) {
-
707  Vector<uint16_t> channels;
-
708  channels.push_back(left);
-
709  channels.push_back(right);
-
710  ChannelSelectionOutputDef def;
-
711  def.channels = channels;
-
712  def.p_out = &out;
-
713  def.p_audio_info = &out;
-
714  out_channels.push_back(def);
-
715  }
-
716 
-
717  size_t write(const uint8_t *data, size_t len) override {
-
718  if (!is_active) return false;
-
719  LOGD("write %d", (int)len);
-
720  switch (cfg.bits_per_sample) {
-
721  case 16:
-
722  return writeT<int16_t>(data, len);
-
723  case 24:
-
724  return writeT<int24_t>(data, len);
-
725  case 32:
-
726  return writeT<int32_t>(data, len);
-
727  default:
-
728  return 0;
-
729  }
-
730  }
-
731 
-
732  void setAudioInfo(AudioInfo ai) override {
-
733  this->cfg = ai;
-
734  //notifyAudioChange(ai);
-
735  for (auto &info : out_channels) {
-
736  auto p_notify = info.p_audio_info;
-
737  if (p_notify != nullptr) {
-
738  AudioInfo result{ai};
-
739  result.channels = info.channels.size();
-
740  p_notify->setAudioInfo(result);
-
741  }
-
742  }
-
743  }
-
744 
-
745  protected:
-
746  struct ChannelSelectionOutputDef {
-
747  Print *p_out = nullptr;
-
748  AudioInfoSupport *p_audio_info = nullptr;
-
749  SingleBuffer<uint8_t> buffer{CHANNEL_SELECT_BUFFER_SIZE};
-
750  Vector<uint16_t> channels{0};
-
751  };
-
752  Vector<ChannelSelectionOutputDef> out_channels{0};
-
753 
-
754  template <typename T>
-
755  size_t writeT(const uint8_t *buffer, size_t size) {
-
756  if (!is_active) return 0;
-
757  int sample_count = size / sizeof(T);
-
758  //int result_size = sample_count / cfg.channels;
-
759  T *data = (T *)buffer;
-
760 
-
761  for (int i = 0; i < sample_count; i += cfg.channels) {
-
762  T *frame = data + i;
-
763  for (auto &out : out_channels) {
-
764  T out_frame[out.channels.size()] = {0};
-
765  int ch_out = 0;
-
766  for (auto &ch : out.channels) {
-
767  // make sure we have a valid channel
-
768  int channel = (ch < cfg.channels) ? ch : cfg.channels - 1;
-
769  out_frame[ch_out++] = frame[channel];
-
770  }
-
771  // write to buffer
-
772  size_t written = out.buffer.writeArray((const uint8_t *)&out_frame, sizeof(out_frame));
-
773  // write buffer to final output
-
774  if (out.buffer.availableForWrite()<sizeof(out_frame)){
-
775  out.p_out->write(out.buffer.data(), out.buffer.available());
-
776  out.buffer.reset();
-
777  }
-
778  // if (written != sizeof(out_frame)) {
-
779  // LOGW("Could not write all samples %d -> %d", sizeof(out_frame), written);
-
780  // }
-
781  }
-
782  }
-
783  return size;
-
784  }
-
785 
-
787  int getChannels(Print *out, int defaultChannels) {
-
788  for (auto &channels_select : out_channels) {
-
789  if (channels_select.p_out == out) return channels_select.channels.size();
-
790  }
-
791  return defaultChannels;
-
792  }
-
793 };
-
794 
-
795 } // namespace audio_tools
-
audio_tools::AdapterAudioOutputToAudioStream
Wrapper which converts a AudioStream to a AudioOutput.
Definition: AudioIO.h:285
-
audio_tools::AdapterAudioOutputToAudioStream::isDeletable
virtual bool isDeletable()
If true we need to release the related memory in the destructor.
Definition: AudioIO.h:306
-
audio_tools::AdapterAudioOutputToAudioStream::setAudioInfo
void setAudioInfo(AudioInfo info) override
Defines the input AudioInfo.
Definition: AudioIO.h:293
-
audio_tools::AdapterAudioOutputToAudioStream::audioInfo
AudioInfo audioInfo() override
provides the actual input AudioInfo
Definition: AudioIO.h:295
-
audio_tools::AdapterAudioStreamToAudioOutput
Wrapper which converts a AudioStream to a AudioOutput.
Definition: AudioIO.h:250
-
audio_tools::AdapterAudioStreamToAudioOutput::isDeletable
virtual bool isDeletable()
If true we need to release the related memory in the destructor.
Definition: AudioIO.h:273
-
audio_tools::AdapterAudioStreamToAudioOutput::setAudioInfo
void setAudioInfo(AudioInfo info) override
Defines the input AudioInfo.
Definition: AudioIO.h:258
-
audio_tools::AdapterAudioStreamToAudioOutput::audioInfo
AudioInfo audioInfo() override
provides the actual input AudioInfo
Definition: AudioIO.h:260
-
audio_tools::AdapterPrintToAudioOutput
Wrapper which converts a Print to a AudioOutput.
Definition: AudioIO.h:232
-
audio_tools::AdapterPrintToAudioOutput::isDeletable
virtual bool isDeletable()
If true we need to release the related memory in the destructor.
Definition: AudioIO.h:240
-
audio_tools::AdapterPrintToAudioOutput::setAudioInfo
void setAudioInfo(AudioInfo info)
Defines the input AudioInfo.
Definition: AudioIO.h:235
+
130  int result_queue_factor = 5;
+
131 
+
135  Print *setupOutput() {
+
136  Print *result = p_transform->getPrint();
+
137  p_transform->setOutput((Print &)result_queue);
+
138 
+
139  return result;
+
140  }
+
143  void restoreOutput(Print *out) {
+
144  if (out) p_transform->setOutput(*out);
+
145  }
+
146 };
+
147 
+
154 class ReformatBaseStream : public ModifyingStream {
+
155  public:
+
156  virtual void setStream(Stream &stream) override {
+
157  TRACED();
+
158  p_stream = &stream;
+
159  p_print = &stream;
+
160  }
+
161 
+
162  virtual void setStream(AudioStream &stream) {
+
163  TRACED();
+
164  p_stream = &stream;
+
165  p_print = &stream;
+
166  //setNotifyOnOutput(stream);
+
167  addNotifyAudioChange(stream);
+
168  }
+
169 
+
170  virtual void setOutput(AudioOutput &print) {
+
171  TRACED();
+
172  p_print = &print;
+
173  addNotifyAudioChange(print);
+
174  }
+
175 
+
176  virtual void setOutput(Print &print) override {
+
177  TRACED();
+
178  p_print = &print;
+
179  }
+
180 
+
181  virtual Print *getPrint() { return p_print; }
+
182 
+
183  virtual Stream *getStream() { return p_stream; }
+
184 
+
185  size_t readBytes(uint8_t *data, size_t len) override {
+
186  LOGD("ReformatBaseStream::readBytes: %d", (int)len);
+
187  return reader.readBytes(data, len);
+
188  }
+
189 
+
190  int available() override {
+
191  return DEFAULT_BUFFER_SIZE; // reader.availableForWrite();
+
192  }
+
193 
+
194  int availableForWrite() override {
+
195  return DEFAULT_BUFFER_SIZE; // reader.availableForWrite();
+
196  }
+
197 
+
198  virtual float getByteFactor() = 0;
+
199 
+
200  void end() override {
+
201  TRACED();
+
202  AudioStream::end();
+
203  reader.end();
+
204  }
+
205 
+
207  virtual TransformationReader<ReformatBaseStream> &transformationReader() {return reader;}
+
208 
+
209  protected:
+
210  TransformationReader<ReformatBaseStream> reader;
+
211  Stream *p_stream = nullptr;
+
212  Print *p_print = nullptr;
+
213 
+
214  void setupReader() {
+
215  if (getStream() != nullptr) {
+
216  reader.begin(this, getStream());
+
217  }
+
218  }
+
219 };
+
220 
+
225 class AudioOutputAdapter : public AudioOutput {};
+
226 
+
231 class AdapterPrintToAudioOutput : public AudioOutputAdapter {
+
232  public:
+
233  AdapterPrintToAudioOutput(Print &print) { p_print = &print; }
+
234  void setAudioInfo(AudioInfo info) {}
+
235  size_t write(const uint8_t *data, size_t len) {
+
236  return p_print->write(data, len);
+
237  }
+
239  virtual bool isDeletable() { return true; }
+
240 
+
241  protected:
+
242  Print *p_print = nullptr;
+
243 };
+
244 
+
249 class AdapterAudioStreamToAudioOutput : public AudioOutputAdapter {
+
250  public:
+
251  AdapterAudioStreamToAudioOutput() = default;
+
252 
+
253  AdapterAudioStreamToAudioOutput(AudioStream &stream) { setStream(stream); }
+
254 
+
255  void setStream(AudioStream &stream) { p_stream = &stream; }
+
256 
+
257  void setAudioInfo(AudioInfo info) override { p_stream->setAudioInfo(info); }
+
258 
+
259  AudioInfo audioInfo() override { return p_stream->audioInfo(); }
+
260 
+
261  size_t write(const uint8_t *data, size_t len) override {
+
262  return p_stream->write(data, len);
+
263  }
+
264 
+
265  int availableForWrite() override { return p_stream->availableForWrite(); }
+
266 
+
267  bool begin() override { return p_stream->begin(); }
+
268 
+
269  void end() override { p_stream->end(); }
+
270 
+
272  virtual bool isDeletable() { return true; }
+
273 
+
274  operator bool() override { return *p_stream; }
+
275 
+
276  protected:
+
277  AudioStream *p_stream = nullptr;
+
278 };
+
279 
+
284 class AdapterAudioOutputToAudioStream : public AudioStream {
+
285  public:
+
286  AdapterAudioOutputToAudioStream() = default;
+
287 
+
288  AdapterAudioOutputToAudioStream(AudioOutput &stream) { setOutput(stream); }
+
289 
+
290  void setOutput(AudioOutput &stream) { p_stream = &stream; }
+
291 
+
292  void setAudioInfo(AudioInfo info) override { p_stream->setAudioInfo(info); }
+
293 
+
294  AudioInfo audioInfo() override { return p_stream->audioInfo(); }
+
295 
+
296  size_t write(const uint8_t *data, size_t len) override {
+
297  return p_stream->write(data, len);
+
298  }
+
299 
+
300  bool begin() override { return p_stream->begin(); }
+
301 
+
302  void end() override { p_stream->end(); }
+
303 
+
305  virtual bool isDeletable() { return true; }
+
306 
+
307  operator bool() override { return *p_stream; }
+
308 
+
309  protected:
+
310  AudioOutput *p_stream = nullptr;
+
311 };
+
312 
+
319 class MultiOutput : public ModifyingOutput {
+
320  public:
+
322  MultiOutput() = default;
+
323 
+
324  MultiOutput(Print &out) { add(out); }
+
325 
+
327  MultiOutput(AudioOutput &out) { add(out); }
+
328 
+
329  MultiOutput(AudioStream &out) { add(out); }
+
330 
+
332  MultiOutput(AudioOutput &out1, AudioOutput &out2) {
+
333  add(out1);
+
334  add(out2);
+
335  }
+
336 
+
338  MultiOutput(AudioStream &out1, AudioStream &out2) {
+
339  add(out1);
+
340  add(out2);
+
341  }
+
342 
+
345  MultiOutput(Print &out1, Print &out2) {
+
346  add(out1);
+
347  add(out2);
+
348  }
+
349 
+
350  virtual ~MultiOutput() {
+
351  for (int j = 0; j < vector.size(); j++) {
+
352  if (vector[j]->isDeletable()) {
+
353  delete vector[j];
+
354  }
+
355  }
+
356  }
+
357 
+
359  void add(AudioOutput &out) { vector.push_back(&out); }
+
360 
+
362  void add(AudioStream &stream) {
+
363  AdapterAudioStreamToAudioOutput *out =
+
364  new AdapterAudioStreamToAudioOutput(stream);
+
365  vector.push_back(out);
+
366  }
+
367 
+
368  void add(Print &print) {
+
369  AdapterPrintToAudioOutput *out = new AdapterPrintToAudioOutput(print);
+
370  vector.push_back(out);
+
371  }
+
372 
+
373  void flush() {
+
374  for (int j = 0; j < vector.size(); j++) {
+
375  vector[j]->flush();
+
376  }
+
377  }
+
378 
+
379  void setAudioInfo(AudioInfo info) {
+
380  for (int j = 0; j < vector.size(); j++) {
+
381  vector[j]->setAudioInfo(info);
+
382  }
+
383  }
+
384 
+
385  size_t write(const uint8_t *data, size_t len) {
+
386  for (int j = 0; j < vector.size(); j++) {
+
387  int open = len;
+
388  int start = 0;
+
389  while (open > 0) {
+
390  int written = vector[j]->write(data + start, open);
+
391  open -= written;
+
392  start += written;
+
393  }
+
394  }
+
395  return len;
+
396  }
+
397 
+
398  size_t write(uint8_t ch) {
+
399  for (int j = 0; j < vector.size(); j++) {
+
400  int open = 1;
+
401  while (open > 0) {
+
402  open -= vector[j]->write(ch);
+
403  }
+
404  }
+
405  return 1;
+
406  }
+
407 
+
408  protected:
+
409  Vector<AudioOutput *> vector;
+
411  void setOutput(Print &out) { add(out); }
+
412 };
+
413 
+
423 class TimedStream : public ModifyingStream {
+
424  public:
+
425  TimedStream() = default;
+
426 
+
427  TimedStream(AudioStream &io, long startSeconds = 0, long endSeconds = -1) {
+
428  p_stream = &io;
+
429  p_print = &io;
+
430  p_info = &io;
+
431  setStartSec(startSeconds);
+
432  setEndSec(endSeconds);
+
433  }
+
434 
+
435  TimedStream(AudioOutput &o, long startSeconds = 0, long endSeconds = -1) {
+
436  p_print = &o;
+
437  p_info = &o;
+
438  setStartSec(startSeconds);
+
439  setEndSec(endSeconds);
+
440  }
+
441 
+
444  void setStartSec(uint32_t startSeconds) {
+
445  start_ms = startSeconds * 1000;
+
446  calculateByteLimits();
+
447  }
+
448 
+
450  void setStartMs(uint32_t ms) {
+
451  start_ms = ms;
+
452  calculateByteLimits();
+
453  }
+
454 
+
457  void setEndSec(uint32_t endSeconds) {
+
458  end_ms = endSeconds * 1000;
+
459  calculateByteLimits();
+
460  }
+
461 
+
463  void setEndMs(uint32_t ms) {
+
464  end_ms = ms;
+
465  calculateByteLimits();
+
466  }
+
467 
+
469  bool isPlaying() {
+
470  if (current_bytes < start_bytes) return false;
+
471  if (end_bytes > 0 && current_bytes > end_bytes) return false;
+
472  return true;
+
473  }
+
474 
+
476  bool isActive() {
+
477  return (current_bytes < end_bytes && current_bytes >= start_bytes);
+
478  }
+
479 
+
480  bool begin(AudioInfo info) {
+
481  setAudioInfo(info);
+
482  return begin();
+
483  }
+
484 
+
485  bool begin() override {
+
486  calculateByteLimits();
+
487  current_bytes = 0;
+
488  LOGI("byte range %u - %u",(unsigned) start_bytes,(unsigned) end_bytes);
+
489  return true;
+
490  }
+
491 
+
492  operator bool() { return isActive(); }
+
493 
+
497  size_t readBytes(uint8_t *data, size_t len) override {
+
498  // if reading is not supported we stop
+
499  if (p_stream == nullptr) return 0;
+
500  // Positioin to start
+
501  if (start_bytes > current_bytes){
+
502  consumeBytes(start_bytes - current_bytes);
+
503  }
+
504  // if we are past the end we stop
+
505  if (!isActive()) return 0;
+
506  // read the data now
+
507  size_t result = 0;
+
508  do {
+
509  result = p_stream->readBytes(data, len);
+
510  current_bytes += len;
+
511  // ignore data before start time
+
512  } while (result > 0 && current_bytes < start_bytes);
+
513  return isPlaying() ? result : 0;
+
514  }
+
515 
+
517  size_t write(const uint8_t *data, size_t len) override {
+
518  if (current_bytes >= end_bytes) return 0;
+
519  current_bytes += len;
+
520  if (current_bytes < start_bytes) return len;
+
521  return p_print->write(data, len);
+
522  }
+
523 
+
525  int available() override {
+
526  if (p_stream == nullptr) return 0;
+
527  return current_bytes < end_bytes ? p_stream->available() : 0;
+
528  }
+
529 
+
531  void setAudioInfo(AudioInfo info) override {
+
532  AudioStream::setAudioInfo(info);
+
533  if (p_info) p_info->setAudioInfo(info);
+
534  calculateByteLimits();
+
535  }
+
536 
+
537  int availableForWrite() override {
+
538  return current_bytes < end_bytes ? p_print->availableForWrite() : 0;
+
539  }
+
540 
+
543  void setCompressionRatio(float ratio) { compression_ratio = ratio; }
+
544 
+
546  int bytesPerSecond() {
+
547  return info.sample_rate * info.channels * info.bits_per_sample / 8;
+
548  }
+
549 
+
550  void setOutput(Print &out) { p_print = &out; }
+
551 
+
552  void setStream(Stream &stream) {
+
553  p_print = &stream;
+
554  p_stream = &stream;
+
555  }
+
556 
+
557  void setOutput(AudioOutput &out) {
+
558  p_print = &out;
+
559  p_info = &out;
+
560  }
+
561 
+
562  void setStream(AudioOutput &out) {
+
563  p_print = &out;
+
564  p_info = &out;
+
565  }
+
566 
+
567  void setStream(AudioStream &stream) {
+
568  p_print = &stream;
+
569  p_stream = &stream;
+
570  p_info = &stream;
+
571  }
+
572 
+
573  size_t size() {
+
574  return end_bytes - start_bytes;
+
575  }
+
576 
+
577  protected:
+
578  Stream *p_stream = nullptr;
+
579  Print *p_print = nullptr;
+
580  AudioInfoSupport *p_info = nullptr;
+
581  uint32_t start_ms = 0;
+
582  uint32_t end_ms = UINT32_MAX;
+
583  uint32_t start_bytes = 0;
+
584  uint32_t end_bytes = UINT32_MAX;
+
585  uint32_t current_bytes = 0;
+
586  float compression_ratio = 1.0;
+
587 
+
588  void consumeBytes(uint32_t len){
+
589  int open = len;
+
590  uint8_t buffer[1024];
+
591  while (open > 0){
+
592  int toread = min(1024, open);
+
593  p_stream->readBytes(buffer, toread);
+
594  open -= toread;
+
595  }
+
596  current_bytes += len;
+
597  LOGD("consumed %u -> %u",(unsigned) len, (unsigned)current_bytes);
+
598  }
+
599 
+
600  void calculateByteLimits() {
+
601  float bytes_per_second = bytesPerSecond();
+
602  if (bytes_per_second > 0) {
+
603  start_bytes = bytes_per_second * start_ms / compression_ratio / 1000;
+
604  end_bytes = bytes_per_second * end_ms / compression_ratio / 1000;
+
605  } else {
+
606  LOGE("AudioInfo not defined");
+
607  }
+
608  }
+
609 };
+
610 
+
620 class ChannelsSelectOutput : public AudioOutput {
+
621  public:
+
622  ChannelsSelectOutput() = default;
+
623 
+
624  bool begin(AudioInfo info) {
+
625  setAudioInfo(info);
+
626  return begin();
+
627  }
+
628 
+
629  bool begin() {
+
630  AudioOutput::begin();
+
631  // make sure that selected channels are valid
+
632  for (auto &out : out_channels) {
+
633  for (auto &ch : out.channels) {
+
634  if (ch > cfg.channels - 1) {
+
635  LOGE("Channel '%d' not valid for max %d channels", ch, cfg.channels);
+
636  return false;
+
637  }
+
638  }
+
639  }
+
640  return true;
+
641  }
+
642 
+
645  void addOutput(AudioOutput &out, uint16_t channel) {
+
646  Vector<uint16_t> channels;
+
647  channels.push_back(channel);
+
648  ChannelSelectionOutputDef def;
+
649  def.channels = channels;
+
650  def.p_out = &out;
+
651  def.p_audio_info = &out;
+
652  out_channels.push_back(def);
+
653  }
+
654 
+
657  void addOutput(AudioStream &out, uint16_t channel) {
+
658  Vector<uint16_t> channels;
+
659  channels.push_back(channel);
+
660  ChannelSelectionOutputDef def;
+
661  def.channels = channels;
+
662  def.p_out = &out;
+
663  def.p_audio_info = &out;
+
664  out_channels.push_back(def);
+
665  }
+
666 
+
669  void addOutput(Print &out, uint16_t channel) {
+
670  Vector<uint16_t> channels;
+
671  channels.push_back(channel);
+
672  ChannelSelectionOutputDef def;
+
673  def.channels = channels;
+
674  def.p_out = &out;
+
675  out_channels.push_back(def);
+
676  }
+
677 
+
680  void addOutput(Print &out, uint16_t left, uint16_t right) {
+
681  Vector<uint16_t> channels;
+
682  channels.push_back(left);
+
683  channels.push_back(right);
+
684  ChannelSelectionOutputDef def;
+
685  def.channels = channels;
+
686  def.p_out = &out;
+
687  out_channels.push_back(def);
+
688  }
+
689 
+
692  void addOutput(AudioOutput &out, uint16_t left, uint16_t right) {
+
693  Vector<uint16_t> channels;
+
694  channels.push_back(left);
+
695  channels.push_back(right);
+
696  ChannelSelectionOutputDef def;
+
697  def.channels = channels;
+
698  def.p_out = &out;
+
699  def.p_audio_info = &out;
+
700  out_channels.push_back(def);
+
701  }
+
702 
+
705  void addOutput(AudioStream &out, uint16_t left, uint16_t right) {
+
706  Vector<uint16_t> channels;
+
707  channels.push_back(left);
+
708  channels.push_back(right);
+
709  ChannelSelectionOutputDef def;
+
710  def.channels = channels;
+
711  def.p_out = &out;
+
712  def.p_audio_info = &out;
+
713  out_channels.push_back(def);
+
714  }
+
715 
+
716  size_t write(const uint8_t *data, size_t len) override {
+
717  if (!is_active) return false;
+
718  LOGD("write %d", (int)len);
+
719  switch (cfg.bits_per_sample) {
+
720  case 16:
+
721  return writeT<int16_t>(data, len);
+
722  case 24:
+
723  return writeT<int24_t>(data, len);
+
724  case 32:
+
725  return writeT<int32_t>(data, len);
+
726  default:
+
727  return 0;
+
728  }
+
729  }
+
730 
+
731  void setAudioInfo(AudioInfo ai) override {
+
732  this->cfg = ai;
+
733  //notifyAudioChange(ai);
+
734  for (auto &info : out_channels) {
+
735  auto p_notify = info.p_audio_info;
+
736  if (p_notify != nullptr) {
+
737  AudioInfo result{ai};
+
738  result.channels = info.channels.size();
+
739  p_notify->setAudioInfo(result);
+
740  }
+
741  }
+
742  }
+
743 
+
744  protected:
+
745  struct ChannelSelectionOutputDef {
+
746  Print *p_out = nullptr;
+
747  AudioInfoSupport *p_audio_info = nullptr;
+
748  SingleBuffer<uint8_t> buffer{CHANNEL_SELECT_BUFFER_SIZE};
+
749  Vector<uint16_t> channels{0};
+
750  };
+
751  Vector<ChannelSelectionOutputDef> out_channels{0};
+
752 
+
753  template <typename T>
+
754  size_t writeT(const uint8_t *buffer, size_t size) {
+
755  if (!is_active) return 0;
+
756  int sample_count = size / sizeof(T);
+
757  //int result_size = sample_count / cfg.channels;
+
758  T *data = (T *)buffer;
+
759 
+
760  for (int i = 0; i < sample_count; i += cfg.channels) {
+
761  T *frame = data + i;
+
762  for (auto &out : out_channels) {
+
763  T out_frame[out.channels.size()] = {0};
+
764  int ch_out = 0;
+
765  for (auto &ch : out.channels) {
+
766  // make sure we have a valid channel
+
767  int channel = (ch < cfg.channels) ? ch : cfg.channels - 1;
+
768  out_frame[ch_out++] = frame[channel];
+
769  }
+
770  // write to buffer
+
771  size_t written = out.buffer.writeArray((const uint8_t *)&out_frame, sizeof(out_frame));
+
772  // write buffer to final output
+
773  if (out.buffer.availableForWrite()<sizeof(out_frame)){
+
774  out.p_out->write(out.buffer.data(), out.buffer.available());
+
775  out.buffer.reset();
+
776  }
+
777  // if (written != sizeof(out_frame)) {
+
778  // LOGW("Could not write all samples %d -> %d", sizeof(out_frame), written);
+
779  // }
+
780  }
+
781  }
+
782  return size;
+
783  }
+
784 
+
786  int getChannels(Print *out, int defaultChannels) {
+
787  for (auto &channels_select : out_channels) {
+
788  if (channels_select.p_out == out) return channels_select.channels.size();
+
789  }
+
790  return defaultChannels;
+
791  }
+
792 };
+
793 
+
794 } // namespace audio_tools
+
audio_tools::AdapterAudioOutputToAudioStream
Wrapper which converts a AudioStream to a AudioOutput.
Definition: AudioIO.h:284
+
audio_tools::AdapterAudioOutputToAudioStream::isDeletable
virtual bool isDeletable()
If true we need to release the related memory in the destructor.
Definition: AudioIO.h:305
+
audio_tools::AdapterAudioOutputToAudioStream::setAudioInfo
void setAudioInfo(AudioInfo info) override
Defines the input AudioInfo.
Definition: AudioIO.h:292
+
audio_tools::AdapterAudioOutputToAudioStream::audioInfo
AudioInfo audioInfo() override
provides the actual input AudioInfo
Definition: AudioIO.h:294
+
audio_tools::AdapterAudioStreamToAudioOutput
Wrapper which converts a AudioStream to a AudioOutput.
Definition: AudioIO.h:249
+
audio_tools::AdapterAudioStreamToAudioOutput::isDeletable
virtual bool isDeletable()
If true we need to release the related memory in the destructor.
Definition: AudioIO.h:272
+
audio_tools::AdapterAudioStreamToAudioOutput::setAudioInfo
void setAudioInfo(AudioInfo info) override
Defines the input AudioInfo.
Definition: AudioIO.h:257
+
audio_tools::AdapterAudioStreamToAudioOutput::audioInfo
AudioInfo audioInfo() override
provides the actual input AudioInfo
Definition: AudioIO.h:259
+
audio_tools::AdapterPrintToAudioOutput
Wrapper which converts a Print to a AudioOutput.
Definition: AudioIO.h:231
+
audio_tools::AdapterPrintToAudioOutput::isDeletable
virtual bool isDeletable()
If true we need to release the related memory in the destructor.
Definition: AudioIO.h:239
+
audio_tools::AdapterPrintToAudioOutput::setAudioInfo
void setAudioInfo(AudioInfo info)
Defines the input AudioInfo.
Definition: AudioIO.h:234
audio_tools::AudioInfoSource::addNotifyAudioChange
virtual void addNotifyAudioChange(AudioInfoSupport &bi)
Adds target to be notified about audio changes.
Definition: AudioTypes.h:162
audio_tools::AudioInfoSupport
Supports changes to the sampling rate, bits and channels.
Definition: AudioTypes.h:139
audio_tools::AudioInfoSupport::setAudioInfo
virtual void setAudioInfo(AudioInfo info)=0
Defines the input AudioInfo.
-
audio_tools::AudioOutputAdapter
Base class for Output Adpapters.
Definition: AudioIO.h:226
+
audio_tools::AudioOutputAdapter
Base class for Output Adpapters.
Definition: AudioIO.h:225
audio_tools::AudioOutput
Abstract Audio Ouptut class.
Definition: AudioOutput.h:22
audio_tools::AudioOutput::isDeletable
virtual bool isDeletable()
If true we need to release the related memory in the destructor.
Definition: AudioOutput.h:57
audio_tools::AudioStream
Base class for all Audio Streams. It support the boolean operator to test if the object is ready with...
Definition: BaseStream.h:109
audio_tools::AudioStream::setAudioInfo
virtual void setAudioInfo(AudioInfo newInfo) override
Defines the input AudioInfo.
Definition: BaseStream.h:117
-
audio_tools::ChannelsSelectOutput
Flexible functionality to extract one or more channels from a multichannel signal....
Definition: AudioIO.h:621
-
audio_tools::ChannelsSelectOutput::addOutput
void addOutput(Print &out, uint16_t left, uint16_t right)
Definition: AudioIO.h:681
-
audio_tools::ChannelsSelectOutput::setAudioInfo
void setAudioInfo(AudioInfo ai) override
Defines the input AudioInfo.
Definition: AudioIO.h:732
-
audio_tools::ChannelsSelectOutput::addOutput
void addOutput(Print &out, uint16_t channel)
Definition: AudioIO.h:670
-
audio_tools::ChannelsSelectOutput::addOutput
void addOutput(AudioOutput &out, uint16_t channel)
Definition: AudioIO.h:646
-
audio_tools::ChannelsSelectOutput::getChannels
int getChannels(Print *out, int defaultChannels)
Determine number of channels for destination.
Definition: AudioIO.h:787
-
audio_tools::ChannelsSelectOutput::addOutput
void addOutput(AudioStream &out, uint16_t channel)
Definition: AudioIO.h:658
-
audio_tools::ChannelsSelectOutput::addOutput
void addOutput(AudioStream &out, uint16_t left, uint16_t right)
Definition: AudioIO.h:706
-
audio_tools::ChannelsSelectOutput::addOutput
void addOutput(AudioOutput &out, uint16_t left, uint16_t right)
Definition: AudioIO.h:693
+
audio_tools::ChannelsSelectOutput
Flexible functionality to extract one or more channels from a multichannel signal....
Definition: AudioIO.h:620
+
audio_tools::ChannelsSelectOutput::addOutput
void addOutput(Print &out, uint16_t left, uint16_t right)
Definition: AudioIO.h:680
+
audio_tools::ChannelsSelectOutput::setAudioInfo
void setAudioInfo(AudioInfo ai) override
Defines the input AudioInfo.
Definition: AudioIO.h:731
+
audio_tools::ChannelsSelectOutput::addOutput
void addOutput(Print &out, uint16_t channel)
Definition: AudioIO.h:669
+
audio_tools::ChannelsSelectOutput::addOutput
void addOutput(AudioOutput &out, uint16_t channel)
Definition: AudioIO.h:645
+
audio_tools::ChannelsSelectOutput::getChannels
int getChannels(Print *out, int defaultChannels)
Determine number of channels for destination.
Definition: AudioIO.h:786
+
audio_tools::ChannelsSelectOutput::addOutput
void addOutput(AudioStream &out, uint16_t channel)
Definition: AudioIO.h:657
+
audio_tools::ChannelsSelectOutput::addOutput
void addOutput(AudioStream &out, uint16_t left, uint16_t right)
Definition: AudioIO.h:705
+
audio_tools::ChannelsSelectOutput::addOutput
void addOutput(AudioOutput &out, uint16_t left, uint16_t right)
Definition: AudioIO.h:692
audio_tools::ModifyingOutput
Abstract class: Objects can be put into a pipleline.
Definition: AudioOutput.h:97
audio_tools::ModifyingStream
Abstract class: Objects can be put into a pipleline.
Definition: AudioStreams.h:69
-
audio_tools::MultiOutput
Replicates the output to multiple destinations.
Definition: AudioIO.h:320
-
audio_tools::MultiOutput::add
void add(AudioOutput &out)
Add an additional AudioOutput output.
Definition: AudioIO.h:360
-
audio_tools::MultiOutput::setAudioInfo
void setAudioInfo(AudioInfo info)
Defines the input AudioInfo.
Definition: AudioIO.h:380
-
audio_tools::MultiOutput::add
void add(AudioStream &stream)
Add an AudioStream to the output.
Definition: AudioIO.h:363
-
audio_tools::MultiOutput::MultiOutput
MultiOutput(AudioStream &out1, AudioStream &out2)
Defines a MultiOutput with 2 final outputs.
Definition: AudioIO.h:339
-
audio_tools::MultiOutput::MultiOutput
MultiOutput(AudioOutput &out1, AudioOutput &out2)
Defines a MultiOutput with 2 final outputs.
Definition: AudioIO.h:333
-
audio_tools::MultiOutput::MultiOutput
MultiOutput(AudioOutput &out)
Defines a MultiOutput with a single final outputs,.
Definition: AudioIO.h:328
-
audio_tools::MultiOutput::setOutput
void setOutput(Print &out)
support for Pipleline
Definition: AudioIO.h:412
-
audio_tools::MultiOutput::MultiOutput
MultiOutput(Print &out1, Print &out2)
Definition: AudioIO.h:346
+
audio_tools::MultiOutput
Replicates the output to multiple destinations.
Definition: AudioIO.h:319
+
audio_tools::MultiOutput::add
void add(AudioOutput &out)
Add an additional AudioOutput output.
Definition: AudioIO.h:359
+
audio_tools::MultiOutput::setAudioInfo
void setAudioInfo(AudioInfo info)
Defines the input AudioInfo.
Definition: AudioIO.h:379
+
audio_tools::MultiOutput::add
void add(AudioStream &stream)
Add an AudioStream to the output.
Definition: AudioIO.h:362
+
audio_tools::MultiOutput::MultiOutput
MultiOutput(AudioStream &out1, AudioStream &out2)
Defines a MultiOutput with 2 final outputs.
Definition: AudioIO.h:338
+
audio_tools::MultiOutput::MultiOutput
MultiOutput(AudioOutput &out1, AudioOutput &out2)
Defines a MultiOutput with 2 final outputs.
Definition: AudioIO.h:332
+
audio_tools::MultiOutput::MultiOutput
MultiOutput(AudioOutput &out)
Defines a MultiOutput with a single final outputs,.
Definition: AudioIO.h:327
+
audio_tools::MultiOutput::setOutput
void setOutput(Print &out)
support for Pipleline
Definition: AudioIO.h:411
+
audio_tools::MultiOutput::MultiOutput
MultiOutput(Print &out1, Print &out2)
Definition: AudioIO.h:345
audio_tools::MultiOutput::MultiOutput
MultiOutput()=default
Defines a MultiOutput with no final output: Define your outputs with add()
audio_tools::Print
Definition: NoArduino.h:58
audio_tools::QueueStream::begin
virtual bool begin()
Activates the output.
Definition: BaseStream.h:318
-
audio_tools::ReformatBaseStream
Base class for chained converting streams.
Definition: AudioIO.h:155
-
audio_tools::ReformatBaseStream::setStream
virtual void setStream(Stream &stream) override
Defines/Changes the input & output.
Definition: AudioIO.h:157
-
audio_tools::ReformatBaseStream::setOutput
virtual void setOutput(Print &print) override
Defines/Changes the output target.
Definition: AudioIO.h:177
-
audio_tools::ReformatBaseStream::transformationReader
virtual TransformationReader< ReformatBaseStream > & transformationReader()
Provides access to the TransformationReader.
Definition: AudioIO.h:208
+
audio_tools::ReformatBaseStream
Base class for chained converting streams.
Definition: AudioIO.h:154
+
audio_tools::ReformatBaseStream::setStream
virtual void setStream(Stream &stream) override
Defines/Changes the input & output.
Definition: AudioIO.h:156
+
audio_tools::ReformatBaseStream::setOutput
virtual void setOutput(Print &print) override
Defines/Changes the output target.
Definition: AudioIO.h:176
+
audio_tools::ReformatBaseStream::transformationReader
virtual TransformationReader< ReformatBaseStream > & transformationReader()
Provides access to the TransformationReader.
Definition: AudioIO.h:207
audio_tools::RingBuffer< uint8_t >
audio_tools::RingBuffer::size
virtual size_t size()
Returns the maximum capacity of the buffer.
Definition: Buffers.h:383
audio_tools::SingleBuffer< uint8_t >
audio_tools::Stream
Definition: NoArduino.h:125
-
audio_tools::TimedStream
AudioStream class that can define a start and (an optional) stop time Usually it is used to wrap an A...
Definition: AudioIO.h:424
-
audio_tools::TimedStream::setEndSec
void setEndSec(uint32_t endSeconds)
Definition: AudioIO.h:458
-
audio_tools::TimedStream::setEndMs
void setEndMs(uint32_t ms)
Defines the (optional) end time in milliseconds.
Definition: AudioIO.h:464
-
audio_tools::TimedStream::setCompressionRatio
void setCompressionRatio(float ratio)
Definition: AudioIO.h:544
-
audio_tools::TimedStream::readBytes
size_t readBytes(uint8_t *data, size_t len) override
Definition: AudioIO.h:498
-
audio_tools::TimedStream::setStream
void setStream(Stream &stream)
Defines/Changes the input & output.
Definition: AudioIO.h:553
-
audio_tools::TimedStream::setStartSec
void setStartSec(uint32_t startSeconds)
Definition: AudioIO.h:445
-
audio_tools::TimedStream::available
int available() override
Provides the available bytes until the end time has reached.
Definition: AudioIO.h:526
-
audio_tools::TimedStream::write
size_t write(const uint8_t *data, size_t len) override
Plays only data for the indiated start and end time.
Definition: AudioIO.h:518
-
audio_tools::TimedStream::setStartMs
void setStartMs(uint32_t ms)
Defines the start time in milliseconds.
Definition: AudioIO.h:451
-
audio_tools::TimedStream::isPlaying
bool isPlaying()
Returns true if we are in a valid time range and are still playing sound.
Definition: AudioIO.h:470
-
audio_tools::TimedStream::isActive
bool isActive()
Returns true if we are not past the end time;.
Definition: AudioIO.h:477
-
audio_tools::TimedStream::setAudioInfo
void setAudioInfo(AudioInfo info) override
Updates the AudioInfo in the current object and in the source or target.
Definition: AudioIO.h:532
-
audio_tools::TimedStream::setOutput
void setOutput(Print &out)
Defines/Changes the output target.
Definition: AudioIO.h:551
-
audio_tools::TimedStream::bytesPerSecond
int bytesPerSecond()
Calculates the bytes per second from the AudioInfo.
Definition: AudioIO.h:547
+
audio_tools::TimedStream
AudioStream class that can define a start and (an optional) stop time Usually it is used to wrap an A...
Definition: AudioIO.h:423
+
audio_tools::TimedStream::setEndSec
void setEndSec(uint32_t endSeconds)
Definition: AudioIO.h:457
+
audio_tools::TimedStream::setEndMs
void setEndMs(uint32_t ms)
Defines the (optional) end time in milliseconds.
Definition: AudioIO.h:463
+
audio_tools::TimedStream::setCompressionRatio
void setCompressionRatio(float ratio)
Definition: AudioIO.h:543
+
audio_tools::TimedStream::readBytes
size_t readBytes(uint8_t *data, size_t len) override
Definition: AudioIO.h:497
+
audio_tools::TimedStream::setStream
void setStream(Stream &stream)
Defines/Changes the input & output.
Definition: AudioIO.h:552
+
audio_tools::TimedStream::setStartSec
void setStartSec(uint32_t startSeconds)
Definition: AudioIO.h:444
+
audio_tools::TimedStream::available
int available() override
Provides the available bytes until the end time has reached.
Definition: AudioIO.h:525
+
audio_tools::TimedStream::write
size_t write(const uint8_t *data, size_t len) override
Plays only data for the indiated start and end time.
Definition: AudioIO.h:517
+
audio_tools::TimedStream::setStartMs
void setStartMs(uint32_t ms)
Defines the start time in milliseconds.
Definition: AudioIO.h:450
+
audio_tools::TimedStream::isPlaying
bool isPlaying()
Returns true if we are in a valid time range and are still playing sound.
Definition: AudioIO.h:469
+
audio_tools::TimedStream::isActive
bool isActive()
Returns true if we are not past the end time;.
Definition: AudioIO.h:476
+
audio_tools::TimedStream::setAudioInfo
void setAudioInfo(AudioInfo info) override
Updates the AudioInfo in the current object and in the source or target.
Definition: AudioIO.h:531
+
audio_tools::TimedStream::setOutput
void setOutput(Print &out)
Defines/Changes the output target.
Definition: AudioIO.h:550
+
audio_tools::TimedStream::bytesPerSecond
int bytesPerSecond()
Calculates the bytes per second from the AudioInfo.
Definition: AudioIO.h:546
audio_tools::TransformationReader
ConverterStream Helper class which implements the readBytes with the help of write.
Definition: AudioIO.h:23
audio_tools::TransformationReader::begin
void begin(T *transform, Stream *source)
setup of the TransformationReader class
Definition: AudioIO.h:29
audio_tools::TransformationReader::resizeReadBuffer
void resizeReadBuffer(int size)
Defines the read buffer size for individual reads.
Definition: AudioIO.h:45
-
audio_tools::TransformationReader::restoreOutput
void restoreOutput(Print *out)
restores the original output in the converter class
Definition: AudioIO.h:144
-
audio_tools::TransformationReader::setupOutput
Print * setupOutput()
Definition: AudioIO.h:136
+
audio_tools::TransformationReader::restoreOutput
void restoreOutput(Print *out)
restores the original output in the converter class
Definition: AudioIO.h:143
+
audio_tools::TransformationReader::setupOutput
Print * setupOutput()
Definition: AudioIO.h:135
audio_tools::TransformationReader::resizeResultQueue
void resizeResultQueue(int size)
Defines the queue size for result.
Definition: AudioIO.h:49
audio_tools::TransformationReader::setResultQueueFactor
void setResultQueueFactor(int factor)
Defines the queue size dependent on the read size.
Definition: AudioIO.h:121
audio_tools::Vector< uint16_t >
@@ -834,7 +833,7 @@
audio_tools::AudioInfo::sample_rate
sample_rate_t sample_rate
Sample Rate: e.g 44100.
Definition: AudioTypes.h:55
audio_tools::AudioInfo::channels
uint16_t channels
Number of channels: 2=stereo, 1=mono.
Definition: AudioTypes.h:57
audio_tools::AudioInfo::bits_per_sample
uint8_t bits_per_sample
Number of bits per sample (int16_t = 16 bits)
Definition: AudioTypes.h:59
-
audio_tools::ChannelsSelectOutput::ChannelSelectionOutputDef
Definition: AudioIO.h:746
+
audio_tools::ChannelsSelectOutput::ChannelSelectionOutputDef
Definition: AudioIO.h:745