Skip to content

Commit

Permalink
New bit depth audio data property
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeugma440 committed Dec 1, 2022
1 parent 18b5127 commit 4bdece1
Show file tree
Hide file tree
Showing 35 changed files with 173 additions and 152 deletions.
128 changes: 65 additions & 63 deletions ATL.test/IO/AudioData/AudioData.cs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions ATL.test/IO/HighLevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,7 @@ public void StreamedIO_R_Audio()

Assert.AreEqual(33, theTrack.Duration);
Assert.AreEqual(69, theTrack.Bitrate);
Assert.AreEqual(-1, theTrack.BitDepth);
Assert.AreEqual(22050, theTrack.SampleRate);
Assert.AreEqual(true, theTrack.IsVBR);
Assert.AreEqual(23125, theTrack.TechnicalInformation.AudioDataOffset);
Expand Down
5 changes: 5 additions & 0 deletions ATL/AudioData/AudioFileIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ public double BitRate
get => audioData.BitRate;
}
/// <inheritdoc/>
public int BitDepth
{
get => audioData.BitDepth;
}
/// <inheritdoc/>
public int SampleRate
{
get => audioData.SampleRate;
Expand Down
3 changes: 3 additions & 0 deletions ATL/AudioData/IO/AA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ public int SampleRate
}
}
}

public int BitDepth => -1; // Irrelevant for lossy formats

