Skip to content

Add AC3 RF audio decoding via ac3rf Python extension#1034

Merged
happycube merged 3 commits into
happycube:mainfrom
staffanu:ac3rf-decode
May 23, 2026
Merged

Add AC3 RF audio decoding via ac3rf Python extension#1034
happycube merged 3 commits into
happycube:mainfrom
staffanu:ac3rf-decode

Conversation

@staffanu
Copy link
Copy Markdown
Contributor

@staffanu staffanu commented Apr 9, 2026

LaserDisc discs containing Dolby AC3 audio encode the audio as a QPSK-modulated
signal at 2.88 MHz on the video carrier. This PR adds support for demodulating
that signal and writing the raw QPSK symbols to an .ac3sym file, analogous to
how EFM T-values are written to .efm.

  • Removes the old dead AC3 pipe code (ac3_pipe, AC3filter) which referenced
    ld-ac3-demodulate/ld-ac3-decode executables that no longer exist
  • Replaces it with AC3demodulate() using the ac3rf Python extension
    (built from ldaudio/ac3rf-decode,
    publicly readable over HTTPS)
  • When --ac3 is passed, ld-decode writes a .ac3sym file containing raw QPSK
    dibits (1 byte/symbol) and records the per-field symbol count in the .tbc DB
    as ac3_symbols
  • The Nix flake builds the ac3rf Python extension from a pinned commit of the
    ldaudio repo (which pulls in the firpm submodule via ?submodules=1);
    nanobind is pre-fetched as a flake input so the build requires no network
    access inside the Nix sandbox

The .ac3sym output is intended to be consumed by a downstream decoder to
produce a final .ac3 bitstream. The per-field symbol counts stored in the DB
allow the downstream tool to reconstruct per-field byte offsets into the file.

staffanu added 3 commits April 9, 2026 23:09
Remove ac3_pipe from utils.py (referenced sox/ld-ac3-demodulate/ld-ac3-decode
which no longer exist) and the unused bandpass filter setup in RFDecode.

Replace AC3filter with AC3demodulate, which uses the ac3rf Python extension
(built from ac3rf-decode with BUILD_PYTHON=ON) to demodulate raw ADC samples
directly into QPSK symbols. Output goes to a .ac3sym file, analogous to .efm
containing EFM T-values. Per-field symbol counts are recorded in the
field_record table (as ac3_symbols) for use by downstream decoders (decode-orc).

Overlap deduplication prevents re-processing samples shared between
consecutive fields.
Add ldaudio (contains ac3rf-decode) and nanobind-src as flake inputs.
Build ac3rf as a Python extension module (BUILD_PYTHON=ON) using CMake
with nanobind supplied via FETCHCONTENT_SOURCE_DIR so the Nix sandbox
can build without network access.

The extension is added to propagatedBuildInputs so it is automatically
on PYTHONPATH for nix run and nix develop. ldaudio is publicly readable
over HTTPS so no special access is needed.
@happycube happycube merged commit 59ea8e2 into happycube:main May 23, 2026
@happycube
Copy link
Copy Markdown
Owner

Sorry I didn't notice this for so long!

@staffanu
Copy link
Copy Markdown
Contributor Author

No problem! Glad you merged it and hope it works!

@staffanu staffanu deleted the ac3rf-decode branch May 23, 2026 05:09
simoninns pushed a commit that referenced this pull request May 24, 2026
This reverts commit 59ea8e2, reversing
changes made to 44f2528.
simoninns added a commit that referenced this pull request May 24, 2026
Revert "Merge pull request #1034 from staffanu/ac3rf-decode"
@simoninns
Copy link
Copy Markdown
Collaborator

This PR caused CI/CD failure and had to be reverted - it will need to be resubmitted against the current commit for inclusion (I put the cause in the notes of the PR to revert).

On a related note, this PR was pulling in a nix build from a remote repo (a nix submodule) which had a different nix package base (unstable rather than 25.11) - The architecture of this would be a lot better if it followed the EFM implementation and kept the demod within ld-decode's python base rather than coupling it externally.

@happycube 's call really - but I don't think the AC3 demod in a remote flake is a strong approach imho

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants