Skip to content

Commit

Permalink
Audio data format is now described by AudioFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeugma440 committed Nov 2, 2024
1 parent 02e37d8 commit 0930ad3
Show file tree
Hide file tree
Showing 45 changed files with 472 additions and 384 deletions.
9 changes: 2 additions & 7 deletions ATL.benchmark/Information/FileFinder.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
using System;
using System.IO;
using System.Collections.Generic;
using Commons;
using System.Threading;
using System.Threading.Tasks;
using Commons;

namespace ATL.benchmark
{
public class FileFinder
{
static ICollection<Format> supportedFormats;
static ICollection<AudioFormat> supportedFormats;

static FileFinder()
{
Expand Down
10 changes: 9 additions & 1 deletion ATL.benchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Diagnostics.Metrics;
using System.IO;
using ATL.Playlist;
using ATL.AudioData;

namespace ATL.benchmark
{
Expand All @@ -27,7 +28,7 @@ static void Main(string[] args)

//browseFor(@"E:\Music\", "*.mp3");

info(@"D:\temp\mka\recording.webm");
info(@"D:\temp\caf\sound.caf");

//info(@"D:\temp\wav\74\empty_tagged_audacity.wav");

Expand Down Expand Up @@ -130,13 +131,20 @@ static private void reduce(string filePath)
new Reduce().reduce(filePath);
}

enum MetadataSpecification
{
Mp4, Aiff, Vorbis, Id3V1, Id3V23, Id3V24, Ape, Wma, Undefined
}

static private void info(string filePath)
{
new ConsoleLogger();
Console.WriteLine(">>> INFO : BEGIN @ " + filePath);

Track t = new Track(filePath);

Console.WriteLine(t.AudioFormat.ID);

Console.WriteLine(t.Path + "......." + t.AudioFormat.Name + " | " + Utils.EncodeTimecode_s(t.Duration) + " | " + t.SampleRate + " (" + t.Bitrate + " kpbs" + (t.IsVBR ? " VBR)" : ")" + " " + t.ChannelsArrangement));
Console.WriteLine(Utils.BuildStrictLengthString("", t.Path.Length, '.') + ".......disc " + t.DiscNumber + " | track " + t.TrackNumber + " | title " + t.Title + " | artist " + t.Artist + " | album " + t.Album + " | year " + t.Year);

Expand Down
183 changes: 101 additions & 82 deletions ATL.unit-test/IO/AudioData/AudioData.cs

Large diffs are not rendered by default.

152 changes: 76 additions & 76 deletions ATL/AudioData/AudioDataIOFactory.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ATL/AudioData/AudioFileIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ private ISet<TagType> getMetasToRemove(TagType tagType)
/// </summary>
public int IntBitRate => (int)Math.Round(audioData.BitRate);
/// <inheritdoc/>
public Format AudioFormat => audioData.AudioFormat;
public AudioFormat AudioFormat => audioData.AudioFormat;
/// <inheritdoc/>
public int CodecFamily => audioData.CodecFamily;
/// <inheritdoc/>
Expand Down
8 changes: 4 additions & 4 deletions ATL/AudioData/IO/AA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ partial class AA : MetaDataIO, IAudioDataIO
private long tocOffset;
private long tocSize;

private readonly Format audioFormat;
private readonly AudioFormat audioFormat;

private IDictionary<int, TocEntry> toc;

Expand Down Expand Up @@ -89,11 +89,11 @@ public override string ToString()
/// <inheritdoc/>
public bool IsVBR => false;
/// <inheritdoc/>
public Format AudioFormat
public AudioFormat AudioFormat
{
get
{
Format f = new Format(audioFormat);
AudioFormat f = new AudioFormat(audioFormat);
if (codec.Length > 0)
f.Name = f.Name + " (" + codec + ")";
else
Expand Down Expand Up @@ -194,7 +194,7 @@ protected void resetData()
AudioDataSize = 0;
}

public AA(string fileName, Format format)
public AA(string fileName, AudioFormat format)
{
this.FileName = fileName;
audioFormat = format;
Expand Down
4 changes: 2 additions & 2 deletions ATL/AudioData/IO/AAC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class AAC : IAudioDataIO
public bool IsVBR => AAC_BITRATE_TYPE_VBR == bitrateTypeID;

/// <inheritdoc/>
public Format AudioFormat
public AudioFormat AudioFormat
{
get;
}
Expand Down Expand Up @@ -115,7 +115,7 @@ protected void resetData()
AudioDataSize = 0;
}

public AAC(string fileName, Format format)
public AAC(string fileName, AudioFormat format)
{
this.FileName = fileName;
AudioFormat = format;
Expand Down
7 changes: 2 additions & 5 deletions ATL/AudioData/IO/AC3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ class AC3 : IAudioDataIO
/// <inheritdoc/>
public bool IsVBR => false;
/// <inheritdoc/>
public Format AudioFormat
{
get;
}
public AudioFormat AudioFormat { get; }
/// <inheritdoc/>
public int CodecFamily => AudioDataIOFactory.CF_LOSSY;
/// <inheritdoc/>
Expand Down Expand Up @@ -65,7 +62,7 @@ protected void resetData()
AudioDataSize = 0;
}

public AC3(string filePath, Format format)
public AC3(string filePath, AudioFormat format)
{
this.FileName = filePath;
AudioFormat = format;
Expand Down
4 changes: 2 additions & 2 deletions ATL/AudioData/IO/AIFF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private struct ChunkHeader
// IAudioDataIO
public bool IsVBR => false;

public Format AudioFormat
public AudioFormat AudioFormat
{
get;
}
Expand Down Expand Up @@ -169,7 +169,7 @@ private void resetData()
ResetData();
}

public AIFF(string filePath, Format format)
public AIFF(string filePath, AudioFormat format)
{
this.FileName = filePath;
AudioFormat = format;
Expand Down
7 changes: 2 additions & 5 deletions ATL/AudioData/IO/Ape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,7 @@ private sealed class ApeDescriptor

public bool IsVBR => false;

public Format AudioFormat
{
get;
}
public AudioFormat AudioFormat { get; }
public int CodecFamily => AudioDataIOFactory.CF_LOSSLESS;

public string FileName { get; }
Expand Down Expand Up @@ -172,7 +169,7 @@ protected void resetData()
AudioDataSize = 0;
}

public APE(string filePath, Format format)
public APE(string filePath, AudioFormat format)
{
this.FileName = filePath;
AudioFormat = format;
Expand Down
58 changes: 29 additions & 29 deletions ATL/AudioData/IO/CAF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,21 @@ class CAF : MetaDataIO, IAudioDataIO
{ (146 << 16) | 21, TMH_10_2_FULL }
};

// Mapping between CAF format ID and format names
// Mapping between CAF format ID, ATL format ID and custom format names
private static readonly Dictionary<string, KeyValuePair<int, string>> formatsMapping = new Dictionary<string, KeyValuePair<int, string>>()
{
{ "none", new KeyValuePair<int, string>(0,"") },
{ "lpcm", new KeyValuePair<int, string>(1,"Linear PCM") },
{ "ima4", new KeyValuePair<int, string>(2,"Apple IMA 4:1 ADPCM") },
{ "aac ", new KeyValuePair<int, string>(3,"MPEG-4 AAC") },
{ "MAC3", new KeyValuePair<int, string>(4,"MACE 3:1") },
{ "MAC6", new KeyValuePair<int, string>(5,"MACE 6:1") },
{ "ulaw", new KeyValuePair<int, string>(6,"μLaw 2:1") },
{ "alaw", new KeyValuePair<int, string>(7,"aLaw 2:1") },
{ ".mp1", new KeyValuePair<int, string>(8,"MPEG-1 or 2, Layer 1") },
{ ".mp2", new KeyValuePair<int, string>(9,"MPEG-1 or 2, Layer 2") },
{ ".mp3", new KeyValuePair<int, string>(10,"MPEG-1 or 2, Layer 3") },
{ "alac", new KeyValuePair<int, string>(11,"Apple Lossless") }
{ "none", new KeyValuePair<int, string>(Format.UNKNOWN_FORMAT.ID,"") },
{ "lpcm", new KeyValuePair<int, string>(AudioDataIOFactory.CID_WAV,"Linear PCM") },
{ "ima4", new KeyValuePair<int, string>(AudioDataIOFactory.CID_WAV,"Apple IMA 4:1 ADPCM") },
{ "aac ", new KeyValuePair<int, string>(AudioDataIOFactory.CID_AAC, "MPEG-4 AAC") },
{ "MAC3", new KeyValuePair<int, string>(Format.UNKNOWN_FORMAT.ID,"MACE 3:1") }, // Macintosh Audio Compression
{ "MAC6", new KeyValuePair<int, string>(Format.UNKNOWN_FORMAT.ID, "MACE 6:1") },
{ "ulaw", new KeyValuePair<int, string>(AudioDataIOFactory.CID_WAV,"μLaw 2:1") },
{ "alaw", new KeyValuePair<int, string>(AudioDataIOFactory.CID_WAV,"aLaw 2:1") },
{ ".mp1", new KeyValuePair<int, string>(AudioDataIOFactory.CID_MPEG,"MPEG-1 or 2, Layer 1") },
{ ".mp2", new KeyValuePair<int, string>(AudioDataIOFactory.CID_MPEG,"MPEG-1 or 2, Layer 2") },
{ ".mp3", new KeyValuePair<int, string>(AudioDataIOFactory.CID_MPEG,"MPEG-1 or 2, Layer 3") },
{ "alac", new KeyValuePair<int, string>(AudioDataIOFactory.CID_MP4,"Apple Lossless") }
};

// Mapping between CAF information keys and ATL frame codes
Expand All @@ -119,8 +119,7 @@ class CAF : MetaDataIO, IAudioDataIO


// Private declarations
private Format containerAudioFormat;
private KeyValuePair<int, string> containeeAudioFormat;
private AudioFormat audioFormat;

private uint sampleRate;
private bool isVbr;
Expand All @@ -134,16 +133,8 @@ class CAF : MetaDataIO, IAudioDataIO

public bool IsVBR => isVbr;

public Format AudioFormat
{
get
{
containerAudioFormat = new Format(containerAudioFormat);
containerAudioFormat.Name += " / " + containeeAudioFormat.Value;
containerAudioFormat.ID += containeeAudioFormat.Key;
return containerAudioFormat;
}
}
public AudioFormat AudioFormat => audioFormat;

public int CodecFamily { get; private set; }

public string FileName { get; }
Expand Down Expand Up @@ -206,10 +197,10 @@ protected void resetData()
/// <summary>
/// Constructor
/// </summary>
public CAF(string filePath, Format format)
public CAF(string filePath, AudioFormat format)
{
this.FileName = filePath;
containerAudioFormat = format;
audioFormat = format;
resetData();
}

Expand Down Expand Up @@ -267,8 +258,17 @@ private void readAudioDescriptionChunk(BufferedBinaryReader source)
break;
}

// Determine format
containeeAudioFormat = formatsMapping.TryGetValue(formatId, out var value) ? value : formatsMapping["none"];
// Set audio data format
var format = formatsMapping.TryGetValue(formatId, out var value) ? value : formatsMapping["none"];
var audioDataFormat = new Format(format.Key, format.Value, format.Value, false);
audioFormat = new AudioFormat(audioFormat);
audioFormat.DataFormat = audioDataFormat;

var containerFormat = AudioDataIOFactory.GetInstance().getFormat(audioFormat.ContainerId);
if (null == containerFormat) audioFormat.Name = audioFormat.DataFormat.ShortName;
else audioFormat.Name = containerFormat.Name + " / " + audioFormat.DataFormat.ShortName;

audioFormat.ComputeId();
}

private void readChannelLayoutChunk(BufferedBinaryReader source)
Expand Down
7 changes: 2 additions & 5 deletions ATL/AudioData/IO/DSF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ class DSF : IAudioDataIO, IMetaDataEmbedder

public int SampleRate => (int)sampleRate;
public bool IsVBR => false;
public Format AudioFormat
{
get;
}
public AudioFormat AudioFormat { get; }
public int CodecFamily => AudioDataIOFactory.CF_LOSSLESS;
public string FileName { get; }

Expand Down Expand Up @@ -83,7 +80,7 @@ protected void resetData()
/// <summary>
/// Constructor
/// </summary>
public DSF(string filePath, Format format)
public DSF(string filePath, AudioFormat format)
{
this.FileName = filePath;
AudioFormat = format;
Expand Down
7 changes: 2 additions & 5 deletions ATL/AudioData/IO/DTS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ class DTS : IAudioDataIO

// ---------- INFORMATIVE INTERFACE IMPLEMENTATIONS & MANDATORY OVERRIDES

public Format AudioFormat
{
get;
}
public AudioFormat AudioFormat { get; }
public bool IsVBR => false;
public int CodecFamily => AudioDataIOFactory.CF_LOSSY;
public int SampleRate => (int)sampleRate;
Expand Down Expand Up @@ -63,7 +60,7 @@ protected void resetData()
/// <summary>
/// Constructor
/// </summary>
public DTS(string filePath, Format format)
public DTS(string filePath, AudioFormat format)
{
this.FileName = filePath;
AudioFormat = format;
Expand Down
2 changes: 1 addition & 1 deletion ATL/AudioData/IO/DummyReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public DummyReader(string filePath)
public bool IsVBR => false;

/// <inheritdoc/>
public Format AudioFormat => Factory.UNKNOWN_FORMAT;
public AudioFormat AudioFormat => new AudioFormat(Format.UNKNOWN_FORMAT);

/// <inheritdoc/>
public int CodecFamily => AudioDataIOFactory.CF_LOSSY;
Expand Down
2 changes: 1 addition & 1 deletion ATL/AudioData/IO/DummyTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected override MetaDataIOFactory.TagType getImplementedTagType()
/// <inheritdoc/>
public override IList<Format> MetadataFormats
{
get { return new List<Format>(new[] { Factory.UNKNOWN_FORMAT }); }
get { return new List<Format>(new[] { Format.UNKNOWN_FORMAT }); }
}

/// <inheritdoc/>
Expand Down
8 changes: 3 additions & 5 deletions ATL/AudioData/IO/FLAC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,8 @@ public override IList<Format> MetadataFormats
public ChannelsArrangement ChannelsArrangement { get; private set; }

/// <inheritdoc/>
public Format AudioFormat
{
get;
}
public AudioFormat AudioFormat { get; }

/// <inheritdoc/>
public int CodecFamily => AudioDataIOFactory.CF_LOSSLESS;

Expand Down Expand Up @@ -129,7 +127,7 @@ protected void resetData()
AudioDataSize = 0;
}

public FLAC(string path, Format format) : base(false, false, false, false)
public FLAC(string path, AudioFormat format) : base(false, false, false, false)
{
FileName = path;
AudioFormat = format;
Expand Down
7 changes: 2 additions & 5 deletions ATL/AudioData/IO/GYM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ class GYM : MetaDataIO, IAudioDataIO

public bool IsVBR => false;

public Format AudioFormat
{
get;
}
public AudioFormat AudioFormat { get; }
public int CodecFamily => AudioDataIOFactory.CF_SEQ_WAV;

public string FileName { get; }
Expand Down Expand Up @@ -102,7 +99,7 @@ private void resetData()
ResetData();
}

public GYM(string filePath, Format format)
public GYM(string filePath, AudioFormat format)
{
this.FileName = filePath;
AudioFormat = format;
Expand Down
7 changes: 2 additions & 5 deletions ATL/AudioData/IO/IT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ class IT : MetaDataIO, IAudioDataIO
public bool IsVBR => false;

/// <inheritdoc/>
public Format AudioFormat
{
get;
}
public AudioFormat AudioFormat { get; }
/// <inheritdoc/>
public int CodecFamily => AudioDataIOFactory.CF_SEQ_WAV;
/// <inheritdoc/>
Expand Down Expand Up @@ -111,7 +108,7 @@ protected void resetData()
ResetData();
}

public IT(string filePath, Format format)
public IT(string filePath, AudioFormat format)
{
FileName = filePath;
AudioFormat = format;
Expand Down
Loading

0 comments on commit 0930ad3

Please sign in to comment.