From 89680f7cc5d21367fe4897fe3d6e3ea470222810 Mon Sep 17 00:00:00 2001 From: VoidX Date: Tue, 26 Nov 2024 00:08:29 +0100 Subject: [PATCH] Per-subframe E-AC-3 rendering --- .../Decoders/EnhancedAC3/ObjectAudioMetadata.cs | 7 ++++--- Cavern.Format/Renderers/EnhancedAC3Renderer.cs | 11 ++++------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Cavern.Format/Decoders/EnhancedAC3/ObjectAudioMetadata.cs b/Cavern.Format/Decoders/EnhancedAC3/ObjectAudioMetadata.cs index 1b2be676..3d4c4dba 100644 --- a/Cavern.Format/Decoders/EnhancedAC3/ObjectAudioMetadata.cs +++ b/Cavern.Format/Decoders/EnhancedAC3/ObjectAudioMetadata.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Cavern.Channels; using Cavern.Format.Common; @@ -22,13 +23,13 @@ partial class ObjectAudioMetadata { /// /// Decoded object audio element metadata. /// - OAElementMD[] elements = new OAElementMD[0]; + OAElementMD[] elements = Array.Empty(); /// /// Bed channels used. The first dimension is the element ID, the second is one bit for each channel, /// in the order of . /// - bool[][] bedAssignment; + bool[][] bedAssignment = Array.Empty(); /// /// Use intermediate spatial format (ISF), which has a few fixed layouts. diff --git a/Cavern.Format/Renderers/EnhancedAC3Renderer.cs b/Cavern.Format/Renderers/EnhancedAC3Renderer.cs index e818fc32..3b016b1c 100644 --- a/Cavern.Format/Renderers/EnhancedAC3Renderer.cs +++ b/Cavern.Format/Renderers/EnhancedAC3Renderer.cs @@ -97,6 +97,7 @@ public EnhancedAC3Renderer(EnhancedAC3Decoder stream) : base(stream) { else { for (int channel = 0; channel < outputMatrix.Length; channel++) { Source source = new StreamMasterSource(reader, channel) { + LFE = inputMatrix[channel] == ReferenceChannel.ScreenLFE, Position = ChannelPrototype.AlternativePositions[(int)outputMatrix[channel]] * Listener.EnvironmentSize }; objects.Add(source); @@ -209,15 +210,11 @@ void RenderNextTimeslot() { } // Channel-based rendering or fallback to it when OAMD or JOC can't be decoded correctly else { - for (int i = 0; i < outputMatrix.Length; i++) { + for (int i = 0; i < inputMatrix.Length; i++) { + objects[i].Position = ChannelPrototype.AlternativePositions[(int)inputMatrix[i]] * Listener.EnvironmentSize; timeslotResult[i] = inputData[i]; - objects[i].Position = ChannelPrototype.AlternativePositions[(int)outputMatrix[i]] * Listener.EnvironmentSize; - if (ChannelPrototype.Mapping[(int)outputMatrix[i]].LFE) { // LFE is handled elsewhere - objects[i].Position = default; - timeslotResult[i].Clear(); - } } - for (int i = outputMatrix.Length; i < timeslotResult.Length; i++) { + for (int i = inputMatrix.Length; i < timeslotResult.Length; i++) { objects[i].Position = default; timeslotResult[i].Clear(); }