|
5 | 5 | #include "AudioBasic/Str.h" |
6 | 6 |
|
7 | 7 | #define READ_BUFFER_SIZE 512 |
8 | | -#define MAX_WAV_HEADER_LEN 50 |
| 8 | +#define MAX_WAV_HEADER_LEN 200 |
9 | 9 |
|
10 | 10 | namespace audio_tools { |
11 | 11 |
|
@@ -80,14 +80,20 @@ class WAVHeader { |
80 | 80 | return true; |
81 | 81 | } |
82 | 82 |
|
83 | | - /// Returns true if the header is complete (with 44 bytes): contains data + 4 byte len |
| 83 | + /// Returns true if the header is complete (containd data tag) |
84 | 84 | bool isDataComplete() { |
85 | 85 | int pos = getDataPos(); |
86 | | - return pos > 0 && buffer.available() >= pos;; |
| 86 | + return pos > 0 && buffer.available() >= pos; |
87 | 87 | } |
88 | 88 |
|
| 89 | + /// number of bytes available in the header buffer |
| 90 | + size_t available(){ |
| 91 | + return buffer.available(); |
| 92 | + } |
| 93 | + |
| 94 | + /// Determines the data start position using the data tag |
89 | 95 | int getDataPos() { |
90 | | - int pos = Str((char*)buffer.data(),MAX_WAV_HEADER_LEN, buffer.size()).indexOf("data"); |
| 96 | + int pos = Str((char*)buffer.data(),MAX_WAV_HEADER_LEN, buffer.available()).indexOf("data"); |
91 | 97 | return pos > 0 ? pos + 8 : 0; |
92 | 98 | } |
93 | 99 |
|
@@ -116,6 +122,18 @@ class WAVHeader { |
116 | 122 | buffer.reset(); |
117 | 123 | } |
118 | 124 |
|
| 125 | + void dumpHeader() { |
| 126 | + char msg[buffer.available()+1] = {0}; |
| 127 | + for (int j = 0; j< buffer.available();j++){ |
| 128 | + char c = (char)buffer.data()[j]; |
| 129 | + if (!isalpha(c)){ |
| 130 | + c = '.'; |
| 131 | + } |
| 132 | + msg[j] = c; |
| 133 | + } |
| 134 | + LOGI("Header: %s", msg); |
| 135 | + } |
| 136 | + |
119 | 137 |
|
120 | 138 | protected: |
121 | 139 | struct WAVAudioInfo headerInfo; |
@@ -380,10 +398,13 @@ class WAVDecoder : public AudioDecoder { |
380 | 398 | // we expect at least the full header |
381 | 399 | int written = header.write(in_ptr, in_size); |
382 | 400 | if (!header.isDataComplete()) { |
| 401 | + LOGW("WAV header misses 'data' section in len: %d", header.available()); |
| 402 | + header.dumpHeader(); |
383 | 403 | return 0; |
384 | 404 | } |
385 | 405 | // parse header |
386 | 406 | if (!header.parse()){ |
| 407 | + LOGE("WAV header parsing failed"); |
387 | 408 | return 0; |
388 | 409 | } |
389 | 410 |
|
|
0 commit comments