arduino-audio-tools
CodecCopy.h
1 #pragma once
2 
3 #include "AudioTools/AudioCodecs/AudioCodecsBase.h"
4 #if defined(ARDUINO) && !defined(IS_MIN_DESKTOP)
5 #include "Print.h"
6 #endif
7 
8 namespace audio_tools {
9 
18 class CopyDecoder : public AudioDecoder {
19 public:
20 
21  CopyDecoder(bool isPcm = false){
22  is_pcm = isPcm;
23  }
24 
25  CopyDecoder(Print &out_stream) { TRACED(); pt_print=&out_stream; }
26 
27  CopyDecoder(Print &out_stream, AudioInfoSupport &bi) {pt_print=&out_stream;}
28 
29  ~CopyDecoder() {}
30 
31  virtual void setOutput(Print &out_stream) {pt_print=&out_stream;}
32 
33  bool begin() { return true; }
34 
35  void end() {}
36 
37  size_t write(const uint8_t *data, size_t len) {
38  TRACED();
39  return pt_print->write((uint8_t*)data,len);
40  }
41 
42  operator bool() { return true; }
43 
45  virtual bool isResultPCM() { return is_pcm;}
46 
48  void setResultPCM(bool pcm){ is_pcm = pcm;}
49 
50 protected:
51  Print *pt_print=nullptr;
52  bool is_pcm = false;
53 };
54 
62 class CopyEncoder : public AudioEncoder {
63 public:
64  CopyEncoder() { TRACED(); }
65 
66  CopyEncoder(Print &out_stream) { TRACED(); pt_print=&out_stream; }
67 
68  CopyEncoder(Print &out_stream, AudioInfoSupport &bi) {pt_print=&out_stream;}
69 
70  ~CopyEncoder() {}
71 
72  virtual void setOutput(Print &out_stream) {pt_print=&out_stream;}
73 
74  bool begin() { return true;}
75 
76  void end() {}
77 
78  size_t write(const uint8_t *data, size_t len) { return pt_print->write((uint8_t*)data,len); }
79 
80  operator bool() { return true; }
81 
82  const char *mime() {return "audio/pcm";}
83 
84 
85 protected:
86  Print *pt_print=nullptr;
87 };
88 
89 using PCMEncoder = CopyEncoder;
90 using PCMDecoder = CopyDecoder;
91 
92 } // namespace audio_tools
93 
Docoding of encoded audio into PCM data.
Definition: AudioCodecsBase.h:16
Encoding of PCM data.
Definition: AudioCodecsBase.h:84
Supports changes to the sampling rate, bits and channels.
Definition: AudioTypes.h:139
Dummy Decoder which just copies the provided data to the output. You can define if it is PCM data.
Definition: CodecCopy.h:18
virtual bool isResultPCM()
The result is encoded data - by default this is false.
Definition: CodecCopy.h:45
virtual void setOutput(Print &out_stream)
Defines where the decoded result is written to.
Definition: CodecCopy.h:31
void setResultPCM(bool pcm)
Defines that the source and therefor the result is also PCM data.
Definition: CodecCopy.h:48
Dummy Encoder which just copies the provided data to the output.
Definition: CodecCopy.h:62
const char * mime()
Provides the mime type of the encoded result.
Definition: CodecCopy.h:82
Definition: NoArduino.h:58
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition: AudioConfig.h:868