@mthines/reaper-mcp 0.75.0-beta.89.2 → 0.75.0-beta.90.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -37
- package/bridge-ui/mcp_bridge.html +38 -38
- package/main.js +2 -4
- package/package.json +1 -1
- package/reaper/mcp_edit_views_lib.lua +99 -6
- package/sidecar/tests/test_verify.py +3 -52
- package/sidecar/verify.py +6 -58
package/main.js
CHANGED
|
@@ -5544,7 +5544,7 @@ function alignmentSummary(data) {
|
|
|
5544
5544
|
...data["warning"] ? { warn: 1 } : {}
|
|
5545
5545
|
};
|
|
5546
5546
|
}
|
|
5547
|
-
var VERIFY_CHECKS = ["null", "discontinuity", "pitch", "tone", "transients"
|
|
5547
|
+
var VERIFY_CHECKS = ["null", "discontinuity", "pitch", "tone", "transients"];
|
|
5548
5548
|
function verifyRow(key, c) {
|
|
5549
5549
|
const verdict = typeof c["verdict"] === "string" ? c["verdict"] : "unknown";
|
|
5550
5550
|
const f = (v, digits, unit) => num(v) === void 0 ? "" : `${num(v).toFixed(digits)}${unit}`;
|
|
@@ -5566,8 +5566,6 @@ function verifyRow(key, c) {
|
|
|
5566
5566
|
return [key, verdict, f(c["driftCents"], 0, " cents"), typeof c["reason"] === "string" ? c["reason"] : f(c["referenceHz"], 0, " Hz reference")];
|
|
5567
5567
|
case "tone":
|
|
5568
5568
|
return [key, verdict, f(c["distanceDb"], 2, " dB"), ""];
|
|
5569
|
-
case "dropout":
|
|
5570
|
-
return [key, verdict, f(c["deepestDipDb"], 1, " dB"), typeof c["reason"] === "string" ? c["reason"] : "deepest dip under the original"];
|
|
5571
5569
|
default:
|
|
5572
5570
|
return [key, verdict, f(c["fluxLogRatio"], 2, ""), typeof c["reason"] === "string" ? c["reason"] : ""];
|
|
5573
5571
|
}
|
|
@@ -5930,7 +5928,7 @@ function registerOfflineTools(server) {
|
|
|
5930
5928
|
);
|
|
5931
5929
|
server.tool(
|
|
5932
5930
|
"verify_edit",
|
|
5933
|
-
`Check the result of an edit you just made, since you cannot hear it: compare the edited track with the audio from before the edit and get a verdict per check. Compensated null: the delay (ms, + = later), gain (dB) and polarity between the two are estimated and removed, and the residual left (dB below the reference) says whether anything else changed (noise, a splice, a different waveform, a swapped stereo channel; it is relative to referenceRmsDb, so with a quiet reference the rounding noise of a 16-bit bounce can set it). Discontinuity: the largest sample-to-sample jump on any channel against the reference's own, with where it happens and which channel (a click or hard splice). Use expect 'identical' (default) for edits that should leave the sound alone apart from level, delay and polarity (alignment, gain, split, crossfade): the residual is judged ok/warn/fail. Use "changed" for EQ, compression and the like: the residual is reported without a verdict. Set timeScale to the playback rate when the edit changed the timing (1.1 = the edit is 10% shorter): the waveform null is then skipped and the click check runs with three warn-only character checks against the reference warped through that rate: pitch drift in cents (skipped for unpitched material), tone (long-term spectrum distance in dB
|
|
5931
|
+
`Check the result of an edit you just made, since you cannot hear it: compare the edited track with the audio from before the edit and get a verdict per check. Compensated null: the delay (ms, + = later), gain (dB) and polarity between the two are estimated and removed, and the residual left (dB below the reference) says whether anything else changed (noise, a splice, a different waveform, a swapped stereo channel; it is relative to referenceRmsDb, so with a quiet reference the rounding noise of a 16-bit bounce can set it). Discontinuity: the largest sample-to-sample jump on any channel against the reference's own, with where it happens and which channel (a click or hard splice). Use expect 'identical' (default) for edits that should leave the sound alone apart from level, delay and polarity (alignment, gain, split, crossfade): the residual is judged ok/warn/fail. Use "changed" for EQ, compression and the like: the residual is reported without a verdict. Set timeScale to the playback rate when the edit changed the timing (1.1 = the edit is 10% shorter): the waveform null is then skipped and the click check runs with three warn-only character checks against the reference warped through that rate: pitch drift in cents (skipped for unpitched material), tone (long-term spectrum distance in dB) and transients (smeared attacks). The reference is another track (e.g. a copy you kept) or an audio file of the same range from before the edit (a bounce), not an undo. Keep a reference track unmuted so it renders. The tone check misses a phase vocoder's smearing and the transient check is blind on drums. A passing result is evidence, not a replacement for listening. Requires the Python sidecar.`,
|
|
5934
5932
|
{
|
|
5935
5933
|
trackIndex: z28.coerce.number().int().min(0).describe("Zero-based index of the edited track"),
|
|
5936
5934
|
referenceTrack: z28.coerce.number().int().min(0).optional().describe("Zero-based index of a track holding the audio from before the edit (give this or referencePath)"),
|
package/package.json
CHANGED
|
@@ -616,6 +616,57 @@ local function item_view(params, before)
|
|
|
616
616
|
return r
|
|
617
617
|
end
|
|
618
618
|
|
|
619
|
+
-- Item selection: the media items selected, per track (0-based item indexes), tracks without any left out
|
|
620
|
+
local function selected_items()
|
|
621
|
+
local out = {}
|
|
622
|
+
for t = 0, (api.CountTracks(0) or 0) - 1 do
|
|
623
|
+
local tr = api.GetTrack(0, t)
|
|
624
|
+
local picked
|
|
625
|
+
for i = 0, (api.CountTrackMediaItems(tr) or 0) - 1 do
|
|
626
|
+
if api.IsMediaItemSelected(api.GetTrackMediaItem(tr, i)) then
|
|
627
|
+
picked = picked or {}
|
|
628
|
+
picked[#picked + 1] = i
|
|
629
|
+
end
|
|
630
|
+
end
|
|
631
|
+
if picked then out[t] = picked end
|
|
632
|
+
end
|
|
633
|
+
return out
|
|
634
|
+
end
|
|
635
|
+
|
|
636
|
+
-- The timeline with a lane per track that has selected items, now or before (the first four): every item on the
|
|
637
|
+
-- track, which ones are selected (`picked`) and which were (`wasPicked`)
|
|
638
|
+
local function selection_view(before)
|
|
639
|
+
local now, was = selected_items(), before or {}
|
|
640
|
+
local order, seen = {}, {}
|
|
641
|
+
for _, set in ipairs({ now, was }) do
|
|
642
|
+
for t in pairs(set) do
|
|
643
|
+
if not seen[t] then seen[t] = true; order[#order + 1] = t end
|
|
644
|
+
end
|
|
645
|
+
end
|
|
646
|
+
table.sort(order)
|
|
647
|
+
local r = timeline_snapshot()
|
|
648
|
+
r.lanes, r.selected, r.wasSelected = {}, 0, 0
|
|
649
|
+
for _, picked in pairs(now) do r.selected = r.selected + #picked end
|
|
650
|
+
for _, picked in pairs(was) do r.wasSelected = r.wasSelected + #picked end
|
|
651
|
+
local all = {}
|
|
652
|
+
for i = 1, math.min(#order, 4) do
|
|
653
|
+
local t = order[i]
|
|
654
|
+
local tr = api.GetTrack(0, t)
|
|
655
|
+
local lane = { t = name_of(tr), items = track_items(tr) }
|
|
656
|
+
local function within(list)
|
|
657
|
+
local out = {}
|
|
658
|
+
for _, idx in ipairs(list or {}) do if idx < EDIT_MAX_MARKS then out[#out + 1] = idx end end
|
|
659
|
+
return #out > 0 and out or nil
|
|
660
|
+
end
|
|
661
|
+
lane.picked, lane.wasPicked = within(now[t]), within(was[t])
|
|
662
|
+
r.lanes[i] = lane
|
|
663
|
+
for _, it in ipairs(lane.items) do all[#all + 1] = it end
|
|
664
|
+
end
|
|
665
|
+
if #order > 4 then r.moreTracks = #order - 4 end
|
|
666
|
+
r.len = project_length(r, all)
|
|
667
|
+
return r
|
|
668
|
+
end
|
|
669
|
+
|
|
619
670
|
-- Arrangement edits: the whole timeline before and after, a lane for up to four tracks the
|
|
620
671
|
-- edit touches, and the span it worked on (copied from, opened, cut) and where it copied to
|
|
621
672
|
local ARRANGE = {}
|
|
@@ -871,7 +922,8 @@ local WAVE_MAX_SAMPLES = 2000000 -- longer renders are read with a stride
|
|
|
871
922
|
local WAV_SAMPLE = { [1] = { [16] = { "<i2", 32768 }, [24] = { "<i3", 8388608 }, [32] = { "<i4", 2147483648 } },
|
|
872
923
|
[3] = { [32] = { "<f", 1 }, [64] = { "<d", 1 } } }
|
|
873
924
|
|
|
874
|
-
local function wav_waveform(path)
|
|
925
|
+
local function wav_waveform(path, buckets, max_samples)
|
|
926
|
+
buckets, max_samples = buckets or WAVE_BUCKETS, max_samples or WAVE_MAX_SAMPLES
|
|
875
927
|
if type(path) ~= "string" then return nil end
|
|
876
928
|
local f = io.open(path, "rb")
|
|
877
929
|
if not f then return nil end
|
|
@@ -897,12 +949,12 @@ local function wav_waveform(path)
|
|
|
897
949
|
local frame_bytes = width * channels
|
|
898
950
|
local frames = data_len // frame_bytes
|
|
899
951
|
if frames < 1 then return nil end
|
|
900
|
-
local stride = math.max(1, math.ceil(frames * channels /
|
|
952
|
+
local stride = math.max(1, math.ceil(frames * channels / max_samples))
|
|
901
953
|
local hi, lo = {}, {}
|
|
902
|
-
for b = 1,
|
|
954
|
+
for b = 1, buckets do hi[b], lo[b] = 0, 0 end
|
|
903
955
|
local peak, sum, count, clipped = 0, 0, 0, 0
|
|
904
956
|
for fr = 0, frames - 1, stride do
|
|
905
|
-
local b = fr *
|
|
957
|
+
local b = fr * buckets // frames + 1
|
|
906
958
|
local at = data_pos + fr * frame_bytes
|
|
907
959
|
for _ = 1, channels do
|
|
908
960
|
local v = string.unpack(fmt, s, at) / scale
|
|
@@ -916,9 +968,44 @@ local function wav_waveform(path)
|
|
|
916
968
|
count = count + 1
|
|
917
969
|
end
|
|
918
970
|
end
|
|
919
|
-
for b = 1,
|
|
971
|
+
for b = 1, buckets do hi[b], lo[b] = round2(hi[b]), round2(lo[b]) end
|
|
920
972
|
local db = function(v) return v > 0 and round2(20 * math.log(v, 10)) or -150 end
|
|
921
|
-
|
|
973
|
+
-- The stride read is the second value, so a caller that merges the table into a result never carries it
|
|
974
|
+
return { hi = hi, lo = lo, peakDb = db(peak), rmsDb = db(math.sqrt(sum / count)), clipped = clipped, channels = channels }, stride
|
|
975
|
+
end
|
|
976
|
+
|
|
977
|
+
-- render_tracks_to_wav: one waveform per rendered track on a shared time axis, read from the cached files (the
|
|
978
|
+
-- bridge keeps them). Coarser than a single render's (fewer slices, a stride through long files) and read within
|
|
979
|
+
-- a time budget, so a 16-track render does not hold the main thread; tracks past the cap or the budget are counted
|
|
980
|
+
local WAVES_MAX_TRACKS = 8
|
|
981
|
+
local WAVES_BUCKETS = 60
|
|
982
|
+
local WAVES_MAX_SAMPLES = 300000
|
|
983
|
+
local WAVES_BUDGET_S = 1.0
|
|
984
|
+
|
|
985
|
+
local function waves_view(params, data)
|
|
986
|
+
if type(data) ~= "table" or type(data.tracks) ~= "table" then return nil end
|
|
987
|
+
local clock = api.time_precise
|
|
988
|
+
local started = clock and clock() or 0
|
|
989
|
+
local rows, more, duration, approx = {}, 0, nil, false
|
|
990
|
+
for _, t in ipairs(data.tracks) do
|
|
991
|
+
duration = duration or round2(t.durationSeconds)
|
|
992
|
+
local ok, wave, stride = false, nil, 1
|
|
993
|
+
if #rows < WAVES_MAX_TRACKS and (not clock or clock() - started < WAVES_BUDGET_S) then
|
|
994
|
+
ok, wave, stride = pcall(wav_waveform, t.wavPath, WAVES_BUCKETS, WAVES_MAX_SAMPLES)
|
|
995
|
+
end
|
|
996
|
+
if ok and wave then
|
|
997
|
+
-- Past the sample cap only every `stride`th frame is read: the clipped count is scaled up and marked approximate
|
|
998
|
+
if (stride or 1) > 1 then approx = true end
|
|
999
|
+
rows[#rows + 1] = { name = t.trackName or "", hi = wave.hi, lo = wave.lo, peakDb = wave.peakDb, rmsDb = wave.rmsDb, clipped = wave.clipped * (stride or 1) }
|
|
1000
|
+
else
|
|
1001
|
+
more = more + 1
|
|
1002
|
+
end
|
|
1003
|
+
end
|
|
1004
|
+
if #rows == 0 then return nil end
|
|
1005
|
+
return {
|
|
1006
|
+
tracks = rows, more = more > 0 and more or nil, durationSeconds = duration, start = round2(tonumber(params.startTime)),
|
|
1007
|
+
approx = approx and 1 or nil, rendered = data.rendered or 0, cached = data.cached or 0,
|
|
1008
|
+
}
|
|
922
1009
|
end
|
|
923
1010
|
|
|
924
1011
|
-- Mixing depth views: built from the handler's own result, which carries the state before
|
|
@@ -1284,6 +1371,8 @@ function M.before(cmd_type, params)
|
|
|
1284
1371
|
return ARRANGE.before(cmd_type, params)
|
|
1285
1372
|
elseif cmd_type == "set_time_selection" or cmd_type == "set_cursor_position" then
|
|
1286
1373
|
return time_state()
|
|
1374
|
+
elseif cmd_type == "set_selected_items" then
|
|
1375
|
+
return selected_items()
|
|
1287
1376
|
elseif ROUTING_COMMANDS[cmd_type] and cmd_type ~= "get_track_routing" then
|
|
1288
1377
|
local tr = routing_track(params)
|
|
1289
1378
|
return tr and { track = tr, routes = routes_of(tr) }
|
|
@@ -1335,6 +1424,10 @@ function M.summary(cmd_type, params, data, before)
|
|
|
1335
1424
|
return ARRANGE.view(cmd_type, params, data, before)
|
|
1336
1425
|
elseif TIME_COMMANDS[cmd_type] then
|
|
1337
1426
|
return time_view(before)
|
|
1427
|
+
elseif cmd_type == "set_selected_items" then
|
|
1428
|
+
return selection_view(before)
|
|
1429
|
+
elseif cmd_type == "render_tracks_to_wav" then
|
|
1430
|
+
return waves_view(params, data)
|
|
1338
1431
|
elseif ROUTING_COMMANDS[cmd_type] then
|
|
1339
1432
|
-- A write reads the same track it read before (remove_send can leave nothing to resolve by index)
|
|
1340
1433
|
local tr = before and before.track or routing_track(params)
|
|
@@ -270,35 +270,11 @@ def test_a_stretch_that_keeps_the_pitch_passes_every_character_check():
|
|
|
270
270
|
assert checks["transients"]["verdict"] == "ok"
|
|
271
271
|
|
|
272
272
|
|
|
273
|
-
def
|
|
273
|
+
def test_varispeed_is_reported_as_pitch_drift_in_cents():
|
|
274
274
|
reference = _voice(4)
|
|
275
275
|
checks = _character(reference, _resampled(reference, 1.1), 1.1)
|
|
276
|
-
assert checks["pitch"]["verdict"] == "info"
|
|
277
|
-
assert checks["pitch"]["varispeed"] is True
|
|
278
|
-
assert checks["pitch"]["driftCents"] == pytest.approx(1200 * np.log2(1.1), abs=15)
|
|
279
|
-
assert checks["pitch"]["expectedCents"] == pytest.approx(1200 * np.log2(1.1), abs=0.2)
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
def test_a_slow_down_that_moves_the_pitch_is_also_a_plain_speed_change():
|
|
283
|
-
reference = _voice(4)
|
|
284
|
-
checks = _character(reference, _resampled(reference, 0.92), 0.92)
|
|
285
|
-
assert checks["pitch"]["verdict"] == "info"
|
|
286
|
-
assert checks["pitch"]["driftCents"] < -100
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
def test_a_pitch_error_the_speed_change_does_not_explain_still_warns_after_a_speed_change():
|
|
290
|
-
reference = _voice(4)
|
|
291
|
-
off = _resampled(_voice(4, pitch_scale=2 ** (1.0 / 12)), 1.1) # a semitone further up than the speed alone
|
|
292
|
-
checks = _character(reference, off, 1.1)
|
|
293
276
|
assert checks["pitch"]["verdict"] == "warn"
|
|
294
|
-
assert
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
def test_the_tone_shift_of_a_speed_change_is_reported_not_warned():
|
|
298
|
-
reference = _voice(4)
|
|
299
|
-
checks = _character(reference, _resampled(reference, 1.25), 1.25)
|
|
300
|
-
assert checks["tone"]["distanceDb"] >= verify.TONE_WARN_DB
|
|
301
|
-
assert checks["tone"]["verdict"] == "info"
|
|
277
|
+
assert checks["pitch"]["driftCents"] == pytest.approx(1200 * np.log2(1.1), abs=15)
|
|
302
278
|
|
|
303
279
|
|
|
304
280
|
def test_a_half_semitone_error_is_found():
|
|
@@ -337,30 +313,5 @@ def test_character_checks_only_run_when_the_timing_changed(source):
|
|
|
337
313
|
|
|
338
314
|
def test_a_character_warning_makes_the_verdict_a_warning_never_a_fail():
|
|
339
315
|
reference = _voice(4)
|
|
340
|
-
|
|
341
|
-
result = verify.verify_edit(reference, off, SR, time_scale=1.1)
|
|
316
|
+
result = verify.verify_edit(reference, _resampled(reference, 1.1), SR, time_scale=1.1)
|
|
342
317
|
assert result["verdict"] == "warn"
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
def _slowed(rate):
|
|
346
|
-
return _voice(4, rate=rate)
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
def test_a_clean_big_slow_down_reports_a_shallow_dip_and_passes():
|
|
350
|
-
checks = _character(_voice(4), _slowed(0.8), 0.8)
|
|
351
|
-
assert checks["dropout"]["verdict"] == "ok"
|
|
352
|
-
assert checks["dropout"]["deepestDipDb"] < verify.DROPOUT_WARN_DB
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
def test_a_piece_of_a_slow_down_that_went_missing_is_found():
|
|
356
|
-
edited = _slowed(0.8).copy()
|
|
357
|
-
mid = len(edited) // 2
|
|
358
|
-
edited[mid:mid + int(0.08 * SR)] *= 0.02 # 80 ms gone while the original keeps sounding there
|
|
359
|
-
checks = _character(_voice(4), edited, 0.8)
|
|
360
|
-
assert checks["dropout"]["verdict"] == "warn"
|
|
361
|
-
assert checks["dropout"]["deepestDipDb"] >= verify.DROPOUT_WARN_DB
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
def test_mild_slow_downs_and_speed_ups_are_not_checked_for_dropouts():
|
|
365
|
-
assert "dropout" not in _character(_voice(4), _slowed(0.92), 0.92)
|
|
366
|
-
assert "dropout" not in _character(_voice(4), _voice(4, rate=1.1), 1.1)
|
package/sidecar/verify.py
CHANGED
|
@@ -44,13 +44,7 @@ SILENCE = 1e-6
|
|
|
44
44
|
|
|
45
45
|
# Character checks (only when the timing changed): warn lines from the issue 81 experiment
|
|
46
46
|
PITCH_WARN_CENTS = 20.0
|
|
47
|
-
TONE_WARN_DB =
|
|
48
|
-
# A drift this close to what the speed change alone predicts is a plain speed change (varispeed), reported, not warned
|
|
49
|
-
VARISPEED_TOLERANCE_CENTS = 35.0
|
|
50
|
-
# Slow-downs below this rate stretch audible artifacts into a vocal (listening test, issue 81 follow-up: 0.80, 0.85
|
|
51
|
-
# and 0.88 had them, 0.90 and up did not). The dropout check runs only there; the line is provisional (one phrase).
|
|
52
|
-
DROPOUT_MAX_RATE = 0.9
|
|
53
|
-
DROPOUT_WARN_DB = 12.0
|
|
47
|
+
TONE_WARN_DB = 0.7
|
|
54
48
|
TRANSIENT_WARN_LOG = -0.25
|
|
55
49
|
MIN_VOICED_FRAMES = 12
|
|
56
50
|
MIN_VOICED_SHARE = 0.25
|
|
@@ -257,14 +251,11 @@ def pitch_drift(reference: np.ndarray, edited: np.ndarray, sample_rate: int, rat
|
|
|
257
251
|
return {"verdict": "skipped", "reason": "too few voiced frames in both to compare"}
|
|
258
252
|
cents = 1200.0 * np.log2(edit_f0[both] / ref_f0[index][both])
|
|
259
253
|
drift = float(np.median(cents))
|
|
260
|
-
expected = 1200.0 * np.log2(rate) # what a plain speed change (pitch follows the speed) would do
|
|
261
|
-
varispeed = abs(expected) >= PITCH_WARN_CENTS and abs(drift - expected) <= VARISPEED_TOLERANCE_CENTS
|
|
262
254
|
return {
|
|
263
|
-
"verdict": "
|
|
255
|
+
"verdict": "warn" if abs(drift) >= PITCH_WARN_CENTS else "ok",
|
|
264
256
|
"driftCents": round(drift, 1),
|
|
265
257
|
"referenceHz": round(centre, 1),
|
|
266
258
|
"framesCompared": int(both.sum()),
|
|
267
|
-
**({"varispeed": True, "expectedCents": round(expected, 1)} if varispeed else {}),
|
|
268
259
|
}
|
|
269
260
|
|
|
270
261
|
|
|
@@ -288,19 +279,11 @@ def _long_term_bands(x: np.ndarray, sample_rate: int) -> np.ndarray:
|
|
|
288
279
|
return levels[frame_level > frame_level.max() - 40.0].mean(axis=0)
|
|
289
280
|
|
|
290
281
|
|
|
291
|
-
def tone_difference(reference: np.ndarray, edited: np.ndarray, sample_rate: int
|
|
292
|
-
"""
|
|
293
|
-
Rms dB difference of the long-term spectrum, overall gain removed. After a plain speed change the whole
|
|
294
|
-
spectrum moves with the pitch by design, so a distance over the line is reported, not warned.
|
|
295
|
-
"""
|
|
282
|
+
def tone_difference(reference: np.ndarray, edited: np.ndarray, sample_rate: int) -> dict[str, Any]:
|
|
283
|
+
"""Rms dB difference of the long-term spectrum, overall gain removed."""
|
|
296
284
|
delta = _long_term_bands(reference, sample_rate) - _long_term_bands(edited, sample_rate)
|
|
297
285
|
distance = float(np.sqrt(np.mean((delta - delta.mean()) ** 2)))
|
|
298
|
-
|
|
299
|
-
return {
|
|
300
|
-
"verdict": ("info" if varispeed else "warn") if over else "ok",
|
|
301
|
-
"distanceDb": round(distance, 2),
|
|
302
|
-
**({"reason": "the spectrum moves with the pitch after a plain speed change"} if over and varispeed else {}),
|
|
303
|
-
}
|
|
286
|
+
return {"verdict": "warn" if distance >= TONE_WARN_DB else "ok", "distanceDb": round(distance, 2)}
|
|
304
287
|
|
|
305
288
|
|
|
306
289
|
def _flux_peakiness(x: np.ndarray) -> float:
|
|
@@ -316,39 +299,6 @@ def transient_change(reference: np.ndarray, edited: np.ndarray) -> dict[str, Any
|
|
|
316
299
|
return {"verdict": "warn" if ratio <= TRANSIENT_WARN_LOG else "ok", "fluxLogRatio": round(ratio, 3)}
|
|
317
300
|
|
|
318
301
|
|
|
319
|
-
def _envelope_db(x: np.ndarray, sample_rate: int, window: float = 0.03, hop: float = 0.01) -> np.ndarray:
|
|
320
|
-
w, h = int(window * sample_rate), int(hop * sample_rate)
|
|
321
|
-
frames = (len(x) - w) // h
|
|
322
|
-
return 10.0 * np.log10(np.array([np.mean(x[i * h:i * h + w] ** 2) for i in range(frames)]) + 1e-12)
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
def slowdown_dropout(reference: np.ndarray, edited: np.ndarray, sample_rate: int, rate: float) -> dict[str, Any]:
|
|
326
|
-
"""
|
|
327
|
-
Where does the edit go quiet while the reference, warped through the speed change, does not? A big slow-down
|
|
328
|
-
can drop or smear a piece of the signal: the loudness (30 ms frames, level matched, small lag searched)
|
|
329
|
-
falls far below the reference at one spot. Reports the deepest dip in dB; only slow-downs below
|
|
330
|
-
DROPOUT_MAX_RATE are checked. Unvalidated beyond one vocal phrase, and a steep onset moved a few ms also dips.
|
|
331
|
-
"""
|
|
332
|
-
hop = 0.01
|
|
333
|
-
ref_env, edit_env = _envelope_db(reference, sample_rate, hop=hop), _envelope_db(edited, sample_rate, hop=hop)
|
|
334
|
-
if len(ref_env) < 10 or len(edit_env) < 10:
|
|
335
|
-
return {"verdict": "skipped", "reason": "too short for a loudness comparison"}
|
|
336
|
-
best: tuple[float, np.ndarray] | None = None
|
|
337
|
-
for lag in np.arange(-0.03, 0.0301, hop):
|
|
338
|
-
positions = ((np.arange(len(edit_env)) * hop * rate + lag) / hop).clip(0, len(ref_env) - 1)
|
|
339
|
-
warped = np.interp(positions, np.arange(len(ref_env)), ref_env)
|
|
340
|
-
active = warped > warped.max() - 30.0
|
|
341
|
-
if active.sum() < 10:
|
|
342
|
-
return {"verdict": "skipped", "reason": "too quiet for a loudness comparison"}
|
|
343
|
-
diff = (edit_env - warped)[active]
|
|
344
|
-
diff = diff - np.median(diff)
|
|
345
|
-
score = float(np.sqrt(np.mean(diff ** 2)))
|
|
346
|
-
if best is None or score < best[0]:
|
|
347
|
-
best = (score, diff)
|
|
348
|
-
dip = float(-best[1].min())
|
|
349
|
-
return {"verdict": "warn" if dip >= DROPOUT_WARN_DB else "ok", "deepestDipDb": round(dip, 1)}
|
|
350
|
-
|
|
351
|
-
|
|
352
302
|
def _click_verdict(edit_score: float | None, ref_score: float | None) -> str:
|
|
353
303
|
if edit_score is None:
|
|
354
304
|
return "unknown"
|
|
@@ -405,10 +355,8 @@ def verify_edit(reference: np.ndarray, edited: np.ndarray, sample_rate: int, *,
|
|
|
405
355
|
checks["null"] = {"verdict": "skipped", "reason": "timing changed (timeScale != 1): a waveform null needs the same timing"}
|
|
406
356
|
ref_mono, edit_mono = _mono(reference), _mono(edited)
|
|
407
357
|
checks["pitch"] = pitch_drift(ref_mono, edit_mono, sample_rate, time_scale)
|
|
408
|
-
checks["tone"] = tone_difference(ref_mono, edit_mono, sample_rate
|
|
358
|
+
checks["tone"] = tone_difference(ref_mono, edit_mono, sample_rate)
|
|
409
359
|
checks["transients"] = transient_change(ref_mono, edit_mono)
|
|
410
|
-
if time_scale < DROPOUT_MAX_RATE:
|
|
411
|
-
checks["dropout"] = slowdown_dropout(ref_mono, edit_mono, sample_rate, time_scale)
|
|
412
360
|
else:
|
|
413
361
|
null = compensated_null(reference, edited, sample_rate, max_lag_ms)
|
|
414
362
|
if "error" in null:
|