fix(render48k): chunk-scan WAV loader — hdr[40] is not data size when bext/junk present
This commit is contained in:
+15
-1
@@ -26,7 +26,21 @@ static bool load_wav(const char* path, std::vector<float>& out, int& sr) {
|
||||
sr = *(int*)(hdr + 24);
|
||||
int ch = *(short*)(hdr + 22);
|
||||
int bits = *(short*)(hdr + 34);
|
||||
int data = *(int*)(hdr + 40);
|
||||
// scan chunks to find data chunk size (hdr[40] may be bext/junk size)
|
||||
int data = 0;
|
||||
int64_t pos = 12;
|
||||
fseek(f, 12, SEEK_SET);
|
||||
while (pos < 32 * 1024 * 1024) {
|
||||
char cid[4]; int csize;
|
||||
if (fread(cid, 1, 4, f) < 4 || fread(&csize, 4, 1, f) < 1) break;
|
||||
pos += 8;
|
||||
if (memcmp(cid, "data", 4) == 0) { data = csize; break; }
|
||||
pos += csize;
|
||||
int skip = csize;
|
||||
if (csize % 2) skip++; // odd chunk size padded
|
||||
fseek(f, skip, SEEK_CUR);
|
||||
}
|
||||
if (!data) { fclose(f); return false; }
|
||||
int n = data / (ch * (bits / 8));
|
||||
g_in_ch = ch;
|
||||
out.resize(n);
|
||||
|
||||
Reference in New Issue
Block a user