# 出力形式と短音の遅延を調べる実験 2026-10-17 のピッチ品質改善に伴う独立実験を保存した。アプリの実装全体や報告者の音源を使うテストではない。ソースは `.build/pitch-limiter-audit` と作業中の `AudioProcessingQuality.swift` からコピーした。媒体ファイルや実行バイナリは含めない。 | ファイル | 内容 | | --- | --- | | `AudioProcessingQuality.swift` | overlap 32、PeakLimiter、outputFormat に基づく接続の実装スナップショット | | `AudioProcessingQuality-input-format.swift` | 比較用の inputFormat 接続を行う旧試作 | | `FormatProbe.swift` | 手動レンダリングと実時間エンジンの接続前後で input/output/post-gain の形式を表示 | | `EdgeImpulseProbe.swift` | 48 kHz、64/4800 フレーム、先頭 0.1/末尾 −0.08 のインパルスをレンダリング。TimePitch の bypass あり/なしを比較 | | `format-results.txt` | outputFormat で接続したときの形式の実測 | | `edge-input-format-results.txt` | inputFormat を使う旧試作の出力位置と値 | | `edge-output-format-results.txt` | outputFormat を使う試作の出力位置と値 | 実験時の環境は macOS 27.0.1、Xcode 27.0、Swift 6、arm64。Audio Unit を生成できる環境で実行した。記録中のオブジェクトのアドレスは実行ごとに変わる。`FormatProbe` の実時間側は実際の出力デバイスの形式を読むため、再実行時のサンプルレートは環境によって異なる。音源は予約せず、音楽を再生する実験ではない。 保存した `EdgeImpulseProbe.swift` は 64/4800 フレーム、`scheduleFile` の後に 9600 フレームのゼロ PCM を予約し、最大 4096 フレームずつレンダリングする。2026-10-17 に保存済みソースを再コンパイルして inputFormat/outputFormat の各 4 条件を実行し、出力中のオブジェクトアドレスだけを正規化すると、保存済みの両結果ファイルと全文が一致した。Audio Unit を生成できないサンドボックスで発生した `comp != nullptr` の例外は測定結果に含めず、Audio Unit を利用できる環境で再実行した。 Wiki を clone したディレクトリで、次を実行する。各回の結果と生成音声は新しい一時ディレクトリに保存する。 ```bash set -euo pipefail probe_dir="$(pwd)/benchmarks/pitch-protection-2026-10-17" run_dir="$(mktemp -d /tmp/smp-pitch-protection-XXXXXX)" mkdir -p "$run_dir/.build/pitch-limiter-audit" cp "$probe_dir/FormatProbe.swift" "$run_dir/main.swift" xcrun --sdk macosx swiftc -O -swift-version 6 \ -module-cache-path "$run_dir/module-cache" \ "$probe_dir/AudioProcessingQuality.swift" "$run_dir/main.swift" \ -o "$run_dir/format-probe" > "$run_dir/format-compile.log" 2>&1 "$run_dir/format-probe" > "$run_dir/format-results.txt" 2> "$run_dir/format-runtime.log" cp "$probe_dir/EdgeImpulseProbe.swift" "$run_dir/main.swift" for mode in input-format output-format; do if [ "$mode" = input-format ]; then quality_source="$probe_dir/AudioProcessingQuality-input-format.swift" else quality_source="$probe_dir/AudioProcessingQuality.swift" fi xcrun --sdk macosx swiftc -O -swift-version 6 \ -module-cache-path "$run_dir/module-cache" \ "$quality_source" "$run_dir/main.swift" \ -o "$run_dir/edge-$mode" > "$run_dir/edge-$mode-compile.log" 2>&1 ( cd "$run_dir" "./edge-$mode" > "edge-$mode-results.txt" 2> "edge-$mode-runtime.log" ) done printf 'Results: %s\n' "$run_dir" ``` `EdgeImpulseProbe` は診断用の CAF と float32 音声も `.build/pitch-limiter-audit` に生成するが、Wiki へ追加する必要はない。`edge-*-results.txt` のフレーム番号は先頭遅延を除去する前の値である。正常な形式の試作では先頭/末尾が 96/159 または 96/4895 となった。TimePitch をバイパスしたときの値は 0.1/−0.08 だった。これらをアプリ側の最終書き出しと混同しない。アプリは先頭 96 フレーム相当を除去し、元の期待長で保存する。 アプリ側の検証はリポジトリの `PitchProcessingTests` と `AudioEngineConfigurationRecoveryTests` を使う。前者はピーク、サンプルレート変換、WAV の再読み込み、短音の両端、速度変更後の長さ、キャンセルを扱う。後者は通知と再生要求の順序を制御し、停止要求後の一時的な再生や二重予約を確認する。最終結果は Wiki の「ピッチ品質改善と出力ピーク保護の実装」に記録する。