#!/usr/bin/env python3 # Copyright (C) 2026 Yusuke Oda # SPDX-License-Identifier: AGPL-3.0-only """Trace the cross-effect table to its recorded confirmation jobs and source.""" from pathlib import Path import datetime import hashlib import json import math import statistics ROOT = Path(__file__).resolve().parent.parent PAGE = 'common/Effects-Decision-Matrix-2026-11-05.md' MAPPING = [ ('RV01', 'fdn8_house'), ('RV01', 'fdn16_hadamard'), ('RV04', 'integer_fixed'), ('RV04', 'integer_mod'), ('RV02', 'fft_1024_96000'), ('RV03', 'half_fft_1024_96000'), ('DM01', 'delay-fixed-linear'), ('DM01', 'delay-fixed-sinc32'), ('DM01', 'chorus2-linear'), ('DM01', 'chorus2-sinc32'), ('DM01', 'flanger-linear'), ('DM01', 'flanger-zero-linear'), ('EQPH01', 'phaser-lattice-static6'), ('EQPH01', 'phaser-lattice-lfo6'), ('EQPH01', 'eq-tdf2-tone3'), ('EQPH01', 'eq-svf-tone3'), ('DX01', 'comp.peaklog.max.bass'), ('DX01', 'comp.rmswindow.max.bass'), ('DX01', 'limit.instant.max.0.bass'), ('DX01', 'limit.box.max.5.bass'), ] def sha(path): return hashlib.sha256(path.read_bytes()).hexdigest() def evidence(path, excerpt): source = (ROOT / path).read_text() offset = source.index(excerpt) return {'path': path, 'line': source[:offset].count('\n') + 1, 'excerpt': excerpt} def conditions(family, job): """Configuration facts independently inspected in the frozen sources.""" if family == 'RV01': count = 8 if job == 'fdn8_house' else 16 return {'feedback_lines': count, 'matrix': 'Householder' if count == 8 else 'Hadamard', 'input_allpass_stages': 0, 'rt60_seconds': 2, 'damping_hz': 6000, 'evidence': [evidence('reverb/prototype/reverb.rs', 'pub struct FdnState'), evidence('reverb/prototype/reverb.rs', 'match name{'), evidence('reverb/prototype/main.rs', 'Reverb::new(name,rate,2.,6000.)')]} if family == 'RV04': return {'input_allpass_stages': 4, 'tank_branches': 2, 'allpass_stages_per_tank': 2, 'decay': 0.6, 'damping_hz': 6000, 'modulated': job == 'integer_mod', 'readout': 'Fixed taps use integer indices; each tank first allpass uses linear fractional reads when modulated.', 'evidence': [evidence('reverb/snapshots/rv04/plate.rs', 'struct PlateState'), evidence('reverb/snapshots/rv04/plate.rs', 'let y=if self.depth==0.'), evidence('reverb/snapshots/rv04/plate_main.rs', 'let mut effect=Plate::new(')]} if family in ('RV02', 'RV03'): base = 'reverb/snapshots/rv02/convolution.rs' if family == 'RV02' else 'reverb/snapshots/rv03/convolution_half.rs' return {'ir_taps': 96000, 'partition_frames': 1024, 'fft_length': 2048, 'spectrum': 'full' if family == 'RV02' else 'half', 'convolution_paths': 2, 'distinct_ir_count': 1, 'routing': 'The same mono IR is shared by independent L-to-L and R-to-R paths; no cross paths.', 'evidence': [evidence(base, 'for channel in 0..2'), evidence(base, 'pub fn new(ir:&[f64],partition:usize)')]} if family == 'DM01': refs = [evidence('delay_modulation/snapshots/DM01/main.rs', 'fn new(setting: &str, rate: f64)')] if job.startswith('delay-fixed'): return {'requested_max_delay_seconds': 2, 'allocated_ring_frames': 131072, 'delay_samples_at_48k': 18000.37, 'feedback': 0.6, 'mix': 0.5, 'interpolation': 'Sinc32' if job.endswith('sinc32') else 'Linear', 'cross_feedback': False, 'delay_note': 'The zero reported additional latency excludes the intentionally selected echo delay.', 'evidence': refs + [evidence('delay_modulation/snapshots/DM01/delay.rs', '(max_delay_samples + 34).next_power_of_two()')]} if job.startswith('chorus2'): return {'taps_total': 2, 'retained_wet_taps_per_channel': 1, 'center_ms': 20, 'depth_ms': 2, 'base_rate_hz': 0.7, 'tap_rate_multipliers': [1, 0.83], 'feedback': 0, 'mix': 0.5, 'interpolation': 'Sinc32' if job.endswith('sinc32') else 'Linear', 'evidence': refs + [evidence('delay_modulation/snapshots/DM01/modulation.rs', 'wet[i % 2] += value[i % 2]')]} zero = job == 'flanger-zero-linear' return {'taps_total': 1, 'interpolation': 'Linear', 'through_zero': zero, 'center_samples': 240 if zero else 120, 'depth_samples': 223 if zero else 96, 'rate_hz': 0.25, 'feedback': 0.7, 'mix': 0.5, 'dry_delay_samples': 240 if zero else 0, 'evidence': refs} if family == 'EQPH01': base = 'eq_phaser/snapshots/eqph01/code/' if job.startswith('phaser'): return {'method': 'normalized lattice', 'allpass_stages_per_channel': 6, 'channels': 2, 'reserved_stages_per_channel': 12, 'feedback': 0, 'mix': 0.5, 'spread_octaves': 2, 'coefficient_update_samples': 1 if job.endswith('lfo6') else 0, 'static_center_hz': 1000, 'modulated_center_range_hz': [80, 4000] if job.endswith('lfo6') else None, 'modulation_rate_hz': 0.5 if job.endswith('lfo6') else None, 'control_note': 'LFO values are prepared before timing; the lfo6 case designs coefficients every sample.', 'evidence': [evidence(base+'bench.rs', '"phaser"=>'), evidence(base+'bench.rs', 'let phaser_control:'), evidence(base+'phaser.rs', 'pub struct PhaserState')]} return {'method': 'TDF2' if 'tdf2' in job else 'SVF', 'bands_per_channel': 3, 'channels': 2, 'coefficient_update_samples': 0, 'bands': [{'kind': 'LowShelf', 'frequency_hz': 120, 'gain_db': 6, 'q': '1/sqrt(2)'}, {'kind': 'Bell', 'frequency_hz': 1200, 'gain_db': -8, 'q': 1.2}, {'kind': 'HighShelf', 'frequency_hz': 7000, 'gain_db': 4, 'q': '1/sqrt(2)'}], 'evidence': [evidence(base+'bench.rs', 'fn tone_parameters('), evidence(base+'bench.rs', '"eq"=>')]} comp = job.startswith('comp.') data = {'input': 'Bass', 'stereo_link': 'instantaneous max before detection', 'evidence': [evidence('dynamics/snapshots/initial/main.rs', 'fn signal('), evidence('dynamics/snapshots/initial/main.rs', 'fn new(')]} if comp: data.update({'method': 'Peak to dB gain-reduction AR' if 'peaklog' in job else 'rectangular RMS to dB AR', 'threshold_db': -18, 'ratio': 4, 'knee_db': 6, 'attack_ms': 10, 'release_ms': 100, 'makeup_db': 0, 'rms_window_ms': 20 if 'rmswindow' in job else None}) else: data.update({'method': 'Instant' if 'instant' in job else 'MaxBox', 'lookahead_ms': 0 if 'instant' in job else 5, 'ceiling_db': -1, 'input_gain_db': 6, 'release_ms': 100}) return data def main(): page = (ROOT / PAGE).read_text() table = page.split('| エフェクタ・具体的な構成 |', 1)[1].split('\n\n', 1)[0] rows = [[cell.strip() for cell in line.strip().strip('|').split('|')] for line in table.splitlines()[2:] if line.startswith('|')] assert len(rows) == len(MAPPING) records, issues = [], [] results = {} for index, (cells, (family, identifier)) in enumerate(zip(rows, MAPPING), 1): path = f'common/confirmation/{family}-performance.json' if family not in results: results[family] = json.loads((ROOT / path).read_text()) result = results[family] job = next(j for j in result['plan']['jobs'] if j['id'] == identifier) runs = [run['measurement'] for block in result['blocks'] for run in block['runs'] if run['job_id'] == identifier] label, displayed_mean, memory, latency, link = cells observed_mean = statistics.mean(run['ns_per_frame'] for run in runs) saved_mean = result['analysis']['summaries'][identifier]['mean'] checks = { 'family_link': family+'確認' in link, 'completed_ten_runs': result['status'] == 'complete' and len(runs) == 10, 'mean_agrees_with_raw_runs': math.isclose(observed_mean, saved_mean, rel_tol=1e-13), 'rounded_mean': displayed_mean == f'{saved_mean:.3f}', 'state_bytes_all_runs': all(run['state_bytes'] == int(memory.replace(',', '')) for run in runs), 'latency_samples_all_runs': all(run['latency_samples'] == int(latency) for run in runs), 'stereo_all_runs': all(run['channels'] == 2 for run in runs), 'common_cli': job['argv'][3:] == ['48000', '256', '4', '3000'], 'common_protocol': result['plan']['blocks'] == 10 and result['plan']['cooldown_seconds'] == 5 and result['plan']['cpu'] == 0 and result['plan']['burn_in_ms'] == 3000, } for check, passed in checks.items(): if not passed: issues.append({'row': index, 'check': check, 'label': label}) records.append({'row': index, 'label': label, 'family': family, 'job': identifier, 'source_result': path, 'source_result_sha256': sha(ROOT/path), 'job_definition': job, 'displayed_mean_ns_per_frame': displayed_mean, 'recorded_mean_ns_per_frame': saved_mean, 'raw_runs_mean_ns_per_frame': observed_mean, 'displayed_state_bytes': int(memory.replace(',', '')), 'observed_state_bytes': sorted({run['state_bytes'] for run in runs}), 'displayed_latency_samples': int(latency), 'observed_latency_samples': sorted({run['latency_samples'] for run in runs}), 'checks': checks, 'configuration_source_review': conditions(family, identifier), 'passed': all(checks.values())}) report = {'checked_utc': datetime.datetime.now(datetime.timezone.utc).isoformat(), 'source_page': PAGE, 'source_page_sha256': sha(ROOT/PAGE), 'scope': '20 recorded table rows; no DSP run or new timing. Raw recorded means, rounded display, all ten state/latency observations, and frozen-source configuration review.', 'rows': records, 'row_count': len(records), 'all_passed': not issues, 'issues': issues, 'interpretation_notes': [ 'Convolution examples are two independent channels sharing one mono IR, rather than four distinct true-stereo paths.', 'Plate integer-tap labels describe the optimized fixed reads; the modulated first tank allpasses still use fractional interpolation.', 'Chorus 2 taps means two total tap/LFO paths, with one retained wet tap per channel.', 'Delay additional latency excludes the intentional echo delay; the ring is power-of-two padded beyond its requested two-second maximum.', 'The full-spectrum example is from RV02 and the half-spectrum example from RV03. Their settings match, but the cross-row ratio is not a new within-family paired comparison.', ]} (ROOT/'common/decision-matrix-audit.json').write_text(json.dumps(report, ensure_ascii=False, indent=2)+'\n') print(json.dumps({'rows': len(records), 'all_passed': not issues, 'issues': issues})) if issues: raise SystemExit(1) if __name__ == '__main__': main()