arduino-audio-tools
CodecCopy.h
1 #pragma once
2 
3 #include "AudioCodecs/AudioEncoded.h"
4 #if defined(ARDUINO) && !defined(IS_MIN_DESKTOP)
5 #include "Print.h"
6 #endif
7 
8 namespace audio_tools {
9 
17 class CopyDecoder : public AudioDecoder {
18 public:
19  CopyDecoder() { TRACED(); }
20 
21  CopyDecoder(bool isPcm){
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 void *data, size_t len) {
38  TRACED();
39  return pt_print->write((uint8_t*)data,len);
40  }
41 
42  operator bool() { return true; }
43 
44  // The result is encoded data
45  virtual bool isResultPCM() { return is_pcm;}
46 
47 protected:
48  Print *pt_print=nullptr;
49  bool is_pcm = false;
50 };
51 
59 class CopyEncoder : public AudioEncoder {
60 public:
61  CopyEncoder() { TRACED(); }
62 
63  CopyEncoder(Print &out_stream) { TRACED(); pt_print=&out_stream; }
64 
65  CopyEncoder(Print &out_stream, AudioInfoSupport &bi) {pt_print=&out_stream;}
66 
67  ~CopyEncoder() {}
68 
69  virtual void setOutput(Print &out_stream) {pt_print=&out_stream;}
70 
71  bool begin() { return true;}
72 
73  void end() {}
74 
75  size_t write(const void *data, size_t len) { return pt_print->write((uint8_t*)data,len); }
76 
77  operator bool() { return true; }
78 
79  const char *mime() {return "audio/pcm";}
80 
81 
82 protected:
83  Print *pt_print=nullptr;
84 };
85 
86 using PCMEncoder = CopyEncoder;
87 using PCMDecoder = CopyDecoder;
88 
89 } // namespace audio_tools
90 
Docoding of encoded audio into PCM data.
Definition: AudioEncoded.h:18
Encoding of PCM data.
Definition: AudioEncoded.h:88
Supports changes to the sampling rate, bits and channels.
Definition: AudioTypes.h:136
Dummy Decoder which just copies the provided data to the output.
Definition: CodecCopy.h:17
virtual bool isResultPCM()
If true, the decoding result is PCM data.
Definition: CodecCopy.h:45
virtual void setOutput(Print &out_stream)
Defines where the decoded result is written to.
Definition: CodecCopy.h:31
Dummy Encoder which just copies the provided data to the output.
Definition: CodecCopy.h:59
const char * mime()
Provides the mime type of the encoded result.
Definition: CodecCopy.h:79
Definition: NoArduino.h:58
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition: AnalogAudio.h:10