Ψ-W2-T2 remediation: atomic temp+rename collapse write, honest unknown-channel fallback, [verify — DAW] markers, corrected+filed bake-collapse deferral, observable collapse message, quiet-NaN test
This commit is contained in:
@@ -51,6 +51,16 @@ static void putFloat(std::vector<std::uint8_t>& b, float f) {
|
||||
std::memcpy(tmp, &f, 4);
|
||||
for (int i = 0; i < 4; ++i) b.push_back(tmp[i]);
|
||||
}
|
||||
static float floatFromBits(std::uint32_t bits) {
|
||||
float f;
|
||||
std::memcpy(&f, &bits, 4);
|
||||
return f;
|
||||
}
|
||||
static std::uint32_t bitsFromFloat(float f) {
|
||||
std::uint32_t bits;
|
||||
std::memcpy(&bits, &f, 4);
|
||||
return bits;
|
||||
}
|
||||
|
||||
// A canonical 32-bit-float WAV: RIFF/WAVE, fmt (tag 3, 16-byte body), data holding
|
||||
// `frames` interleaved frames of `channels`. `leadingJunk` optionally inserts an
|
||||
@@ -746,6 +756,25 @@ static void testCollapseChangesContentHash() {
|
||||
CHECK(hashWavContent(c.bytes) != hashWavContent(wav));
|
||||
}
|
||||
|
||||
// The float->double->float rebuild's stated hole is a SIGNALING NaN (double promotion
|
||||
// quiets it); a QUIET NaN is not that hole. Both channels carry the identical
|
||||
// quiet-NaN bit pattern, so the predicate collapses; the rebuilt mono channel must
|
||||
// carry that exact bit pattern back, not merely "some NaN".
|
||||
static void testCollapsePreservesQuietNaNBitPattern() {
|
||||
constexpr std::uint32_t kQuietNaNBits = 0x7FC12345u; // exponent all-ones, mantissa MSB set
|
||||
auto wav = buildFloatWav(2, 48000, 1,
|
||||
[kQuietNaNBits](std::size_t, std::uint16_t) {
|
||||
return floatFromBits(kQuietNaNBits);
|
||||
});
|
||||
const MonoCollapse c = collapseToMono(wav);
|
||||
CHECK(c.collapsed);
|
||||
const WavLayout L = parseWavLayout(c.bytes);
|
||||
CHECK(L.valid && L.channelCount == 1 && L.frameCount() == 1);
|
||||
const auto pcm = extractFloatFrames(c.bytes, L, 0, 1);
|
||||
CHECK(pcm.size() == 1);
|
||||
if (!pcm.empty()) CHECK(bitsFromFloat(pcm[0]) == kQuietNaNBits);
|
||||
}
|
||||
|
||||
int main() {
|
||||
testParseCanonicalStereo();
|
||||
testParseMonoAndLeadingChunk();
|
||||
@@ -780,6 +809,7 @@ int main() {
|
||||
testCollapseThroughOddPaddedLeadingChunk();
|
||||
testCollapseDeclinesOnUnparseableBytes();
|
||||
testCollapseChangesContentHash();
|
||||
testCollapsePreservesQuietNaNBitPattern();
|
||||
|
||||
if (g_fail == 0) std::printf("wav_codec: all tests passed\n");
|
||||
else std::printf("wav_codec: %d CHECK(s) FAILED\n", g_fail);
|
||||
|
||||
Reference in New Issue
Block a user