Skip to content

Commit a1ecd88

Browse files
committed
WAV extended logging
1 parent 9ba1f84 commit a1ecd88

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/AudioCodecs/CodecWAV.h

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "AudioBasic/Str.h"
66

77
#define READ_BUFFER_SIZE 512
8-
#define MAX_WAV_HEADER_LEN 50
8+
#define MAX_WAV_HEADER_LEN 200
99

1010
namespace audio_tools {
1111

@@ -80,14 +80,20 @@ class WAVHeader {
8080
return true;
8181
}
8282

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)
8484
bool isDataComplete() {
8585
int pos = getDataPos();
86-
return pos > 0 && buffer.available() >= pos;;
86+
return pos > 0 && buffer.available() >= pos;
8787
}
8888

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
8995
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");
9197
return pos > 0 ? pos + 8 : 0;
9298
}
9399

@@ -116,6 +122,18 @@ class WAVHeader {
116122
buffer.reset();
117123
}
118124

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+
119137

120138
protected:
121139
struct WAVAudioInfo headerInfo;
@@ -380,10 +398,13 @@ class WAVDecoder : public AudioDecoder {
380398
// we expect at least the full header
381399
int written = header.write(in_ptr, in_size);
382400
if (!header.isDataComplete()) {
401+
LOGW("WAV header misses 'data' section in len: %d", header.available());
402+
header.dumpHeader();
383403
return 0;
384404
}
385405
// parse header
386406
if (!header.parse()){
407+
LOGE("WAV header parsing failed");
387408
return 0;
388409
}
389410

0 commit comments

Comments
 (0)