arduino-audio-tools
Loading...
Searching...
No Matches
CodecWAV.h
Go to the documentation of this file.
1#pragma once
2
7
8#define READ_BUFFER_SIZE 512
9#define MAX_WAV_HEADER_LEN 200
10
11namespace audio_tools {
12
36
37static const char *wav_mime = "audio/wav";
38
65class WAVHeader {
66 public:
67 WAVHeader() = default;
68
71 int write(uint8_t *data, size_t data_len) {
72 return buffer.writeArray(data, data_len);
73 }
74
76 bool parse() {
77 LOGI("WAVHeader::begin: %u", (unsigned)buffer.available());
78 this->data_pos = 0l;
79 memset((void *)&headerInfo, 0, sizeof(WAVAudioInfo));
80
81 if (!setPos("RIFF")) return false;
82 // RIFF stores chunk_size (= file_size - 8): normalize to full file size
84 if (!setPos("WAVE")) return false;
85 if (!setPos("fmt ")) return false;
86 int fmt_length = read_int32();
93 if (!setPos("data")) return false;
95 if (headerInfo.data_length == 0 || headerInfo.data_length >= 0x7fff0000) {
98 }
99
100 logInfo();
101 buffer.clear();
102 return true;
103 }
104
107 int pos = getDataPos();
108 return pos > 0 && buffer.available() >= pos;
109 }
110
112 size_t available() { return buffer.available(); }
113
116 int pos =
118 .indexOf("data");
119 return pos > 0 ? pos + 8 : 0;
120 }
121
124
126 void setAudioInfo(WAVAudioInfo info) { headerInfo = info; }
127
129 bool writeHeader(Print *out) {
130 return writeHeader(out, headerInfo);
131 }
132
134 bool writeHeader(Print *out, const WAVAudioInfo &info) {
135 writeRiffHeader(buffer, info);
136 writeFMT(buffer, info);
137 writeDataHeader(buffer, info);
138 int len = buffer.available();
139 int written = out->write(buffer.data(), len);
140 if (written != len) {
141 LOGE("Failed to write WAV header to output: written %d of %d bytes", written, len);
142 }
143 return written == len;
144 }
145
147 void clear() {
148 data_pos = 0;
149 WAVAudioInfo empty;
150 empty.sample_rate = 0;
151 empty.channels = 0;
152 empty.bits_per_sample = 0;
153 headerInfo = empty;
155 buffer.reset();
156 }
157
159 void dumpHeader() {
160 char msg[buffer.available() + 1];
161 memset(msg, 0, buffer.available() + 1);
162 for (int j = 0; j < buffer.available(); j++) {
163 char c = (char)buffer.data()[j];
164 if (!isalpha(c)) {
165 c = '.';
166 }
167 msg[j] = c;
168 }
169 LOGI("Header: %s", msg);
170 }
171
172 protected:
175 size_t data_pos = 0;
176
177 bool setPos(const char *id) {
178 int id_len = strlen(id);
179 int pos = indexOf(id);
180 if (pos < 0) return false;
181 data_pos = pos + id_len;
182 return true;
183 }
184
185 int indexOf(const char *str) {
186 return StrView((char *)buffer.data(), MAX_WAV_HEADER_LEN,
188 .indexOf(str);
189 }
190
192 uint32_t tag = 0;
193 tag = (tag << 8) | getChar();
194 tag = (tag << 8) | getChar();
195 tag = (tag << 8) | getChar();
196 tag = (tag << 8) | getChar();
197 return tag;
198 }
199
200 uint32_t getChar32() { return getChar(); }
201
203 uint32_t value = 0;
204 value |= getChar32() << 0;
205 value |= getChar32() << 8;
206 value |= getChar32() << 16;
207 value |= getChar32() << 24;
208 return value;
209 }
210
212 uint16_t value = 0;
213 value |= getChar() << 0;
214 value |= getChar() << 8;
215 return value;
216 }
217
218 void skip(int n) {
219 int i;
220 for (i = 0; i < n; i++) getChar();
221 }
222
223 int getChar() {
224 if (data_pos < buffer.size())
225 return buffer.data()[data_pos++];
226 else
227 return -1;
228 }
229
230 void seek(long int offset, int origin) {
231 if (origin == SEEK_SET) {
232 data_pos = offset;
233 } else if (origin == SEEK_CUR) {
234 data_pos += offset;
235 }
236 }
237
238 size_t tell() { return data_pos; }
239
240 bool eof() { return data_pos >= buffer.size() - 1; }
241
242 void logInfo() {
243 LOGI("WAVHeader sound_pos: %d", getDataPos());
244 LOGI("WAVHeader channels: %d ", headerInfo.channels);
245 LOGI("WAVHeader bits_per_sample: %d", headerInfo.bits_per_sample);
246 LOGI("WAVHeader sample_rate: %d ", (int)headerInfo.sample_rate);
247 LOGI("WAVHeader format: %d", (int)headerInfo.format);
248 }
249
251 const WAVAudioInfo &info) {
252 buffer.writeArray((uint8_t *)"RIFF", 4);
253 // chunk_size = file_size - 8 (RIFF header size)
254 uint32_t chunk_size = info.file_size > 8 ? info.file_size - 8 : 0;
255 LOGI("writeRiffHeader: file_size=%u riff_size=%u", info.file_size, chunk_size);
257 buffer.writeArray((uint8_t *)"WAVE", 4);
258 }
259
261 uint16_t fmt_len = 16;
262 buffer.writeArray((uint8_t *)"fmt ", 4);
264 write16(buffer, (uint16_t)info.format); // PCM
265 write16(buffer, info.channels);
267 write32(buffer, info.byte_rate);
268 write16(buffer, info.block_align); // frame size
270 }
271
273 buffer.writeArray((uint8_t *)"data", 4);
274 uint32_t data_length = info.data_length;
275 if (headerInfo.is_streamed && data_length == 0) {
276 data_length = ~0; // use max value for streamed data if not set
277 }
278 if (!headerInfo.is_streamed && info.file_size >= 36 && (data_length == 0 || data_length == ~0)) {
279 data_length = info.file_size - 36; // data length = file size - header size (36 bytes)
280 }
281 LOGI("writeDataHeader: data_length=%u", data_length);
282 write32(buffer, data_length);
283 int offset = info.offset;
284 if (offset > 0) {
285 uint8_t empty[offset];
286 memset(empty, 0, offset);
287 buffer.writeArray(empty, offset); // resolve issue with wrong aligment
288 }
289 }
290
292 buffer.writeArray((uint8_t *)&value, 4);
293 }
294
296 buffer.writeArray((uint8_t *)&value, 2);
297 }
298
299};
300
322class WAVDecoder : public AudioDecoder {
323
324 public:
328 WAVDecoder() = default;
329
335
338 TRACED();
340 p_decoder = &dec;
341 }
342
344 void setOutput(Print &out_stream) override { this->p_print = &out_stream; }
345
347 bool begin() override {
348 TRACED();
349 header.clear();
352 buffer24.reset();
353 isFirst = true;
354 active = true;
355 return true;
356 }
357
359 void end() override {
360 TRACED();
362 buffer24.reset();
363 active = false;
364 }
365
367 const char *mime() { return wav_mime; }
368
371
373 AudioInfo audioInfo() override {
375 if (convert8to16 && info.format == AudioFormat::PCM &&
376 info.bits_per_sample == 8) {
378 }
379 // 32 bits gives better result
380 if (convert24 && info.format == AudioFormat::PCM &&
381 info.bits_per_sample == 24) {
383 }
384 return info;
385 }
386
388 virtual size_t write(const uint8_t *data, size_t len) override {
389 TRACED();
390 size_t result = 0;
391 if (active) {
392 if (isFirst) {
393 int data_start = decodeHeader((uint8_t *)data, len);
394 // we do not have the complete header yet: need more data
395 if (data_start == 0) return len;
396 // process the outstanding data
397 result = data_start +
398 write_out((uint8_t *)data + data_start, len - data_start);
399
400 } else if (isValid) {
401 result = write_out((uint8_t *)data, len);
402 }
403 }
404 return result;
405 }
406
408 virtual operator bool() override { return active; }
409
413 }
414
418 }
419
422
423 protected:
425 bool isFirst = true;
426 bool isValid = true;
427 bool active = false;
433 bool convert8to16 = true; // Optional conversion flag
434 bool convert24 = true; // Optional conversion flag
435 const size_t batch_size = 256;
436
437 Print &out() { return p_decoder == nullptr ? *p_print : dec_out; }
438
439 virtual size_t write_out(const uint8_t *in_ptr, size_t in_size) {
440 // check if we need to convert int24 data from 3 bytes to 4 bytes
441 size_t result = 0;
443 header.audioInfo().bits_per_sample == 24 && sizeof(int24_t) == 4) {
445 result = in_size;
448 result = write_out_8to16(in_ptr, in_size);
449 } else {
450 result = out().write(in_ptr, in_size);
451 }
452 return result;
453 }
454
456 size_t write_out_8to16(const uint8_t *in_ptr, size_t in_size) {
457 size_t total_written = 0;
458 size_t samples_remaining = in_size;
459 size_t offset = 0;
461 while (samples_remaining > 0) {
462 size_t current_batch =
464 for (size_t i = 0; i < current_batch; ++i) {
465 out_buf[i] = ((int16_t)in_ptr[offset + i] - 128) << 8;
466 }
468 offset += current_batch;
470 }
471 return in_size;
472 }
473
475 size_t write_out_24(const uint8_t *in_ptr, size_t in_size) {
476 // store 1 sample
479
480 for (size_t i = 0; i < in_size; i++) {
481 // Add byte to buffer
483
484 // Process complete sample when buffer is full
485 if (byte_buffer.isFull()) {
489 if (buffer24.isFull()) {
491 buffer24.reset();
492 }
494 }
495 }
496
497 return in_size;
498 }
499
500
503 int result = in_size;
504 // we expect at least the full header
505 int written = header.write(in_ptr, in_size);
506 if (!header.isDataComplete()) {
507 LOGW("WAV header misses 'data' section in len: %d",
508 (int)header.available());
510 return 0;
511 }
512 // parse header
513 if (!header.parse()) {
514 LOGE("WAV header parsing failed");
515 return 0;
516 }
517
518 isFirst = false;
520
521 LOGI("WAV sample_rate: %d", (int)header.audioInfo().sample_rate);
522 LOGI("WAV data_length: %u", (unsigned)header.audioInfo().data_length);
523 LOGI("WAV is_streamed: %d", header.audioInfo().is_streamed);
524 LOGI("WAV is_valid: %s", header.audioInfo().is_valid ? "true" : "false");
525
526 // check format
528 isValid = format == decoder_format;
529 if (isValid) {
530 // update blocksize
531 if (p_decoder != nullptr) {
532 int block_size = header.audioInfo().block_align;
533 p_decoder->setBlockSize(block_size);
534 }
535
536 // update sampling rate if the target supports it
539 } else {
540 LOGE("WAV format not supported: %d", (int)format);
541 }
542 return header.getDataPos();
543 }
544
546 if (p_decoder != nullptr) {
547 assert(p_print != nullptr);
551 }
552 }
553};
554
565class WAVEncoder : public AudioEncoder {
566 public:
570 WAVEncoder() = default;
571
576
579 TRACED();
581 p_encoder = &enc;
582 }
583
585 void setOutput(Print &out) override {
586 TRACED();
587 p_print = &out;
588 }
589
591 const char *mime() override { return wav_mime; }
592
596 info.format = AudioFormat::PCM;
600 info.is_streamed = true;
601 info.is_valid = true;
602 info.data_length = 0x7fff0000;
603 info.file_size = info.data_length + 36;
604 return info;
605 }
606
608 virtual void setAudioInfo(AudioInfo from) override {
612 // recalculate byte rate, block align...
614 }
615
620 wav_info = ai;
621 LOGI("sample_rate: %d", (int)wav_info.sample_rate);
622 LOGI("channels: %d", wav_info.channels);
623 LOGI("bits_per_sample: %d", wav_info.bits_per_sample);
624 // bytes per second
630 }
631 }
632
635 header.clear();
637 return begin();
638 }
639
641 virtual bool begin() override {
642 TRACED();
644
645 // normalize streaming mode and payload limits at start time
647 wav_info.data_length >= 0x7fff0000) {
648 LOGI("is_streamed! because length is %u",
649 (unsigned)wav_info.data_length);
650 wav_info.is_streamed = true;
652 size_limit = 0;
653 } else {
654 wav_info.is_streamed = false;
656 LOGI("size_limit is %d", (int)size_limit);
657 }
658
659 header_written = false;
660 is_open = true;
661 return true;
662 }
663
665 void end() override { is_open = false; }
666
668 virtual size_t write(const uint8_t *data, size_t len) override {
669 if (!is_open) {
670 LOGE("The WAVEncoder is not open - please call begin()");
671 return 0;
672 }
673
674 if (p_print == nullptr) {
675 LOGE("No output stream was provided");
676 return 0;
677 }
678
679 if (!header_written) {
680 LOGI("Writing Header");
682 LOGE("Failed to write WAV header");
683 is_open = false;
684 return 0;
685 }
686 header_written = true;
687 }
688
689 int32_t result = 0;
690 Print *p_out = p_encoder == nullptr ? p_print : &enc_out;
691
692 if (wav_info.is_streamed) {
693 result = p_out->write((uint8_t *)data, len);
694 } else if (size_limit > 0) {
695 size_t write_size = min((size_t)len, (size_t)size_limit);
696 result = p_out->write((uint8_t *)data, write_size);
697 size_limit -= result;
698
699 if (size_limit <= 0) {
700 LOGI("The defined size was written - so we close the WAVEncoder now");
701 is_open = false;
702 }
703 }
704 return result;
705 }
706
708 operator bool() override { return is_open; }
709
711 bool isOpen() { return is_open; }
712
714 void setDataOffset(uint16_t offset) { wav_info.offset = offset; }
715
717 void setDataLength(uint32_t data_length) {
718 wav_info.data_length = data_length;
720 (data_length == 0 || data_length >= 0x7fff0000);
721 if (!wav_info.is_streamed) {
722 // full file size = RIFF chunk (36) + data chunk payload
724 }
726 }
727
730
733
734 protected:
736 Print *p_print = nullptr; // final output CopyEncoder copy; // used for PCM
741 bool header_written = false;
742 volatile bool is_open = false;
743
745 if (p_encoder != nullptr) {
746 assert(p_print != nullptr);
750 enc_out.begin();
751 // block size only available after begin(): update block size
753 }
754 }
755};
756
757} // namespace audio_tools
WAV Audio Formats used by Microsoft e.g. in AVI video files.
#define LOGW(...)
Definition AudioLoggerIDF.h:29
#define TRACED()
Definition AudioLoggerIDF.h:31
#define LOGI(...)
Definition AudioLoggerIDF.h:28
#define LOGE(...)
Definition AudioLoggerIDF.h:30
#define DEFAULT_BITS_PER_SAMPLE
Definition AudioToolsConfig.h:94
#define DEFAULT_CHANNELS
Definition AudioToolsConfig.h:90
#define DEFAULT_SAMPLE_RATE
Definition AudioToolsConfig.h:86
#define MAX_WAV_HEADER_LEN
Definition CodecWAV.h:9
#define assert(T)
Definition avr.h:10
Definition AudioCodecsBase.h:119
virtual void setBlockSize(int blockSize)=0
Decoding of encoded audio into PCM data.
Definition AudioCodecsBase.h:18
AudioInfo info
Definition AudioCodecsBase.h:76
Print * p_print
Definition AudioCodecsBase.h:75
Definition AudioCodecsBase.h:124
Encoding of PCM data.
Definition AudioCodecsBase.h:97
AudioInfo info
Definition AudioCodecsBase.h:116
void setAudioInfo(AudioInfo from) override
Defines the sample rate, number of channels and bits per sample.
Definition AudioCodecsBase.h:106
void notifyAudioChange(AudioInfo info)
Definition AudioTypes.h:178
Shared functionality of all buffers.
Definition Buffers.h:22
void clear()
same as reset
Definition Buffers.h:95
A more natural Print class to process encoded data (aac, wav, mp3...). Just define the output and the...
Definition AudioEncoded.h:21
void setEncoder(AudioEncoder *encoder)
Definition AudioEncoded.h:131
bool begin() override
Starts the processing - sets the status to active.
Definition AudioEncoded.h:161
virtual void setAudioInfo(AudioInfo newInfo) override
Defines the input AudioInfo.
Definition AudioEncoded.h:87
void setDecoder(AudioDecoder *decoder)
Definition AudioEncoded.h:144
void setOutput(Print *outputStream)
Defines the output.
Definition AudioEncoded.h:107
Definition NoArduino.h:62
virtual size_t write(const uint8_t *data, size_t len)
Definition NoArduino.h:126
A simple Buffer implementation which just uses a (dynamically sized) array.
Definition Buffers.h:172
size_t size() override
Definition Buffers.h:303
bool write(T sample) override
write add an entry to the buffer
Definition Buffers.h:206
void setClearWithZero(bool flag)
Sets the buffer to 0 on clear.
Definition Buffers.h:314
int available() override
provides the number of entries that are available to read
Definition Buffers.h:233
bool isFull() override
checks if the buffer is full
Definition Buffers.h:240
bool resize(int size)
Resizes the buffer if supported: returns false if not supported.
Definition Buffers.h:305
int writeArray(const T data[], int len) override
Fills the buffer data.
Definition Buffers.h:201
T * data()
Provides address of actual data.
Definition Buffers.h:284
void reset() override
clears the buffer
Definition Buffers.h:286
A simple wrapper to provide string functions on existing allocated char*. If the underlying char* is ...
Definition StrView.h:28
virtual int indexOf(const char c, int start=0)
Definition StrView.h:260
A simple WAVDecoder: We parse the header data on the first record to determine the format....
Definition CodecWAV.h:322
virtual size_t write(const uint8_t *data, size_t len) override
Write incoming WAV data (header + PCM) into output.
Definition CodecWAV.h:388
bool active
Definition CodecWAV.h:427
void setOutput(Print &out_stream) override
Defines the output Stream.
Definition CodecWAV.h:344
bool isFirst
Definition CodecWAV.h:425
void setDecoder(AudioDecoderExt &dec, AudioFormat fmt)
Defines an optional decoder if the format is not PCM.
Definition CodecWAV.h:337
size_t write_out_24(const uint8_t *in_ptr, size_t in_size)
convert 3 byte int24 to 4 byte int32
Definition CodecWAV.h:475
Print & out()
Definition CodecWAV.h:437
int decodeHeader(uint8_t *in_ptr, size_t in_size)
Decodes the header data: Returns the start pos of the data.
Definition CodecWAV.h:502
AudioDecoderExt * p_decoder
Definition CodecWAV.h:429
void setConvert8Bit(bool enable)
Convert 8 bit to 16 bit PCM data (default: enabled)
Definition CodecWAV.h:411
void setupEncodedAudio()
Definition CodecWAV.h:545
void end() override
Finish decoding and release temporary buffers.
Definition CodecWAV.h:359
AudioFormat decoder_format
Definition CodecWAV.h:428
WAVHeader & getHeader()
Access to the internal header parser and info.
Definition CodecWAV.h:421
const char * mime()
Provides MIME type "audio/wav".
Definition CodecWAV.h:367
bool isValid
Definition CodecWAV.h:426
WAVDecoder()=default
Construct a new WAVDecoder object for PCM data.
const size_t batch_size
Definition CodecWAV.h:435
SingleBuffer< uint8_t > byte_buffer
Definition CodecWAV.h:431
WAVAudioInfo & audioInfoEx()
Extended WAV specific info (original header values)
Definition CodecWAV.h:370
WAVHeader header
Definition CodecWAV.h:424
WAVDecoder(AudioDecoderExt &dec, AudioFormat fmt)
Construct a new WAVDecoder object for ADPCM data.
Definition CodecWAV.h:334
void setConvert24Bit(bool enable)
Convert 24 bit (3 byte) to 32 bit (4 byte) PCM data (default: enabled)
Definition CodecWAV.h:416
bool begin() override
Prepare decoder for a new WAV stream.
Definition CodecWAV.h:347
size_t write_out_8to16(const uint8_t *in_ptr, size_t in_size)
Convert 8-bit PCM to 16-bit PCM and write out.
Definition CodecWAV.h:456
EncodedAudioOutput dec_out
Definition CodecWAV.h:430
bool convert24
Definition CodecWAV.h:434
virtual size_t write_out(const uint8_t *in_ptr, size_t in_size)
Definition CodecWAV.h:439
AudioInfo audioInfo() override
Exposed AudioInfo (may reflect conversion flags)
Definition CodecWAV.h:373
bool convert8to16
Definition CodecWAV.h:433
SingleBuffer< int32_t > buffer24
Definition CodecWAV.h:432
A simple WAV file encoder. If no AudioEncoderExt is specified the WAV file contains PCM data,...
Definition CodecWAV.h:565
virtual size_t write(const uint8_t *data, size_t len) override
Writes PCM data to be encoded as WAV.
Definition CodecWAV.h:668
void setOutput(Print &out) override
Defines the otuput stream.
Definition CodecWAV.h:585
volatile bool is_open
Definition CodecWAV.h:742
bool isOpen()
Check if encoder is open.
Definition CodecWAV.h:711
void setupEncodedAudio()
Definition CodecWAV.h:744
virtual bool begin() override
starts the processing using the actual WAVAudioInfo
Definition CodecWAV.h:641
bool header_written
Definition CodecWAV.h:741
AudioEncoderExt * p_encoder
Definition CodecWAV.h:737
bool begin(WAVAudioInfo ai)
starts the processing
Definition CodecWAV.h:634
WAVAudioInfo wav_info
Definition CodecWAV.h:739
void end() override
stops the processing
Definition CodecWAV.h:665
virtual void setAudioInfo(WAVAudioInfo ai)
Defines the WAVAudioInfo.
Definition CodecWAV.h:617
int64_t size_limit
Definition CodecWAV.h:740
WAVEncoder()=default
Construct a new WAVEncoder object for PCM data.
void setDataOffset(uint16_t offset)
Adds n empty bytes at the beginning of the data.
Definition CodecWAV.h:714
WAVHeader & getHeader()
Access to the internal header parser and info.
Definition CodecWAV.h:732
EncodedAudioOutput enc_out
Definition CodecWAV.h:738
WAVAudioInfo & audioInfoEx()
Extended WAV specific info.
Definition CodecWAV.h:729
WAVEncoder(AudioEncoderExt &enc, AudioFormat fmt)
Construct a new WAVEncoder object for ADPCM data.
Definition CodecWAV.h:575
WAVAudioInfo defaultConfig()
Provides the default configuration.
Definition CodecWAV.h:594
WAVHeader header
Definition CodecWAV.h:735
const char * mime() override
Provides "audio/wav".
Definition CodecWAV.h:591
virtual void setAudioInfo(AudioInfo from) override
Update actual WAVAudioInfo.
Definition CodecWAV.h:608
Print * p_print
Definition CodecWAV.h:736
void setEncoder(AudioEncoderExt &enc, AudioFormat fmt)
Associates an external encoder for non-PCM formats.
Definition CodecWAV.h:578
void setDataLength(uint32_t data_length)
Defines the WAV payload length in bytes (without header)
Definition CodecWAV.h:717
Parser for Wav header data for details see https://de.wikipedia.org/wiki/RIFF_WAVE.
Definition CodecWAV.h:65
void writeDataHeader(BaseBuffer< uint8_t > &buffer, const WAVAudioInfo &info)
Definition CodecWAV.h:272
void logInfo()
Definition CodecWAV.h:242
void write16(BaseBuffer< uint8_t > &buffer, uint16_t value)
Definition CodecWAV.h:295
bool parse()
Call when header data write is complete to parse the data.
Definition CodecWAV.h:76
bool isDataComplete()
Returns true if the header is complete (containd data tag)
Definition CodecWAV.h:106
void skip(int n)
Definition CodecWAV.h:218
void seek(long int offset, int origin)
Definition CodecWAV.h:230
void setAudioInfo(WAVAudioInfo info)
Sets the info in the header.
Definition CodecWAV.h:126
bool eof()
Definition CodecWAV.h:240
void writeFMT(BaseBuffer< uint8_t > &buffer, const WAVAudioInfo &info)
Definition CodecWAV.h:260
bool writeHeader(Print *out, const WAVAudioInfo &info)
Just write a wav header with explicit info to the indicated output.
Definition CodecWAV.h:134
size_t available()
number of bytes available in the header buffer
Definition CodecWAV.h:112
bool writeHeader(Print *out)
Just write a wav header to the indicated outputbu.
Definition CodecWAV.h:129
int getChar()
Definition CodecWAV.h:223
int getDataPos()
Determines the data start position using the data tag.
Definition CodecWAV.h:115
SingleBuffer< uint8_t > buffer
Definition CodecWAV.h:174
WAVAudioInfo & audioInfo()
provides the info from the header
Definition CodecWAV.h:123
int write(uint8_t *data, size_t data_len)
Definition CodecWAV.h:71
void clear()
Reset internal stored header information and buffer.
Definition CodecWAV.h:147
uint32_t read_tag()
Definition CodecWAV.h:191
void writeRiffHeader(BaseBuffer< uint8_t > &buffer, const WAVAudioInfo &info)
Definition CodecWAV.h:250
WAVAudioInfo headerInfo
Definition CodecWAV.h:173
uint16_t read_int16()
Definition CodecWAV.h:211
bool setPos(const char *id)
Definition CodecWAV.h:177
uint32_t read_int32()
Definition CodecWAV.h:202
int indexOf(const char *str)
Definition CodecWAV.h:185
size_t data_pos
Definition CodecWAV.h:175
void write32(BaseBuffer< uint8_t > &buffer, uint64_t value)
Definition CodecWAV.h:291
void dumpHeader()
Debug helper: dumps header bytes as printable characters.
Definition CodecWAV.h:159
size_t tell()
Definition CodecWAV.h:238
uint32_t getChar32()
Definition CodecWAV.h:200
24bit integer which is used for I2S sound processing. The values are really using 3 bytes....
Definition Int24_3bytes_t.h:16
24bit integer which is used for I2S sound processing. The values are represented as int32_t,...
Definition Int24_4bytes_t.h:16
AudioFormat
Audio format codes used by Microsoft e.g. in avi or wav files.
Definition AudioFormat.h:19
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition AudioCodecsBase.h:10
static const char * wav_mime
Definition CodecWAV.h:37
size_t writeData(Print *p_out, T *data, int samples, int maxSamples=512)
Definition AudioTypes.h:512
Basic Audio information which drives e.g. I2S.
Definition AudioTypes.h:55
sample_rate_t sample_rate
Sample Rate: e.g 44100.
Definition AudioTypes.h:57
uint16_t channels
Number of channels: 2=stereo, 1=mono.
Definition AudioTypes.h:59
uint8_t bits_per_sample
Number of bits per sample (int16_t = 16 bits)
Definition AudioTypes.h:61
Sound information which is available in the WAV header.
Definition CodecWAV.h:19
AudioFormat format
Definition CodecWAV.h:27
bool is_streamed
Definition CodecWAV.h:30
bool is_valid
Definition CodecWAV.h:31
int block_align
Definition CodecWAV.h:29
WAVAudioInfo(const AudioInfo &from)
Definition CodecWAV.h:21
uint32_t file_size
Definition CodecWAV.h:33
int offset
Definition CodecWAV.h:34
int byte_rate
Definition CodecWAV.h:28
uint32_t data_length
Definition CodecWAV.h:32