arduino-audio-tools
All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Modules Pages
CodecFactory.h
1#pragma once
2
3#include "AudioTools/AudioCodecs/AudioCodecsBase.h"
4
5namespace audio_tools {
13 public:
14 bool addDecoder(const char* id, AudioDecoder* (*cb)()) {
15 if (id == nullptr || cb == nullptr) return false;
17 line.id = id;
18 line.cb = cb;
19 decoders.push_back(line);
20 return true;
21 }
22
23 bool addEncoder(const char* id, AudioEncoder* (*cb)()) {
24 if (id == nullptr || cb == nullptr) return false;
26 line.id = id;
27 line.cb = cb;
28 encoders.push_back(line);
29 return true;
30 }
31
33 AudioDecoder* createDecoder(const char* str) {
34 for (auto& line : decoders) {
35 if (line.id.equals(str)) {
36 return line.cb();
37 }
38 }
39 return nullptr;
40 }
42 AudioEncoder* createEncoder(const char* str) {
43 for (auto& line : encoders) {
44 if (line.id.equals(str)) {
45 return line.cb();
46 }
47 }
48 return nullptr;
49 }
50
51 protected:
53 Str id;
54 AudioDecoder* (*cb)() = nullptr;
55 };
57 Str id;
58 AudioEncoder* (*cb)() = nullptr;
59 };
62};
63
64} // namespace audio_tools
Decoding of encoded audio into PCM data.
Definition AudioCodecsBase.h:18
Encoding of PCM data.
Definition AudioCodecsBase.h:96
Factory for creating new decoders based on the mime type or id.
Definition CodecFactory.h:12
AudioEncoder * createEncoder(const char *str)
create a new encoder instance
Definition CodecFactory.h:42
AudioDecoder * createDecoder(const char *str)
create a new decoder instance
Definition CodecFactory.h:33
Str which keeps the data on the heap. We grow the allocated memory only if the copy source is not fit...
Definition Str.h:24
Vector implementation which provides the most important methods as defined by std::vector....
Definition Vector.h:21
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition AudioCodecsBase.h:10