Skip to content

Commit

Permalink
Better OAMD metadata display
Browse files Browse the repository at this point in the history
  • Loading branch information
VoidXH committed Oct 13, 2023
1 parent 53ab18e commit 96c2fe2
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void Read(BitExtractor extractor, bool alternateObjectPresent, int object
if (elementIndex == objectElementIndex) {
ObjectElement(extractor, objectCount, bedOrISFObjects);
} else { // Other elements are unused by encoders
blockOffsetFactor = new short[] { -1 };
blockOffsetFactor = new short[] { (short)(-1 - elementIndex) };
}
extractor.Position = endPos; // Padding
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
using System.Collections.Generic;
using System.Linq;

using Cavern.Format.Common;

namespace Cavern.Format.Decoders.EnhancedAC3 {
partial class OAElementMD : IMetadataSupplier {
/// <inheritdoc/>
public ReadableMetadata GetMetadata() {
if (blockOffsetFactor[0] < 0) {
return new ReadableMetadata(new[] {
new ReadableMetadataHeader("Object Audio Element Metadata (Unknown Element)", new[] {
new ReadableMetadataField("oa_element_id_idx", "Type of the Object Audio Element", -1 - blockOffsetFactor[0]),
})
});
}

List<ReadableMetadataHeader> headers = new List<ReadableMetadataHeader> {
new ReadableMetadataHeader("Object Audio Element Metadata", new[] {
new ReadableMetadataHeader("Object Audio Element Metadata (Object Element)", new[] {
new ReadableMetadataField("sample_offset", "Offset from the frame beginning in samples", sampleOffset),
new ReadableMetadataField("num_obj_info_blocks", "Number of block update info blocks", blockOffsetFactor.Length)
})
};
if (infoBlocks != null) {
for (int obj = 0; obj < updateLast.Length; ++obj) {
for (int blk = 0; blk < infoBlocks[obj].Length; ++blk) {
headers.AddRange(infoBlocks[obj][blk].GetMetadata().Headers);
}

int channels = 0;
for (int obj = 0; obj < updateLast.Length; ++obj) {
for (int blk = 0; blk < infoBlocks[obj].Length; ++blk) {
ObjectInfoBlock block = infoBlocks[obj][blk];
string title = block.IsBed ?
$"Bed {++channels} Info Block {blk + 1}" :
$"Object {obj - channels + 1} Info Block {blk + 1}";
headers.AddRange(block.GetMetadata().Headers.Select(x => new ReadableMetadataHeader(title, x.Fields)));
}
}
return new ReadableMetadata(headers);
Expand Down
4 changes: 3 additions & 1 deletion Cavern.Format/Decoders/EnhancedAC3/ObjectAudioMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ partial class ObjectAudioMetadata {
/// Bed channels used. The first dimension is the element ID, the second is one bit for each channel,
/// in the order of <see cref="bedChannels"/>.
/// </summary>
bool[][] bedAssignment = new bool[0][];
bool[][] bedAssignment;

/// <summary>
/// Use intermediate spatial format (ISF), which has a few fixed layouts.
Expand Down Expand Up @@ -163,6 +163,8 @@ void ProgramAssignment(BitExtractor extractor) {
bedAssignment = new bool[1][];
bedAssignment[0] = new bool[(int)NonStandardBedChannel.Max];
bedAssignment[0][(int)NonStandardBedChannel.LowFrequencyEffects] = true;
} else {
bedAssignment = new bool[0][];
}
} else {
int contentDescription = extractor.Read(4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ partial class ObjectAudioMetadata : IMetadataSupplier {
/// Gets the metadata for this codec in a human-readable format.
/// </summary>
public ReadableMetadata GetMetadata() {
bool hasLFE = bedAssignment.Length == 1 && bedAssignment[0][(int)NonStandardBedChannel.LowFrequencyEffects];
List<ReadableMetadataHeader> headers = new List<ReadableMetadataHeader> {
new ReadableMetadataHeader("Object Audio MetaData header", new[] {
new ReadableMetadataField("object_count", "Number of rendered dynamic objects", ObjectCount),
new ReadableMetadataField("oa_element_count", "Number of Object Audio Element blocks", elements.Length)
new ReadableMetadataField("object_count", "Total number of audio objects, including static and dynamic", ObjectCount),
new ReadableMetadataField("oa_element_count", "Number of Object Audio Element blocks", elements.Length),
new ReadableMetadataField("b_dyn_object_only_program", "The program only contains dynamic objects other than the LFE",
bedAssignment.Length == 0 || hasLFE),
new ReadableMetadataField("b_lfe_present", "The LFE channel is present in an object-only program", hasLFE),
new ReadableMetadataField("num_bed_instances", "Number of bed channels or channel pairs", bedAssignment.Length),
new ReadableMetadataField("num_dynamic_objects", "Number of dynamic objects", ObjectCount - bedAssignment.Length),
})
};
for (int i = 0; i < elements.Length; i++) {
Expand Down
5 changes: 5 additions & 0 deletions Cavern.Format/Decoders/EnhancedAC3/ObjectInfoBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ partial class ObjectInfoBlock {
/// </summary>
public bool ValidPosition { get; private set; }

/// <summary>
/// This object is not dynamic, but used as a bed channel.
/// </summary>
public bool IsBed => anchor == ObjectAnchor.Speaker;

/// <summary>
/// This frame contains the difference from the last object position instead of an exact position.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace Cavern.Format.Decoders.EnhancedAC3 {
partial class ObjectInfoBlock : IMetadataSupplier {
/// <inheritdoc/>
public ReadableMetadata GetMetadata() => new ReadableMetadata(new List<ReadableMetadataHeader> {
new ReadableMetadataHeader("Object Info Block", new[] {
new ReadableMetadataField("object_gain", "Object gain", gain < 0 ? "reuse" : QMath.GainToDb(gain).ToString("0 dB")),
Expand Down

0 comments on commit 96c2fe2

Please sign in to comment.