Repository navigation
feat(audio): DTS:X keeps its heights, rendered to APAC - #755
superuser404notfound merged 6 commits into
Conversation
First stage of DTS:X with heights. LibDTSX (the `dca` crate behind a C API, prebuilt like LibTrueHD) decodes DTS:X on lossless DTS-HD Master Audio and does the DTS-specific work itself: it subtracts every height and object the encoder folded into the compatible 7.1 bed, and places DTS:X's angular object positions in LibTrueHD's room coordinates. Its API has LibTrueHD's shape and speaker codes, so DTSXObjectAudioDecoder is a speaker mapping next to TrueHDObjectAudioDecoder and the renderer is unchanged. Nothing is wired into playback yet. `verdict(feeding:)` answers on a stream's head whether it is DTS:X the library renders: FFmpeg names only two of DTS:X's markers, so its label cannot decide.
With LoadOptions.objectAudioRendering = .apac(layout), a 48 kHz DTS-HD Master Audio track now goes through SpatialAudioBridge on DTSXObjectAudioDecoder, the same renderer, limiter and APAC encoder TrueHD Atmos uses, instead of the channel bridge, which carried DTS:X's compatible 7.1 with the heights folded into the floor. FFmpeg labels some DTS:X plain DTS-HD MA (a D4 trailer with five moving objects), so every DTS-HD MA track is a candidate, and LibDTSX decides on its first three frames before the bridge is built. They are read through Demuxer.peekPackets, which holds them for the producer: no extra read, no seek. A refusal keeps audioBridgeMode with its lossless 7.1; lossy DTS is never offered. The decoder handle that gave the verdict is reset and handed to the bridge. Verified on macOS 27 with the sample tests: the DTS:X Object Emulator renders every bed and height channel bit for bit onto its own speaker and bridges to contiguous APAC; the D4 trailer's objects ramp across 1002 updates; FATE's plain master_audio_7.1_24bit.dts is refused. On an Apple TV 4K (tvOS 27.2) over Jellyfin, 8 Mile, The Bourne Identity and Independence Day (7.1.4+2) played as APAC with the receiver showing Atmos, through seeks; Arrival (plain DTS-HD MA) was refused on its first frame and showed PCM.
With objectAudioRendering on, a track FFmpeg labels DTS:X (or DTS:X IMAX) keeps its heights the way TrueHD Atmos does, so the automatic audio pick prefers it the same way: within the preferred language, or in place of the default track within that track's language, never a commentary, never over an override. `prefersTrueHDAtmos` becomes `prefersObjectAudio`. TrackInfo.codec is the decoder's name, which for DTS is `dca`, not `dts`. Independence Day flags no audio track as default and the probe's best stream is an AC-3 commentary; matching on `dts` left that commentary playing on the Apple TV. The test now builds its tracks the way the probe reports them.
README names DTS:X next to TrueHD Atmos in the Atmos row and the comparison table, and the license section gets a LibDTSX paragraph: Apache-2.0 for the wrapper and for the dca crate it compiles in. formats.md describes the route: what LibDTSX does to the bed and to object positions, which tracks are offered and why FFmpeg's label is not enough, the frames that prime the decoder after a seek, the placement against SpatialAudioBridge's renderer, and the receiver.
The automatic pick ranked TrueHD Atmos, and now DTS:X, ahead of the default track whenever objectAudioRendering was on, but the route itself refuses below OS 26, where the APAC encoder API is missing. There a host that sets the option on every OS it supports had its default track replaced for a channel bridge it would have got anyway. The preference now also needs ObjectAudioRendering.isAvailable.
Now that kristofferR/LibDTSX is public, Package.resolved carries its 1.0.0 pin and a clean checkout resolves. The DTS:X sample, mapping, routing and preference tests pass against the published xcframework.
|
Btw, I'll gladly transfer LibDTSX to you like with LibTrueHD! I don't need to manage two different libs that does the same thing 😛 |
|
Thanks a lot, this is great work, and the measurements against SpatialAudioBridge make it easy to trust. Yes please on the transfer, same as LibTrueHD: transfer One thing I'll fix on that side before merging: On the engine side I'll rebase this onto main (the conflicts are only CHANGELOG / Package.swift / Package.resolved, but #741 renamed |
|
I reviewed this at New: repeated damaged sections inflate the input timelineIn The resulting Deterministic reproduction: take the first complete AU of the DTS Sound Unbound Callout 11.1 sample (2184 bytes, 512 samples at 48 kHz), repeat it 500 times, replace AUs
Reproduced against the published macOS binary through its C API, the PR's Swift adapter, and the Rust source. Suggested fix: keep an independent count of successfully framed AUs for the average, leaving Suggested LibDTSX timing patchdiff --git a/src/framer.rs b/src/framer.rs
index b35faa0..20cc659 100644
--- a/src/framer.rs
+++ b/src/framer.rs
@@ -50,6 +50,8 @@ pub struct Framer {
consumed: u64,
pushed: u64,
frames: u64,
+ /// Successfully framed AUs; unlike `frames`, this excludes estimates for damaged bytes.
+ framed_count: u64,
framed_bytes: u64,
skipped: u64,
/// Bytes skipped since create() before the first frame was found (survives reset).
@@ -70,6 +72,7 @@ impl Framer {
self.consumed = 0;
self.pushed = 0;
self.frames = 0;
+ self.framed_count = 0;
self.framed_bytes = 0;
self.skipped = 0;
self.estimated = false;
@@ -215,9 +218,9 @@ impl Framer {
fn take(&mut self, len: usize, core_samples: u32) -> AuInfo {
let mut estimated_before = 0;
let skipped_before = std::mem::take(&mut self.skipped);
- if skipped_before > 0 && self.frames > 0 {
+ if skipped_before > 0 && self.framed_count > 0 {
// Damage between frames: estimate the frames it held from the average frame size.
- let average = self.framed_bytes as f64 / self.frames as f64;
+ let average = self.framed_bytes as f64 / self.framed_count as f64;
estimated_before = (skipped_before as f64 / average).round() as u64;
self.estimated |= estimated_before > 0;
}
@@ -230,6 +233,7 @@ impl Framer {
skipped_before,
};
self.frames += 1;
+ self.framed_count += 1;
self.framed_bytes += len as u64;
self.start += len;
self.consumed += len as u64;Runnable regression testSave as //! Local PR review: recovery must not manufacture extra time after repeated damage.
//! Run with DTSX_SAMPLE pointing at a standard DTS:X elementary stream.
use dtsx::{*, types::*};
use std::ptr;
#[test]
#[ignore = "requires a local DTSX_SAMPLE; repeats one complete AU to make gap duration exact"]
fn repeated_equal_sized_gaps_do_not_inflate_the_input_timeline() {
let data = std::fs::read(std::env::var_os("DTSX_SAMPLE").expect("set DTSX_SAMPLE")).unwrap();
let header = dca::parse_header(&data).unwrap();
let size = header.frame_size + dca::exss_substream_size(&data[header.frame_size..]).unwrap();
let mut stream = data[..size].repeat(500);
// Every AU is the same size: the decoder can infer exactly 50 lost AUs at each gap.
for (start, end) in [(100, 150), (250, 300)] {
stream[start * size..end * size].fill(0xA5);
}
let decoder = dtsx_decoder_create();
assert!(!decoder.is_null());
let mut end = 0;
let mut resumed = Vec::new();
for chunk in stream.chunks(4096) {
assert_eq!(unsafe { dtsx_decoder_push(decoder, chunk.as_ptr(), chunk.len(), NO_PTS) }, OK);
loop {
let mut b = Block {
sample_rate: 0, frame_count: 0, channel_count: 0, presentation: 0, flags: 0,
access_unit_frames: 0, pts: 0, pts_au_index: 0, layout_serial: 0,
sample_position: 0, input_access_unit: 0, input_frame_offset: 0,
channels: ptr::null(), speakers: ptr::null(), metadata: ptr::null(),
};
let status = unsafe { dtsx_decoder_pull(decoder, &mut b) };
if status == NEED_MORE_DATA { break; }
assert_eq!(status, OK);
end = b.input_frame_offset + u64::from(b.frame_count);
if b.flags & BLOCK_DISCONTINUITY != 0 { resumed.push(b.input_access_unit); }
}
}
unsafe { dtsx_decoder_destroy(decoder); }
assert_eq!(resumed, vec![2, 152, 302], "each gap should be followed by two priming AUs");
assert_eq!(end, 500 * 512, "recovering damage must not create additional source time");
}Sample: Demolandia DTS demos, Sound Unbound Callout 11.1, download entry. Extract the audio without transcoding, for example: ffmpeg -i /path/to/callout.mkv -map 0:a:0 -c:a copy -f dts /path/to/dtsx-callout.dts
DTSX_SAMPLE=/path/to/dtsx-callout.dts cargo +1.98.1 test --release --locked --test timeline_regressions -- --ignoredMy extracted stream's SHA-256: The test fails before the patch ( Already identified: mixed Objective-C/C++ host link failureThis confirms the maintainer's existing finding, rather than reporting a second new discovery. A host exercising both Objective-C and C++ exceptions links and runs with LibDovi 2.1.0 + already-fixed LibTrueHD 2.3.0. Adding the published DTSX binary fails with: Using fixed TrueHD isolates the additional DTSX personality from the PR's older TrueHD dependency. Suggested fix: port the -echo '_dtsx_*' >"$STAGE_DIR/exported_symbols"
+printf '%s\n' '_dtsx_*' '_rust_eh_personality' >"$STAGE_DIR/exported_symbols"
strip -S "$work/DTSX.o"
+ weaken "$work/DTSX.o" _rust_eh_personality
libtool -static -o "$work/$LIB" "$work/DTSX.o" 2>/dev/nullBoth steps are needed: merely exporting a strong definition risks duplicate symbols; keeping it local prevents coalescing. Rebuild all slices, verify a weak external Minimal mixed-host regression reproductionSave these three files together:
#include "truehd_atmos.h"
#include "dovi.h"
#ifdef WITH_DTSX
#include "dtsx.h"
#endif
int objc_exceptions(void);
int cpp_exceptions(void);
int main(void) {
TrueHDAtmosDecoder *t=truehd_atmos_decoder_create(0);
truehd_atmos_decoder_destroy(t);
dovi_rpu_free(0);
#ifdef WITH_DTSX
DTSXDecoder *d=dtsx_decoder_create();
dtsx_decoder_destroy(d);
#endif
return objc_exceptions() + cpp_exceptions() == 2 ? 0 : 1;
}
#import <Foundation/Foundation.h>
int objc_exceptions(void) {
@try { @throw [NSException exceptionWithName:@"Review" reason:@"test" userInfo:nil]; }
@catch (NSException *e) { return e != nil; }
}
extern "C" int cpp_exceptions(void) {
try { throw 1; } catch (int value) { return value; }
}Set the three paths to the macOS slice directories (TrueHD 2.3.0, Dovi 2.1.0, and DTSX 1.0.0 respectively): TRUEHD=/path/to/TrueHD.xcframework/macos-arm64_x86_64
DOVI=/path/to/Dovi.xcframework/macos-arm64_x86_64
DTSX=/path/to/DTSX.xcframework/macos-arm64_x86_64
link_host() {
clang -arch arm64 -O0 -fexceptions -fobjc-exceptions -mmacosx-version-min=15.0 \
-I"$TRUEHD/Headers/TrueHD" -I"$DOVI/Headers" -I"$DTSX/Headers/DTSX" \
mixed-host.c objc-exceptions.m cpp-exceptions.cpp \
-framework Foundation -lc++ "$TRUEHD/libtruehd_atmos.a" "$DOVI/libdovi.a" "$@"
}
link_host -o baseline && ./baseline
link_host -DWITH_DTSX "$DTSX/libdtsx.a" -o with-dtsx && ./with-dtsxBaseline exits 0; the published DTSX archive fails to link. Pointing For context, the normal sample path looked good: 44 selected engine tests passed, including our adapted independent 7.1.4 PCM comparison (maximum error 0), chunking/reset, APAC cadence, and native MKV load/reload checks. The damaged-stream regression is an additional failing case, separate from those passing tests. No physical-device playback validation is claimed here. |
|
I'll leave the fixes up to you @superuser404notfound , I've initiated the transfer now. 🙂 |
Review follow-ups on #755: - On a resume the verdict peeked the file head, and step 8's seek then dropped those packets: one wasted range read per start onto any 48 kHz DTS-HD MA track. The demuxer is now put at the first producer's start before the peek (`seekToInitialProducerStart`, step 8's seek moved into a helper), and step 8 skips its seek when that already happened, so the peeked packets are the producer's first ones. LibDTSX decides mid-stream as well (aetherctl serve --start-position 40: verdict 1 ms, audio gate gapMs=0.0; plain DTS-HD MA refused at 8 s, channel bridge opens on target). - The peek holds every stream's packets until the producer reads them, so it is capped at 24 MiB as well as 512 packets. - A stream that decodes at a rate other than 48 kHz is refused on its first block instead of failing every block in the bridge. - TFC sits on the front-top row (0.5, 0.25, 1) as in the TrueHD map since #742; LSD/RSD map to the side speakers like TrueHD's. - Docs: the angular figures were measured before #742, the 21 ms after a start or seek are skipped rather than filled with silence, the 1200-packet silence report is 12.8 s of DTS, and the OS < 26 pick change for TrueHD Atmos gets a Changed line. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WJcXkGQrMiBPixVEFTSBJS
5fe5ee9
into
superuser404notfound:main
The repository moved from kristofferR to superuser404notfound. 1.0.1 exports rust_eh_personality weak, so a host with Objective-C and C++ links next to LibDovi and LibTrueHD again (#752), and stops repeated damaged sections from pushing the input timeline ahead of the source, which delayed the audio after a second gap until a reset (found by @andreencar). Package URL, docs and changelog follow the move. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WJcXkGQrMiBPixVEFTSBJS
|
Merged in b84557c, pinned to LibDTSX 1.0.1 from its new home. Thanks @kristofferR for the library and the transfer. @andreencar, thank you for the review, the timeline bug was real and your diagnosis was exact:
|
Integrate AetherEngine 7.36.0 while preserving the existing playback corrections. Use the shared TrueHD Atmos and DTS:X setting, retain saved profile preferences, and bundle the decoder notices and independently reviewed translations. Refs superuser404notfound/AetherEngine#744 Refs superuser404notfound/AetherEngine#755 Copilot-Session: 1f0d34d4-4cfc-49cc-85b9-bf4111955fa1
Hi! This is the DTS:X patch asked for on the activator PR. It adds DTS:X to the
objectAudioRenderingroute you built for TrueHD Atmos.The problem
Apple TV can't bitstream DTS-HD either, so a DTS:X track goes through the channel bridge as its compatible 7.1. In DTS:X that 7.1 is a downmix: the encoder folds the four height channels, and any objects, into the floor channels. The heights are still audible, but from the wrong speakers.
How
Same shape as TrueHD Atmos, with the DTS-specific work kept out of the engine:
dcacrate behind a C API, shipped as a staticDTSX.xcframeworkwith the same slices, the same prelink step, a C harness and a Swift package, productDTSX.AllocentricPannerneeds no change.DTSXObjectAudioDecoderis a speaker mapping next toTrueHDObjectAudioDecoder.SpatialAudioBridge, the renderer, the limiter, the APAC encoder and the Atmos activator are unchanged.Demuxer.peekPackets, so the check costs no extra read and no seek.audioBridgeModeexactly as today.prefersTrueHDAtmosbecameprefersObjectAudio.Tested
Examples/MinimalPlayer:DTSXObjectMetadataMappingTests, andDTSXSampleTestsbehindAE_DTSX_SAMPLE,AE_DTSX_ALTERNATE_SAMPLEandAE_DTS_HD_MA_SAMPLE(FATE'sdts/master_audio_7.1_24bit.dts), likeTrueHDAtmosSampleTests. The routing and track-preference tests got DTS cases.Happy to change anything, split it up or answer questions!