arduino-audio-tools
Loading...
Searching...
No Matches
CodecCopy.h
Go to the documentation of this file.
1#pragma once
3
4namespace audio_tools {
5
6class CodecCopy {
7 public:
8 CodecCopy(AudioWriter& to, Stream& from, int len = 1024)
9 : p_out(&to), p_in(&from), buffer_len(len) {}
10
11 size_t copy() {
12 uint8_t buffer[buffer_len];
13 size_t result = p_in->readBytes(buffer, buffer_len);
14 return p_out->write(buffer, result);
15 }
16
17 size_t copy(int len) {
18 uint8_t buffer[buffer_len];
19 size_t total = 0;
20 while ((int)total < len) {
21 size_t chunk = min((size_t)(len - total), (size_t)buffer_len);
22 size_t read = p_in->readBytes(buffer, chunk);
23 if (read == 0) break;
24 total += p_out->write(buffer, read);
25 }
26 return total;
27 }
28
29 protected:
30 AudioWriter* p_out = nullptr;
31 Stream* p_in = nullptr;
32 int buffer_len = 1024;
33};
34
35} // namespace audio_tools
Definition Arduino.h:136
virtual size_t readBytes(uint8_t *data, size_t len)
Definition Arduino.h:140
E.g. used by Encoders and Decoders.
Definition AudioTypes.h:205
virtual size_t write(const uint8_t *data, size_t len)=0
Definition CodecCopy.h:6
CodecCopy(AudioWriter &to, Stream &from, int len=1024)
Definition CodecCopy.h:8
Stream * p_in
Definition CodecCopy.h:31
int buffer_len
Definition CodecCopy.h:32
AudioWriter * p_out
Definition CodecCopy.h:30
size_t copy()
Definition CodecCopy.h:11
size_t copy(int len)
Definition CodecCopy.h:17
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition LMSEchoCancellationStream.h:6