Skip to content

Commit f88e463

Browse files
committed
WAV : Better detection for duration and bitrate [#330]
1 parent 5ec2418 commit f88e463

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

ATL/AudioData/IO/WAV.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ public AudioFormat AudioFormat
111111
public int CodecFamily => AudioDataIOFactory.CF_LOSSLESS;
112112
public string FileName { get; }
113113

114-
public double BitRate { get; private set; }
114+
public double BitRate => getBitrate();
115115

116116
public int BitDepth => bitsPerSample;
117-
public double Duration { get; private set; }
117+
public double Duration => getDuration();
118118

119119
public ChannelsArrangement ChannelsArrangement { get; private set; }
120120

@@ -176,9 +176,6 @@ public override string EncodeDate(DateTime date)
176176

177177
protected void resetData()
178178
{
179-
Duration = 0;
180-
BitRate = 0;
181-
182179
formatId = 0;
183180
sampleRate = 0;
184181
bytesPerSecond = 0;
@@ -445,7 +442,9 @@ private bool readWAV(Stream source, ReadTagParams readTagParams)
445442
id3v2StructureHelper.AddSize(riffChunkSizePos, formattedRiffChunkSize, CHUNK_ID3);
446443
}
447444

448-
source.Seek(chunkDataPos + chunkSize, SeekOrigin.Begin);
445+
var nextPos = chunkDataPos + chunkSize;
446+
if (nextPos > source.Length) break;
447+
source.Seek(nextPos, SeekOrigin.Begin);
449448
}
450449

451450
// Add zone placeholders for future tag writing
@@ -535,7 +534,6 @@ private string getFormat()
535534

536535
private double getDuration()
537536
{
538-
// Get duration
539537
double result = 0;
540538

541539
if (sampleNumber == 0 && bytesPerSecond > 0)
@@ -564,10 +562,6 @@ protected override bool read(Stream source, ReadTagParams readTagParams)
564562

565563
if (!readWAV(source, readTagParams)) return false;
566564

567-
// Process data if loaded and header valid
568-
BitRate = getBitrate();
569-
Duration = getDuration();
570-
571565
return true;
572566
}
573567

0 commit comments

Comments
 (0)