arduino-audio-tools
Loading...
Searching...
No Matches
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 if (pt_print == nullptr) {
40 LOGE("No output stream defined for CopyDecoder");
41 return 0;
42 }
43 return pt_print->write((uint8_t*)data,len);
44 }
45
46 operator bool() { return true; }
47
49 virtual bool isResultPCM() { return is_pcm;}
50
52 void setResultPCM(bool pcm){ is_pcm = pcm;}
53
54protected:
55 Print *pt_print=nullptr;
56 bool is_pcm = false;
57};
58
66class CopyEncoder : public AudioEncoder {
67public:
68 CopyEncoder() { TRACED(); }
69
70 CopyEncoder(Print &out_stream) { TRACED(); pt_print=&out_stream; }
71
72 CopyEncoder(Print &out_stream, AudioInfoSupport &bi) {pt_print=&out_stream;}
73
74 ~CopyEncoder() {}
75
76 virtual void setOutput(Print &out_stream) {pt_print=&out_stream;}
77
78 bool begin() { return true;}
79
80 void end() {}
81
82 size_t write(const uint8_t *data, size_t len) { return pt_print->write((uint8_t*)data,len); }
83
84 operator bool() { return true; }
85
87 const char *mime() {return mime_type;}
88
90 void setMime(const char *mime) { mime_type = mime; }
91
92
93protected:
94 Print *pt_print=nullptr;
95 const char *mime_type = "audio/pcm";
96};
97
98using PCMEncoder = CopyEncoder;
99using PCMDecoder = CopyDecoder;
100
101} // namespace audio_tools
102
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:49
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:52
Dummy Encoder which just copies the provided data to the output.
Definition CodecCopy.h:66
const char * mime()
Provides the mime type of the encoded data.
Definition CodecCopy.h:87
void setMime(const char *mime)
Defines the mime type.
Definition CodecCopy.h:90
Definition NoArduino.h:62
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition AudioCodecsBase.h:10