Fixed AudFormat and WavFormat implementations of ISoundFormat.LengthInSeconds
- Fixed a rounding issue in `WavReader.WaveLength()`. - Fixed `AudReader.SoundLength()` not resetting the stream position. - Fixed crashes caused by disposed streams because `LengthInSeconds` would try and calculate the length on the fly. It is now precalculated and cached (making it consistent across all 5 current `ISoundFormat` implementations). - Fixed a crash in `AudReader.LoadSound()`'s `out Func<Stream> result` because that func would try and access the disposed stream's `Length` property. That works for `SegmentStream`, but not for `FileStream`. - Fixed frameCount/soundLength label positioning in the AssetBrowser window to avoid text clipping .
This commit is contained in:
committed by
Matthias Mailänder
parent
8b944e9c82
commit
abea3a0f74
@@ -34,6 +34,8 @@ namespace OpenRA.Mods.Cnc.FileFormats
|
||||
{
|
||||
public static float SoundLength(Stream s)
|
||||
{
|
||||
var originalPosition = s.Position;
|
||||
|
||||
var sampleRate = s.ReadUInt16();
|
||||
/*var dataSize = */ s.ReadInt32();
|
||||
var outputSize = s.ReadInt32();
|
||||
@@ -46,6 +48,8 @@ namespace OpenRA.Mods.Cnc.FileFormats
|
||||
if ((flags & SoundFlags._16Bit) != 0)
|
||||
samples /= 2;
|
||||
|
||||
s.Seek(originalPosition, SeekOrigin.Begin);
|
||||
|
||||
return (float)samples / sampleRate;
|
||||
}
|
||||
|
||||
@@ -70,10 +74,12 @@ namespace OpenRA.Mods.Cnc.FileFormats
|
||||
throw new NotImplementedException();
|
||||
|
||||
var offsetPosition = s.Position;
|
||||
var streamLength = s.Length;
|
||||
var segmentLength = (int)(streamLength - offsetPosition);
|
||||
|
||||
result = () =>
|
||||
{
|
||||
var audioStream = SegmentStream.CreateWithoutOwningStream(s, offsetPosition, (int)(s.Length - offsetPosition));
|
||||
var audioStream = SegmentStream.CreateWithoutOwningStream(s, offsetPosition, segmentLength);
|
||||
return new AudStream(audioStream, outputSize, dataSize);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user