Skip to content

Commit

Permalink
WAV extended logging
Browse files Browse the repository at this point in the history
  • Loading branch information
pschatzmann committed Oct 3, 2024
1 parent 9ba1f84 commit a1ecd88
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/AudioCodecs/CodecWAV.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "AudioBasic/Str.h"

#define READ_BUFFER_SIZE 512
#define MAX_WAV_HEADER_LEN 50
#define MAX_WAV_HEADER_LEN 200

namespace audio_tools {

Expand Down Expand Up @@ -80,14 +80,20 @@ class WAVHeader {
return true;
}

/// Returns true if the header is complete (with 44 bytes): contains data + 4 byte len
/// Returns true if the header is complete (containd data tag)
bool isDataComplete() {
int pos = getDataPos();
return pos > 0 && buffer.available() >= pos;;
return pos > 0 && buffer.available() >= pos;
}

/// number of bytes available in the header buffer
size_t available(){
return buffer.available();
}

/// Determines the data start position using the data tag
int getDataPos() {
int pos = Str((char*)buffer.data(),MAX_WAV_HEADER_LEN, buffer.size()).indexOf("data");
int pos = Str((char*)buffer.data(),MAX_WAV_HEADER_LEN, buffer.available()).indexOf("data");
return pos > 0 ? pos + 8 : 0;
}

Expand Down Expand Up @@ -116,6 +122,18 @@ class WAVHeader {
buffer.reset();
}

void dumpHeader() {
char msg[buffer.available()+1] = {0};
for (int j = 0; j< buffer.available();j++){
char c = (char)buffer.data()[j];
if (!isalpha(c)){
c = '.';
}
msg[j] = c;
}
LOGI("Header: %s", msg);
}


protected:
struct WAVAudioInfo headerInfo;
Expand Down Expand Up @@ -380,10 +398,13 @@ class WAVDecoder : public AudioDecoder {
// we expect at least the full header
int written = header.write(in_ptr, in_size);
if (!header.isDataComplete()) {
LOGW("WAV header misses 'data' section in len: %d", header.available());
header.dumpHeader();
return 0;
}
// parse header
if (!header.parse()){
LOGE("WAV header parsing failed");
return 0;
}

Expand Down

0 comments on commit a1ecd88

Please sign in to comment.