Skip to content

Commit 4bdece1

Browse files
committed
New bit depth audio data property
1 parent 18b5127 commit 4bdece1

35 files changed

+173
-152
lines changed

ATL.test/IO/AudioData/AudioData.cs

+65-63
Large diffs are not rendered by default.

ATL.test/IO/HighLevel.cs

+1
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,7 @@ public void StreamedIO_R_Audio()
958958

959959
Assert.AreEqual(33, theTrack.Duration);
960960
Assert.AreEqual(69, theTrack.Bitrate);
961+
Assert.AreEqual(-1, theTrack.BitDepth);
961962
Assert.AreEqual(22050, theTrack.SampleRate);
962963
Assert.AreEqual(true, theTrack.IsVBR);
963964
Assert.AreEqual(23125, theTrack.TechnicalInformation.AudioDataOffset);

ATL/AudioData/AudioFileIO.cs

+5
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@ public double BitRate
236236
get => audioData.BitRate;
237237
}
238238
/// <inheritdoc/>
239+
public int BitDepth
240+
{
241+
get => audioData.BitDepth;
242+
}
243+
/// <inheritdoc/>
239244
public int SampleRate
240245
{
241246
get => audioData.SampleRate;

ATL/AudioData/IO/AA.cs

+3
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ public int SampleRate
146146
}
147147
}
148148
}
149+
150+
public int BitDepth => -1; // Irrelevant for lossy formats
151+
149152
public string FileName
150153
{
151154
get { return fileName; }

ATL/AudioData/IO/AAC.cs

+3
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ public int SampleRate
9292
{
9393
get { return sampleRate; }
9494
}
95+
96+
public int BitDepth => -1; // Irrelevant for lossy formats
97+
9598
public string FileName
9699
{
97100
get { return fileName; }

ATL/AudioData/IO/AC3.cs

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public int SampleRate
5353
{
5454
get { return (int)this.sampleRate; }
5555
}
56+
57+
public int BitDepth => -1; // Irrelevant for lossy formats
58+
5659
public ChannelsArrangement ChannelsArrangement
5760
{
5861
get { return channelsArrangement; }

ATL/AudioData/IO/AIFF.cs

+10-11
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private struct ChunkHeader
6464
}
6565

6666
// Private declarations
67-
private uint bits;
67+
private int bits;
6868

6969
private string compression;
7070
private byte versionID;
@@ -94,10 +94,6 @@ public byte VersionID // Version code
9494
{
9595
get { return this.versionID; }
9696
}
97-
public uint Bits
98-
{
99-
get { return bits; }
100-
}
10197
public double CompressionRatio
10298
{
10399
get { return getCompressionRatio(); }
@@ -132,6 +128,9 @@ public double BitRate
132128
{
133129
get { return bitrate; }
134130
}
131+
132+
public int BitDepth => (bits > 0) ? bits : -1;
133+
135134
public double Duration
136135
{
137136
get { return duration; }
@@ -352,7 +351,7 @@ protected override bool read(BinaryReader source, MetaDataIO.ReadTagParams readT
352351
}
353352

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

374373
if (!compression.Equals(COMPRESSION_NONE)) // Sample size is specific to selected compression method
375374
{
376-
if (compression.ToLower().Equals("fl32")) sampleSize = 32;
377-
else if (compression.ToLower().Equals("fl64")) sampleSize = 64;
378-
else if (compression.ToLower().Equals("alaw")) sampleSize = 8;
379-
else if (compression.ToLower().Equals("ulaw")) sampleSize = 8;
375+
if (compression.ToLower().Equals("fl32")) bits = 32;
376+
else if (compression.ToLower().Equals("fl64")) bits = 64;
377+
else if (compression.ToLower().Equals("alaw")) bits = 8;
378+
else if (compression.ToLower().Equals("ulaw")) bits = 8;
380379
}
381-
if (duration > 0) bitrate = sampleSize * numSampleFrames * channelsArrangement.NbChannels / duration;
380+
if (duration > 0) bitrate = bits * numSampleFrames * channelsArrangement.NbChannels / duration;
382381
}
383382
}
384383
else if (header.ID.Equals(CHUNKTYPE_SOUND))

ATL/AudioData/IO/Ape.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,6 @@ public ChannelsArrangement ChannelsArrangement
118118
{
119119
get { return channelsArrangement; }
120120
}
121-
public int Bits
122-
{
123-
get { return bits; }
124-
}
125121
public uint PeakLevel
126122
{
127123
get { return peakLevel; }
@@ -190,6 +186,9 @@ public double Duration
190186
{
191187
get { return duration; }
192188
}
189+
190+
public int BitDepth => bits;
191+
193192
public bool IsMetaSupported(MetaDataIOFactory.TagType metaDataType)
194193
{
195194
return (metaDataType == MetaDataIOFactory.TagType.APE) || (metaDataType == MetaDataIOFactory.TagType.ID3V1) || (metaDataType == MetaDataIOFactory.TagType.ID3V2);

ATL/AudioData/IO/CAF.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ class CAF : MetaDataIO, IAudioDataIO
129129
private double bitrate;
130130
private double duration;
131131
private uint channelsPerFrame;
132+
private uint bitsPerChannel;
132133
double secondsPerByte;
133134
private ChannelsArrangement channelsArrangement;
134135

@@ -163,6 +164,9 @@ public double BitRate
163164
{
164165
get { return bitrate; }
165166
}
167+
168+
public int BitDepth => (int)(bitsPerChannel * channelsPerFrame);
169+
166170
public double Duration
167171
{
168172
get { return duration; }
@@ -217,6 +221,7 @@ protected void resetData()
217221
bitrate = 0;
218222
isVbr = false;
219223
codecFamily = 0;
224+
bitsPerChannel = 0;
220225
channelsPerFrame = 0;
221226
channelsArrangement = null;
222227
secondsPerByte = 0;
@@ -256,7 +261,7 @@ private void readAudioDescriptionChunk(BinaryReader source)
256261
uint bytesPerPacket = StreamUtils.DecodeBEUInt32(source.ReadBytes(4));
257262
uint framesPerPacket = StreamUtils.DecodeBEUInt32(source.ReadBytes(4));
258263
channelsPerFrame = StreamUtils.DecodeBEUInt32(source.ReadBytes(4));
259-
source.BaseStream.Seek(4, SeekOrigin.Current); // bits per channel
264+
bitsPerChannel = StreamUtils.DecodeBEUInt32(source.ReadBytes(4));
260265

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

ATL/AudioData/IO/DSF.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ class DSF : IAudioDataIO, IMetaDataEmbedder
3535

3636

3737
// Public declarations
38-
public uint Bits
39-
{
40-
get { return bits; }
41-
}
4238
public double CompressionRatio
4339
{
4440
get { return getCompressionRatio(); }
@@ -71,6 +67,9 @@ public double BitRate
7167
{
7268
get { return bitrate; }
7369
}
70+
71+
public int BitDepth => (int)bits;
72+
7473
public double Duration
7574
{
7675
get { return duration; }

ATL/AudioData/IO/DTS.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ class DTS : IAudioDataIO
3030

3131

3232
// Public declarations
33-
public uint Bits
34-
{
35-
get { return bits; }
36-
}
3733
public double CompressionRatio
3834
{
3935
get { return getCompressionRatio(); }
@@ -66,6 +62,7 @@ public double BitRate
6662
{
6763
get { return bitrate; }
6864
}
65+
public int BitDepth => (int)bits;
6966
public double Duration
7067
{
7168
get { return duration; }

ATL/AudioData/IO/DummyReader.cs

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ public int SampleRate
3838
{
3939
get { return 0; }
4040
}
41+
42+
/// <inheritdoc/>
43+
public int BitDepth => -1;
44+
4145
/// <inheritdoc/>
4246
public bool IsVBR
4347
{

ATL/AudioData/IO/FLAC.cs

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public double BitRate
9393
{
9494
get { return Math.Round(((double)(sizeInfo.FileSize - AudioDataOffset)) * 8 / Duration); }
9595
}
96+
public int BitDepth => bitsPerSample;
9697
public double Duration
9798
{
9899
get { return getDuration(); }

ATL/AudioData/IO/GYM.cs

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public double BitRate
7272
{
7373
get { return bitrate; }
7474
}
75+
public int BitDepth => -1; // Irrelevant for that format
7576
public double Duration
7677
{
7778
get { return duration; }

ATL/AudioData/IO/IT.cs

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public double BitRate
7373
{
7474
get { return bitrate; }
7575
}
76+
public int BitDepth => -1; // Irrelevant for that format
7677
public double Duration
7778
{
7879
get { return duration; }

ATL/AudioData/IO/MIDI.cs

+1
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ public double BitRate
324324
{
325325
get { return bitrate; }
326326
}
327+
public int BitDepth => -1; // Irrelevant for that format
327328
/// <inheritdoc/>
328329
public double Duration
329330
{

ATL/AudioData/IO/MOD.cs

+1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ public double BitRate
136136
{
137137
get { return bitrate; }
138138
}
139+
public int BitDepth => -1; // Irrelevant for that format
139140
public double Duration
140141
{
141142
get { return duration; }

ATL/AudioData/IO/MP4.cs

+1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ public double BitRate
161161
{
162162
get { return bitrate / 1000.0; }
163163
}
164+
public int BitDepth => -1; // Irrelevant for lossy formats
164165
public double Duration
165166
{
166167
get { return getDuration(); }

ATL/AudioData/IO/MPEGaudio.cs

+1
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ public void LoadFromByteArray(byte[] data)
234234
public VBRData VBR { get => vbrData; }
235235
public bool IsVBR { get => vbrData.Found; }
236236
public double BitRate { get => getBitRate(); }
237+
public int BitDepth => -1; // Irrelevant for lossy formats
237238
public double Duration { get => getDuration(); }
238239
public ChannelsArrangement ChannelsArrangement { get => getChannelsArrangement(HeaderFrame); }
239240
public int SampleRate { get => getSampleRate(); }

ATL/AudioData/IO/MPEGplus.cs

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public double BitRate
6060
{
6161
get { return bitrate; }
6262
}
63+
public int BitDepth => -1; // Irrelevant for lossy formats
6364
public double Duration
6465
{
6566
get { return duration; }

ATL/AudioData/IO/Ogg.cs

+4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class Ogg : VorbisTagHolder, IMetaDataIO, IAudioDataIO
7171

7272
private int contents;
7373

74+
private int bits;
7475
private int sampleRate;
7576
private ushort bitRateNominal;
7677
private ulong samples;
@@ -100,6 +101,7 @@ public double BitRate
100101
{
101102
get { return getBitRate(); }
102103
}
104+
public int BitDepth => bits; // Only for embedded FLAC
103105
public double Duration
104106
{
105107
get { return getDuration(); }
@@ -312,6 +314,7 @@ protected void resetData()
312314
{
313315
sampleRate = 0;
314316
bitRateNominal = 0;
317+
bits = -1;
315318
samples = 0;
316319
contents = -1;
317320
AudioDataOffset = -1;
@@ -750,6 +753,7 @@ public bool Read(BinaryReader source, ReadTagParams readTagParams)
750753
{
751754
channelsArrangement = info.FlacParameters.getChannelsArrangement();
752755
sampleRate = info.FlacParameters.SampleRate;
756+
bits = info.FlacParameters.BitsPerSample;
753757
// No nominal bitrate for FLAC
754758
}
755759

ATL/AudioData/IO/OptimFROG.cs

+6
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public double BitRate
8989
{
9090
get { return bitrate; }
9191
}
92+
public int BitDepth => getBits();
9293
public double Duration
9394
{
9495
get { return duration; }
@@ -153,6 +154,11 @@ private double getBitrate()
153154
return ((sizeInfo.FileSize - header.Size - sizeInfo.TotalTagSize) * 8 / Duration);
154155
}
155156

157+
private sbyte getBits()
158+
{
159+
return OFR_BITS[header.SampleType];
160+
}
161+
156162
public bool Read(BinaryReader source, SizeInfo sizeInfo, MetaDataIO.ReadTagParams readTagParams)
157163
{
158164
bool result = false;

ATL/AudioData/IO/PSF.cs

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public double BitRate
104104
{
105105
get { return bitrate; }
106106
}
107+
public int BitDepth => -1; // Irrelevant for that format
107108
public double Duration
108109
{
109110
get { return duration; }

ATL/AudioData/IO/S3M.cs

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public double BitRate
8080
{
8181
get { return bitrate; }
8282
}
83+
public int BitDepth => -1; // Irrelevant for that format
8384
public double Duration
8485
{
8586
get { return duration; }

ATL/AudioData/IO/SPC.cs

+1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ public double BitRate
166166
{
167167
get { return bitrate; }
168168
}
169+
public int BitDepth => -1; // Irrelevant for that format
169170
public double Duration
170171
{
171172
get { return duration; }

ATL/AudioData/IO/TAK.cs

+4-6
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ class TAK : IAudioDataIO
3535

3636

3737
// Public declarations
38-
public uint Bits
39-
{
40-
get { return bits; }
41-
}
4238
public double CompressionRatio
4339
{
4440
get { return getCompressionRatio(); }
@@ -71,6 +67,7 @@ public double BitRate
7167
{
7268
get { return bitrate; }
7369
}
70+
public int BitDepth => (bits > 0) ? (int)bits : -1;
7471
public double Duration
7572
{
7673
get { return duration; }
@@ -165,8 +162,9 @@ public bool Read(BinaryReader source, SizeInfo sizeInfo, MetaDataIO.ReadTagParam
165162

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

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

171169
if (sampleCount > 0)
172170
{

0 commit comments

Comments
 (0)