arduino-audio-tools
All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Modules Pages
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
8namespace audio_tools {
9
18class CopyDecoder : public AudioDecoder {
19public:
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
50protected:
51 Print *pt_print=nullptr;
52 bool is_pcm = false;
53};
54
62class CopyEncoder : public AudioEncoder {
63public:
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
83 const char *mime() {return mime_type;}
84
86 void setMime(const char *mime) { mime_type = mime; }
87
88
89protected:
90 Print *pt_print=nullptr;
91 const char *mime_type = "audio/pcm";
92};
93
94using PCMEncoder = CopyEncoder;
95using PCMDecoder = CopyDecoder;
96
97} // namespace audio_tools
98
Decoding of encoded audio into PCM data.
Definition AudioCodecsBase.h:18
Encoding of PCM data.
Definition AudioCodecsBase.h:96
Supports changes to the sampling rate, bits and channels.
Definition AudioTypes.h:133
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 data.
Definition CodecCopy.h:83
void setMime(const char *mime)
Defines the mime type.
Definition CodecCopy.h:86
Definition NoArduino.h:62
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition AudioCodecsBase.h:10