diff --git a/README.en.md b/README.en.md index d386c00..870cd33 100644 --- a/README.en.md +++ b/README.en.md @@ -15,7 +15,9 @@ This is research code, not a complete, standards-compliant, or production-grade - Parse ID11 OAMD position updates and build object trajectories. - Reconstruct LFE plus 15 object channels through analysis QMF, parameter interpolation, the object matrix, and inverse QMF. - Write a 25-channel ADM BWF: a 10-channel 7.1.2 bed (silent except for LFE) plus 15 objects. -- Render directly to `2.0`, `3.1`, `5.1`, `7.1`, `5.1.2`, `5.1.4`, `7.1.2`, `7.1.4`, `9.1.4`, or `9.1.6`. +- Render directly to `2.0`, `3.1`, `4.0 Surround`, `4.0 Quad`, `5.1`, `7.1`, `5.1.2`, `5.1.4`, + `7.1.2`, `7.1.4`, `9.1.4`, or `9.1.6` (the two 4.0 layouts are different speaker sets: Surround is a + front trio plus a back centre, Quad is a front and a back pair). - Run public SOFA binaural rendering directly from `pcm16 + ID11/OAMD`, without a temporary ADM BWF. - Keep the binaural DSP in float64/complex128, including 961-sample latency compensation, cross-frame state, and the room tail. - Use a shared float32/PCM24 WAV writer and explicit PCM24 clipping policy for direct outputs. diff --git a/README.md b/README.md index 7caf17c..0848301 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,8 @@ - 解析 ID11 OAMD 位置更新并生成对象轨迹; - 通过 analysis QMF、参数插值、对象矩阵和 inverse QMF 重建 LFE + 15 路对象 PCM; - 输出 25 声道 ADM BWF:10 声道 7.1.2 bed(除 LFE 外静音)+ 15 个对象; -- 直接渲染 `2.0`、`3.1`、`5.1`、`7.1`、`5.1.2`、`5.1.4`、`7.1.2`、`7.1.4`、`9.1.4`、`9.1.6`; +- 直接渲染 `2.0`、`3.1`、`4.0 Surround`、`4.0 Quad`、`5.1`、`7.1`、`5.1.2`、`5.1.4`、`7.1.2`、 + `7.1.4`、`9.1.4`、`9.1.6`(两种 4.0 是不同的扬声器集合:Surround 是前置三声道加后中,Quad 是前后各一对); - 从 `pcm16 + ID11/OAMD` 直接运行公开 SOFA 双耳渲染,不生成临时 ADM BWF; - 双耳 DSP 全程使用 float64/complex128,并保留 961-sample latency compensation、跨帧状态和 room 尾声; - 直接输出统一支持 float32 或 PCM24 WAV,并在 PCM24 削波前提供明确处理策略; diff --git a/docs/math.en.md b/docs/math.en.md index b643f2a..29ba5b8 100644 --- a/docs/math.en.md +++ b/docs/math.en.md @@ -438,7 +438,9 @@ $$ \mathbf h(u)\odot\mathbf v(v). $$ -For 5.1-family layouts with one horizontal surround pair rather than separate side and rear pairs, the longitudinal coordinate is +For layouts with one horizontal surround pair rather than separate side and rear pairs (the 5.1 +family, and layouts such as 4.0 Quad and 4.0 Surround that carry one rear pair only), the +longitudinal coordinate is $$ v_{\mathrm{floor}}= diff --git a/docs/math.md b/docs/math.md index 7450451..fc9a2ec 100644 --- a/docs/math.md +++ b/docs/math.md @@ -435,7 +435,8 @@ $$ \mathbf h(u)\odot\mathbf v(v). $$ -对于只有一对水平环绕、没有独立 side/rear 两对的 5.1 系列布局,纵向坐标使用 +对于只有一对水平环绕、没有独立 side/rear 两对的布局(5.1 系列,以及 4.0 Quad 与 +4.0 Surround 这类只有一对后置声道的布局),纵向坐标使用 $$ v_{\mathrm{floor}}= diff --git a/main.py b/main.py index 02c920d..b0bbc71 100644 --- a/main.py +++ b/main.py @@ -517,6 +517,16 @@ def render(index, bed_path, frame_count, raw_path, gain, progress_every, return dsp_seconds, backend_info, breakdown +def _layout_choice(value: str) -> str: + """Canonical layout name for a --speaker-layout value. + + Legacy spellings resolve here rather than being listed as choices, so "4.0" + still means the layout that name has always meant while the help text shows + the two 4.0 layouts by their own names. + """ + return speaker_layout_display_name(get_speaker_layout(value)) + + def build_parser(): parser = argparse.ArgumentParser( description=("JustOneCacophony (JOC):E-AC-3 JOC → 25ch ADM BWF、" @@ -528,8 +538,9 @@ def build_parser(): parser.add_argument("--binaural-output", type=Path, help="双耳 WAV 路径;仅与 --binaural 一起使用") direct_mode = parser.add_mutually_exclusive_group() - direct_mode.add_argument("--speaker-layout", choices=SPEAKER_LAYOUT_CHOICES, - help="直接扬声器渲染布局,例如 2.0、5.1、7.1.2") + direct_mode.add_argument("--speaker-layout", type=_layout_choice, + choices=SPEAKER_LAYOUT_CHOICES, + help="直接扬声器渲染布局,例如 2.0、4.0 Quad、5.1、7.1.2") direct_mode.add_argument("--binaural", action="store_true", help="直接 SOFA 双耳渲染;不生成临时 ADM BWF") parser.add_argument("--speaker-format", choices=("float32", "int24"), default="float32", diff --git a/src/speaker_layouts.py b/src/speaker_layouts.py index fa6e236..63e26fd 100644 --- a/src/speaker_layouts.py +++ b/src/speaker_layouts.py @@ -109,6 +109,84 @@ _RAW_LAYOUTS = {'20': {'out_ch_config': 0, 'axis0_groups': ((0, 2, 1),), 'axis1_groups': (), 'mode': 1})}, + '40surround': {'out_ch_config': 255, + 'speaker_bitfield': 35, + 'channels': ('L', 'R', 'C', 'Cs'), + 'internal_to_standard': (0, 1, 2, 3), + 'regions': ({'coordinates_q15': ((0, 0, 0), (32767, 0, 0), (16384, 0, 0), (16384, 32767, 0)), + 'speaker_ids': (0, 1, 2, 3), + 'axis0_groups': ((0, 2, 1), (3,)), + 'axis1_groups': (), + 'mode': 2}, + {'coordinates_q15': ((0, 0, 0), (32767, 0, 0), (16384, 0, 0)), + 'speaker_ids': (0, 1, 2), + 'axis0_groups': ((0, 2, 1),), + 'axis1_groups': (), + 'mode': 1}, + {'coordinates_q15': ((0, 0, 0), (32767, 0, 0), (16384, 0, 0), (16384, 32767, 0)), + 'speaker_ids': (0, 1, 2, 3), + 'axis0_groups': ((0, 2, 1), (3,)), + 'axis1_groups': (), + 'mode': 2}, + {'coordinates_q15': ((16384, 0, 0), (16384, 32767, 0)), + 'speaker_ids': (2, 3), + 'axis0_groups': ((0,), (1,)), + 'axis1_groups': (), + 'mode': 2}, + {'coordinates_q15': ((0, 0, 0), (32767, 0, 0), (16384, 0, 0)), + 'speaker_ids': (0, 1, 2), + 'axis0_groups': ((0, 2, 1),), + 'axis1_groups': (), + 'mode': 1}, + {'coordinates_q15': ((16384, 32767, 0),), + 'speaker_ids': (3,), + 'axis0_groups': ((0,),), + 'axis1_groups': (), + 'mode': 1}, + {'coordinates_q15': ((0, 0, 0), (32767, 0, 0), (16384, 0, 0)), + 'speaker_ids': (0, 1, 2), + 'axis0_groups': ((0, 2, 1),), + 'axis1_groups': (), + 'mode': 1})}, + '40quad': {'out_ch_config': 255, + 'speaker_bitfield': 9, + 'channels': ('L', 'R', 'Lrs', 'Rrs'), + 'internal_to_standard': (0, 1, 2, 3), + 'regions': ({'coordinates_q15': ((0, 0, 0), (32767, 0, 0), (0, 32767, 0), (32767, 32767, 0)), + 'speaker_ids': (0, 1, 2, 3), + 'axis0_groups': ((0, 1), (2, 3)), + 'axis1_groups': (), + 'mode': 2}, + {'coordinates_q15': ((0, 0, 0), (32767, 0, 0), (0, 32767, 0), (32767, 32767, 0)), + 'speaker_ids': (0, 1, 2, 3), + 'axis0_groups': ((0, 1), (2, 3)), + 'axis1_groups': (), + 'mode': 2}, + {'coordinates_q15': ((0, 0, 0), (32767, 0, 0), (0, 32767, 0), (32767, 32767, 0)), + 'speaker_ids': (0, 1, 2, 3), + 'axis0_groups': ((0, 1), (2, 3)), + 'axis1_groups': (), + 'mode': 2}, + {'coordinates_q15': ((0, 32767, 0), (32767, 32767, 0)), + 'speaker_ids': (2, 3), + 'axis0_groups': ((0, 1),), + 'axis1_groups': (), + 'mode': 1}, + {'coordinates_q15': ((0, 0, 0), (32767, 0, 0)), + 'speaker_ids': (0, 1), + 'axis0_groups': ((0, 1),), + 'axis1_groups': (), + 'mode': 1}, + {'coordinates_q15': ((0, 32767, 0), (32767, 32767, 0)), + 'speaker_ids': (2, 3), + 'axis0_groups': ((0, 1),), + 'axis1_groups': (), + 'mode': 1}, + {'coordinates_q15': ((0, 0, 0), (32767, 0, 0)), + 'speaker_ids': (0, 1), + 'axis0_groups': ((0, 1),), + 'axis1_groups': (), + 'mode': 1})}, '51': {'out_ch_config': 7, 'speaker_bitfield': 15, 'channels': ('L', 'R', 'C', 'LFE', 'Ls', 'Rs'), @@ -738,6 +816,8 @@ SPEAKER_LAYOUTS = {name: _make_layout(name, item) for name, item in _RAW_LAYOUTS SPEAKER_LAYOUT_ALIASES = { "2.0": "20", "3.1": "31", + "4.0 Surround": "40surround", + "4.0 Quad": "40quad", "5.1": "51", "7.1": "71", "5.1.2": "512", @@ -747,12 +827,18 @@ SPEAKER_LAYOUT_ALIASES = { "9.1.4": "914", "9.1.6": "916", } +# Spellings accepted for compatibility only: "4.0" has always meant the layout +# with a front trio and one back-centre speaker, which is now called 4.0 Surround. +SPEAKER_LAYOUT_LEGACY_ALIASES = { + "4.0": "40surround", +} SPEAKER_LAYOUT_CHOICES = tuple(SPEAKER_LAYOUT_ALIASES) SPEAKER_LAYOUT_DISPLAY_NAMES = {value: key for key, value in SPEAKER_LAYOUT_ALIASES.items()} def get_speaker_layout(name: str) -> SpeakerLayout: key = SPEAKER_LAYOUT_ALIASES.get(name, name) + key = SPEAKER_LAYOUT_LEGACY_ALIASES.get(key, key) try: return SPEAKER_LAYOUTS[key] except KeyError as exc: