arduino-audio-tools
Loading...
Searching...
No Matches
CodecCopy.h
Go to the documentation of this file.
1#pragma once
2
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
30
32 const char *mime() override {return mime_type;}
33
35 void setMime(const char *mime) { mime_type = mime; }
36
37 virtual void setOutput(Print &out_stream) {pt_print=&out_stream;}
38
39 bool begin() { return true; }
40
41 void end() {}
42
43 size_t write(const uint8_t *data, size_t len) {
44 TRACED();
45 if (pt_print == nullptr) {
46 LOGE("No output stream defined for CopyDecoder");
47 return 0;
48 }
49 return pt_print->write((uint8_t*)data,len);
50 }
51
52 operator bool() { return true; }
53
55 virtual bool isResultPCM() { return is_pcm;}
56
58 void setResultPCM(bool pcm){ is_pcm = pcm;}
59
60protected:
61 Print *pt_print=nullptr;
62 bool is_pcm = false;
63 const char *mime_type = "audio/pcm";
64};
65
73class CopyEncoder : public AudioEncoder {
74public:
76
77 CopyEncoder(Print &out_stream) { TRACED(); pt_print=&out_stream; }
78
79 CopyEncoder(Print &out_stream, AudioInfoSupport &bi) {pt_print=&out_stream;}
80
82
83 virtual void setOutput(Print &out_stream) {pt_print=&out_stream;}
84
85 bool begin() { return true;}
86
87 void end() {}
88
89 size_t write(const uint8_t *data, size_t len) {
90 if (pt_print == nullptr) {
91 LOGE("No output stream defined for CopyDecoder");
92 return 0;
93 }
94 return pt_print->write((uint8_t*)data,len);
95 }
96
97 operator bool() { return true; }
98
100 const char *mime() {return mime_type;}
101
103 void setMime(const char *mime) { mime_type = mime; }
104
105
106protected:
107 Print *pt_print=nullptr;
108 const char *mime_type = "audio/pcm";
109};
110
114
118
119} // namespace audio_tools
120
#define TRACED()
Definition AudioLoggerIDF.h:31
#define LOGE(...)
Definition AudioLoggerIDF.h:30
Definition Arduino.h:56
virtual size_t write(const uint8_t *data, size_t len)
Definition Arduino.h:120
Decoding of encoded audio into PCM data.
Definition AudioCodecsBase.h:19
Encoding of PCM data.
Definition AudioCodecsBase.h:101
Supports changes to the sampling rate, bits and channels.
Definition AudioTypes.h:132
Dummy Decoder which just copies the provided data to the output. You can define if it is PCM data.
Definition CodecCopy.h:18
CopyDecoder(Print &out_stream)
Definition CodecCopy.h:25
const char * mime_type
Definition CodecCopy.h:63
virtual bool isResultPCM()
The result is encoded data - by default this is false.
Definition CodecCopy.h:55
virtual void setOutput(Print &out_stream)
Defines where the decoded result is written to.
Definition CodecCopy.h:37
void setResultPCM(bool pcm)
Defines that the source and therefor the result is also PCM data.
Definition CodecCopy.h:58
~CopyDecoder()
Definition CodecCopy.h:29
bool begin()
Definition CodecCopy.h:39
CopyDecoder(Print &out_stream, AudioInfoSupport &bi)
Definition CodecCopy.h:27
bool is_pcm
Definition CodecCopy.h:62
void setMime(const char *mime)
Defines the mime type.
Definition CodecCopy.h:35
CopyDecoder(bool isPcm=false)
Definition CodecCopy.h:21
void end()
Definition CodecCopy.h:41
const char * mime() override
Provides the mime type of the data.
Definition CodecCopy.h:32
Print * pt_print
Definition CodecCopy.h:61
size_t write(const uint8_t *data, size_t len)
Definition CodecCopy.h:43
Dummy Encoder which just copies the provided data to the output.
Definition CodecCopy.h:73
const char * mime_type
Definition CodecCopy.h:108
CopyEncoder()
Definition CodecCopy.h:75
~CopyEncoder()
Definition CodecCopy.h:81
virtual void setOutput(Print &out_stream)
Default output assignment (encoders may override to store Print reference)
Definition CodecCopy.h:83
bool begin()
Definition CodecCopy.h:85
const char * mime()
Provides the mime type of the encoded data.
Definition CodecCopy.h:100
void setMime(const char *mime)
Defines the mime type.
Definition CodecCopy.h:103
CopyEncoder(Print &out_stream)
Definition CodecCopy.h:77
void end()
Definition CodecCopy.h:87
Print * pt_print
Definition CodecCopy.h:107
CopyEncoder(Print &out_stream, AudioInfoSupport &bi)
Definition CodecCopy.h:79
size_t write(const uint8_t *data, size_t len)
Definition CodecCopy.h:89
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition LMSEchoCancellationStream.h:6