Ψ-W1-T1 second-round remediation: ±1-frame bounds tolerance, self-cleanup a refused render, hedge two unverified render-source inferences
Loosens the exact-bounds gate against REAPER's edge rounding; deletes the bytes a BoundsMismatch refusal writes, per prune_fs's self-cleanup carve-out.
This commit is contained in:
@@ -21,11 +21,13 @@
|
||||
#include "shell/capture/capture.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <ctime>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <system_error>
|
||||
#include <vector>
|
||||
|
||||
#include "core/capture/capture_paths.h"
|
||||
@@ -396,13 +398,14 @@ CaptureResult OfflineRenderBackend::capture(const CaptureRequest& request) {
|
||||
}
|
||||
|
||||
// Exact bounds, made structural: with no tail requested the file must contain
|
||||
// exactly the requested window's frames, so a source mode that silently widened
|
||||
// the render fails loudly here instead of landing as a successful capture. Auto
|
||||
// and Manual add frames by design and are skipped. UNVERIFIED: that REAPER
|
||||
// resolves the window's two edges to frame indices the same way frameCountFor
|
||||
// does — a DAW pass decides whether this equality is exact or off by a frame.
|
||||
// (within a tolerance, see below) the requested window's frames, so a source
|
||||
// mode that silently widened the render fails loudly here instead of landing as
|
||||
// a successful capture. Auto and Manual add frames by design and are skipped.
|
||||
// (The file is read again by stampCaptureSample below; the duplicate read is a
|
||||
// once-per-capture cost on an already-warm file.)
|
||||
// once-per-capture cost on an already-warm file.) A bounded/header-only read is
|
||||
// not a clean substitute: parseWavLayout only marks the data chunk valid when
|
||||
// the buffer holds the chunk's FULL declared body (bodyInBounds), so a truncated
|
||||
// read would read as invalid here on every real capture, not just malformed ones.
|
||||
if (request.tailMode == TailMode::None) {
|
||||
const WavLayout layout =
|
||||
parseWavLayout(util::readFileBytes(expectedPath));
|
||||
@@ -411,15 +414,35 @@ CaptureResult OfflineRenderBackend::capture(const CaptureRequest& request) {
|
||||
static_cast<int>(layout.sampleRate))
|
||||
: 0;
|
||||
const long long actualFrames = static_cast<long long>(layout.frameCount());
|
||||
if (expectedFrames > 0 && actualFrames != expectedFrames) {
|
||||
// frameCountFor is a difference of frame indices, not a rounded duration
|
||||
// (see render_window.h) — REAPER's own edge-rounding can legitimately land
|
||||
// one frame off that, so the gate tolerates +/-1 rather than exact equality.
|
||||
// The defect this refuses is a whole-item widening (seconds of extra audio,
|
||||
// thousands of frames), which a 1-frame tolerance still catches with
|
||||
// certainty. Tightening to exact equality needs a DAW pass confirming REAPER
|
||||
// resolves the window's two edges to frame indices the same way this does.
|
||||
const long long frameDelta = actualFrames > expectedFrames
|
||||
? actualFrames - expectedFrames
|
||||
: expectedFrames - actualFrames;
|
||||
if (expectedFrames > 0 && frameDelta > 1) {
|
||||
result.status = CaptureStatus::BoundsMismatch;
|
||||
result.message = "Render produced " + std::to_string(actualFrames) +
|
||||
" frames but the requested range is " +
|
||||
std::to_string(expectedFrames) + " at " +
|
||||
std::to_string(layout.sampleRate) +
|
||||
" Hz -- the render did not honor the requested bounds. "
|
||||
"Nothing was added to the bank; the file is at: " +
|
||||
expectedPath;
|
||||
"Requested [" + std::to_string(request.startSeconds) +
|
||||
"s, " + std::to_string(request.endSeconds) +
|
||||
"s) -> frame indices [" +
|
||||
std::to_string(std::llround(request.startSeconds *
|
||||
layout.sampleRate)) +
|
||||
", " +
|
||||
std::to_string(std::llround(request.endSeconds *
|
||||
layout.sampleRate)) +
|
||||
"). Nothing was added to the bank; the render at " +
|
||||
expectedPath + " was never indexed and has been cleaned up.";
|
||||
std::error_code ec;
|
||||
std::filesystem::remove(expectedPath, ec);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user