arduino-audio-tools
CodecBasic.h
1 #pragma once
2 
3 #include "AudioTools/AudioCodecs/AudioCodecsBase.h"
4 #include "AudioTools/AudioCodecs/CodecG7xx.h"
5 
6 namespace audio_tools {
7 
18 class DecoderBasic : public AudioDecoder {
19 public:
24  DecoderBasic() { TRACED(); }
25 
31  DecoderBasic(Print &out_stream, bool active = true) {
32  TRACED();
33  setOutput(out_stream);
34  }
35 
43  DecoderBasic(Print &out_stream, AudioInfoSupport &bi) {
44  TRACED();
45  setOutput(out_stream);
47  }
48 
50  void setOutput(Print &out_stream) override {
51  decoder.setOutput(out_stream);
52  }
53 
55  decoder.addNotifyAudioChange(bi);
56  }
57 
58  AudioInfo audioInfo() override { return decoder.audioInfo(); }
59 
60  bool begin(AudioInfo info) {
61  decoder.setAudioInfo(info);
62  return decoder.begin();
63  }
64 
65  bool begin() override {
66  TRACED();
67  return decoder.begin();
68  }
69 
70  void end() override { decoder.end(); }
71 
72  virtual size_t write(const uint8_t *data, size_t len) override {
73  return decoder.write((uint8_t *)data, len);
74  }
75 
76  virtual operator bool() override { return decoder; }
77 
78 protected:
79  G711_ULAWDecoder decoder;
80 };
81 
92 class EncoderBasic : public AudioEncoder {
93 public:
94  // Empty Constructor - the output stream must be provided with begin()
95  EncoderBasic() {}
96 
97  // Constructor providing the output stream
98  EncoderBasic(Print &out) { setOutput(out); }
99 
101  void setOutput(Print &out) override { encoder.setOutput(out); }
102 
104  const char *mime() override { return "audio/basic"; }
105 
107  virtual void setAudioInfo(AudioInfo from) override {
109  encoder.setAudioInfo(from);
110  }
111 
113  bool begin() override { return encoder.begin(); }
114 
116  void end() override { encoder.end(); }
117 
119  virtual size_t write(const uint8_t *in_ptr, size_t in_size) override {
120  return encoder.write((uint8_t *)in_ptr, in_size);
121  }
122 
123  operator bool() override {
124  return encoder;
125  }
126 
127  bool isOpen() { return encoder; }
128 
129 protected:
130  G711_ULAWEncoder encoder;
131 };
132 
133 } // namespace audio_tools
Docoding of encoded audio into PCM data.
Definition: AudioCodecsBase.h:16
virtual AudioInfo audioInfo()
provides the actual input AudioInfo
Definition: AudioCodecsBase.h:23
Encoding of PCM data.
Definition: AudioCodecsBase.h:84
void setAudioInfo(AudioInfo from) override
Defines the sample rate, number of channels and bits per sample.
Definition: AudioCodecsBase.h:93
virtual void addNotifyAudioChange(AudioInfoSupport &bi)
Adds target to be notified about audio changes.
Definition: AudioTypes.h:162
Supports changes to the sampling rate, bits and channels.
Definition: AudioTypes.h:139
DecoderBasic - supports mime type audio/basic Requires https://github.com/pschatzmann/arduino-libg7xx...
Definition: CodecBasic.h:18
void setOutput(Print &out_stream) override
Defines the output Stream.
Definition: CodecBasic.h:50
DecoderBasic()
Construct a new DecoderBasic object.
Definition: CodecBasic.h:24
void addNotifyAudioChange(AudioInfoSupport &bi) override
Adds target to be notified about audio changes.
Definition: CodecBasic.h:54
DecoderBasic(Print &out_stream, bool active=true)
Construct a new DecoderBasic object.
Definition: CodecBasic.h:31
AudioInfo audioInfo() override
provides the actual input AudioInfo
Definition: CodecBasic.h:58
DecoderBasic(Print &out_stream, AudioInfoSupport &bi)
Construct a new DecoderBasic object.
Definition: CodecBasic.h:43
EncoderBasic - supports mime type audio/basic. The content of the "audio/basic" subtype is single cha...
Definition: CodecBasic.h:92
void setOutput(Print &out) override
Defines the output Stream.
Definition: CodecBasic.h:101
virtual size_t write(const uint8_t *in_ptr, size_t in_size) override
Writes PCM data to be encoded as RAW.
Definition: CodecBasic.h:119
const char * mime() override
Provides "audio/pcm".
Definition: CodecBasic.h:104
void end() override
stops the processing
Definition: CodecBasic.h:116
bool begin() override
starts the processing using the actual RAWAudioInfo
Definition: CodecBasic.h:113
virtual void setAudioInfo(AudioInfo from) override
We actually do nothing with this.
Definition: CodecBasic.h:107
void setOutput(Print &out_stream) override
Defines where the decoded result is written to.
Definition: CodecG7xx.h:85
void setAudioInfo(AudioInfo info) override
for most decoders this is not needed
Definition: CodecG7xx.h:52
virtual void setAudioInfo(AudioInfo info)
Defines the sample rate, number of channels and bits per sample.
Definition: CodecG7xx.h:174
Definition: NoArduino.h:58
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition: AudioConfig.h:868
Basic Audio information which drives e.g. I2S.
Definition: AudioTypes.h:52