public string FileName
{
get { return fileName; }
Expand Down
3 changes: 3 additions & 0 deletions ATL/AudioData/IO/AAC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ public int SampleRate
{
get { return sampleRate; }
}

public int BitDepth => -1; // Irrelevant for lossy formats

public string FileName
{
get { return fileName; }
Expand Down
3 changes: 3 additions & 0 deletions ATL/AudioData/IO/AC3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public int SampleRate
{
get { return (int)this.sampleRate; }
}

public int BitDepth => -1; // Irrelevant for lossy formats

public ChannelsArrangement ChannelsArrangement
{
get { return channelsArrangement; }
Expand Down
21 changes: 10 additions & 11 deletions ATL/AudioData/IO/AIFF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private struct ChunkHeader
}

// Private declarations
private uint bits;
private int bits;

private string compression;
private byte versionID;
Expand Down Expand Up @@ -94,10 +94,6 @@ public byte VersionID // Version code
{
get { return this.versionID; }
}
public uint Bits
{
get { return bits; }
}
public double CompressionRatio
{
get { return getCompressionRatio(); }
Expand Down Expand Up @@ -132,6 +128,9 @@ public double BitRate
{
get { return bitrate; }
}

public int BitDepth => (bits > 0) ? bits : -1;

public double Duration
{
get { return duration; }
Expand Down Expand Up @@ -352,7 +351,7 @@ protected override bool read(BinaryReader source, MetaDataIO.ReadTagParams readT
}

uint numSampleFrames = StreamUtils.DecodeBEUInt32(source.ReadBytes(4));
short sampleSize = StreamUtils.DecodeBEInt16(source.ReadBytes(2)); // This sample size is for uncompressed data only
bits = StreamUtils.DecodeBEInt16(source.ReadBytes(2)); // This sample size is for uncompressed data only
byte[] byteArray = source.ReadBytes(10);
Array.Reverse(byteArray);
double aSampleRate = StreamUtils.ExtendedToDouble(byteArray);
Expand All @@ -373,12 +372,12 @@ protected override bool read(BinaryReader source, MetaDataIO.ReadTagParams readT

if (!compression.Equals(COMPRESSION_NONE)) // Sample size is specific to selected compression method
{
if (compression.ToLower().Equals("fl32")) sampleSize = 32;
else if (compression.ToLower().Equals("fl64")) sampleSize = 64;
else if (compression.ToLower().Equals("alaw")) sampleSize = 8;
else if (compression.ToLower().Equals("ulaw")) sampleSize = 8;
if (compression.ToLower().Equals("fl32")) bits = 32;
else if (compression.ToLower().Equals("fl64")) bits = 64;
else if (compression.ToLower().Equals("alaw")) bits = 8;
else if (compression.ToLower().Equals("ulaw")) bits = 8;
}
if (duration > 0) bitrate = sampleSize * numSampleFrames * channelsArrangement.NbChannels / duration;
if (duration > 0) bitrate = bits * numSampleFrames * channelsArrangement.NbChannels / duration;
}
}
else if (header.ID.Equals(CHUNKTYPE_SOUND))
Expand Down
7 changes: 3 additions & 4 deletions ATL/AudioData/IO/Ape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,6 @@ public ChannelsArrangement ChannelsArrangement
{
get { return channelsArrangement; }
}
public int Bits
{
get { return bits; }
}
public uint PeakLevel
{
get { return peakLevel; }
Expand Down Expand Up @@ -190,6 +186,9 @@ public double Duration
{
get { return duration; }
}

public int BitDepth => bits;

public bool IsMetaSupported(MetaDataIOFactory.TagType metaDataType)
{
return (metaDataType == MetaDataIOFactory.TagType.APE) || (metaDataType == MetaDataIOFactory.TagType.ID3V1) || (metaDataType == MetaDataIOFactory.TagType.ID3V2);
Expand Down
7 changes: 6 additions & 1 deletion ATL/AudioData/IO/CAF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class CAF : MetaDataIO, IAudioDataIO
private double bitrate;
private double duration;
private uint channelsPerFrame;
private uint bitsPerChannel;
double secondsPerByte;
private ChannelsArrangement channelsArrangement;

Expand Down Expand Up @@ -163,6 +164,9 @@ public double BitRate
{
get { return bitrate; }
}

public int BitDepth => (int)(bitsPerChannel * channelsPerFrame);

public double Duration
{
get { return duration; }
Expand Down Expand Up @@ -217,6 +221,7 @@ protected void resetData()
bitrate = 0;
isVbr = false;
codecFamily = 0;
bitsPerChannel = 0;
channelsPerFrame = 0;
channelsArrangement = null;
secondsPerByte = 0;
Expand Down Expand Up @@ -256,7 +261,7 @@ private void readAudioDescriptionChunk(BinaryReader source)
uint bytesPerPacket = StreamUtils.DecodeBEUInt32(source.ReadBytes(4));
uint framesPerPacket = StreamUtils.DecodeBEUInt32(source.ReadBytes(4));
channelsPerFrame = StreamUtils.DecodeBEUInt32(source.ReadBytes(4));
source.BaseStream.Seek(4, SeekOrigin.Current); // bits per channel
bitsPerChannel = StreamUtils.DecodeBEUInt32(source.ReadBytes(4));

sampleRate = (uint)Math.Round(m_sampleRate);

Expand Down
7 changes: 3 additions & 4 deletions ATL/AudioData/IO/DSF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ class DSF : IAudioDataIO, IMetaDataEmbedder


// Public declarations
public uint Bits
{
get { return bits; }
}
public double CompressionRatio
{
get { return getCompressionRatio(); }
Expand Down Expand Up @@ -71,6 +67,9 @@ public double BitRate
{
get { return bitrate; }
}

public int BitDepth => (int)bits;

public double Duration
{
get { return duration; }
Expand Down
5 changes: 1 addition & 4 deletions ATL/AudioData/IO/DTS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ class DTS : IAudioDataIO


// Public declarations
public uint Bits
{
get { return bits; }
}
public double CompressionRatio
{
get { return getCompressionRatio(); }
Expand Down Expand Up @@ -66,6 +62,7 @@ public double BitRate
{
get { return bitrate; }
}
public int BitDepth => (int)bits;
public double Duration
{
get { return duration; }
Expand Down
4 changes: 4 additions & 0 deletions ATL/AudioData/IO/DummyReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public int SampleRate
{
get { return 0; }
}

/// <inheritdoc/>
public int BitDepth => -1;

/// <inheritdoc/>
public bool IsVBR
{
Expand Down
1 change: 1 addition & 0 deletions ATL/AudioData/IO/FLAC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public double BitRate
{
get { return Math.Round(((double)(sizeInfo.FileSize - AudioDataOffset)) * 8 / Duration); }
}
public int BitDepth => bitsPerSample;
public double Duration
{
get { return getDuration(); }
Expand Down
1 change: 1 addition & 0 deletions ATL/AudioData/IO/GYM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public double BitRate
{
get { return bitrate; }
}
public int BitDepth => -1; // Irrelevant for that format
public double Duration
{
get { return duration; }
Expand Down
1 change: 1 addition & 0 deletions ATL/AudioData/IO/IT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public double BitRate
{
get { return bitrate; }
}
public int BitDepth => -1; // Irrelevant for that format
public double Duration
{
get { return duration; }
Expand Down
1 change: 1 addition & 0 deletions ATL/AudioData/IO/MIDI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ public double BitRate
{
get { return bitrate; }
}
public int BitDepth => -1; // Irrelevant for that format
/// <inheritdoc/>
public double Duration
{
Expand Down
1 change: 1 addition & 0 deletions ATL/AudioData/IO/MOD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public double BitRate
{
get { return bitrate; }
}
public int BitDepth => -1; // Irrelevant for that format
public double Duration
{
get { return duration; }
Expand Down
1 change: 1 addition & 0 deletions ATL/AudioData/IO/MP4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public double BitRate
{
get { return bitrate / 1000.0; }
}
public int BitDepth => -1; // Irrelevant for lossy formats
public double Duration
{
get { return getDuration(); }
Expand Down
1 change: 1 addition & 0 deletions ATL/AudioData/IO/MPEGaudio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ public void LoadFromByteArray(byte[] data)
public VBRData VBR { get => vbrData; }
public bool IsVBR { get => vbrData.Found; }
public double BitRate { get => getBitRate(); }
public int BitDepth => -1; // Irrelevant for lossy formats
public double Duration { get => getDuration(); }
public ChannelsArrangement ChannelsArrangement { get => getChannelsArrangement(HeaderFrame); }
public int SampleRate { get => getSampleRate(); }
Expand Down
1 change: 1 addition & 0 deletions ATL/AudioData/IO/MPEGplus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public double BitRate
{
get { return bitrate; }
}
public int BitDepth => -1; // Irrelevant for lossy formats
public double Duration
{
get { return duration; }
Expand Down
4 changes: 4 additions & 0 deletions ATL/AudioData/IO/Ogg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class Ogg : VorbisTagHolder, IMetaDataIO, IAudioDataIO

private int contents;

private int bits;
private int sampleRate;
private ushort bitRateNominal;
private ulong samples;
Expand Down Expand Up @@ -100,6 +101,7 @@ public double BitRate
{
get { return getBitRate(); }
}
public int BitDepth => bits; // Only for embedded FLAC
public double Duration
{
get { return getDuration(); }
Expand Down Expand Up @@ -312,6 +314,7 @@ protected void resetData()
{
sampleRate = 0;
bitRateNominal = 0;
bits = -1;
samples = 0;
contents = -1;
AudioDataOffset = -1;
Expand Down Expand Up @@ -750,6 +753,7 @@ public bool Read(BinaryReader source, ReadTagParams readTagParams)
{
channelsArrangement = info.FlacParameters.getChannelsArrangement();
sampleRate = info.FlacParameters.SampleRate;
bits = info.FlacParameters.BitsPerSample;
// No nominal bitrate for FLAC
}

Expand Down
6 changes: 6 additions & 0 deletions ATL/AudioData/IO/OptimFROG.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public double BitRate
{
get { return bitrate; }
}
public int BitDepth => getBits();
public double Duration
{
get { return duration; }
Expand Down Expand Up @@ -153,6 +154,11 @@ private double getBitrate()
return ((sizeInfo.FileSize - header.Size - sizeInfo.TotalTagSize) * 8 / Duration);
}

private sbyte getBits()
{
return OFR_BITS[header.SampleType];
}

public bool Read(BinaryReader source, SizeInfo sizeInfo, MetaDataIO.ReadTagParams readTagParams)
{
bool result = false;
Expand Down
1 change: 1 addition & 0 deletions ATL/AudioData/IO/PSF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public double BitRate
{
get { return bitrate; }
}
public int BitDepth => -1; // Irrelevant for that format
public double Duration
{
get { return duration; }
Expand Down
1 change: 1 addition & 0 deletions ATL/AudioData/IO/S3M.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public double BitRate
{
get { return bitrate; }
}
public int BitDepth => -1; // Irrelevant for that format
public double Duration
{
get { return duration; }
Expand Down
1 change: 1 addition & 0 deletions ATL/AudioData/IO/SPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public double BitRate
{
get { return bitrate; }
}
public int BitDepth => -1; // Irrelevant for that format
public double Duration
{
get { return duration; }
Expand Down
10 changes: 4 additions & 6 deletions ATL/AudioData/IO/TAK.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ class TAK : IAudioDataIO


// Public declarations
public uint Bits
{
get { return bits; }
}
public double CompressionRatio
{
get { return getCompressionRatio(); }
Expand Down Expand Up @@ -71,6 +67,7 @@ public double BitRate
{
get { return bitrate; }
}
public int BitDepth => (bits > 0) ? (int)bits : -1;
public double Duration
{
get { return duration; }
Expand Down Expand Up @@ -165,8 +162,9 @@ public bool Read(BinaryReader source, SizeInfo sizeInfo, MetaDataIO.ReadTagParam

sampleCount = (readData16 >> 14) + (readData32 << 2) + ((restOfData & 0x00000080) << 34);

sampleRate = ((restOfData >> 4) & 0x03ffff) + 6000; // bits 4 to 21
channelsArrangement = ChannelsArrangements.GuessFromChannelNumber((int)((restOfData >> 27) & 0x0F) + 1); // bits 28 to 31
sampleRate = ((restOfData >> 4) & 0x03ffff) + 6000; // bits 5 to 22
bits = ((restOfData >> 22) & 0x1f) + 8; // bits 23 to 27
channelsArrangement = GuessFromChannelNumber((int)((restOfData >> 27) & 0x0f) + 1); // bits 28 to 31

if (sampleCount > 0)
{
Expand Down
Loading

0 comments on commit 4bdece1

Please sign in to comment.