Fix channels.

This commit is contained in:
Matthias Mailänder
2020-12-19 12:46:20 +01:00
committed by Paul Chote
parent 9a9f58d744
commit b4c483ce1a
2 changed files with 5 additions and 3 deletions

View File

@@ -49,7 +49,7 @@ namespace OpenRA.Mods.Cnc.AudioLoaders
public sealed class AudFormat : ISoundFormat public sealed class AudFormat : ISoundFormat
{ {
public int Channels { get { return 1; } } public int Channels { get { return channels; } }
public int SampleBits { get { return sampleBits; } } public int SampleBits { get { return sampleBits; } }
public int SampleRate { get { return sampleRate; } } public int SampleRate { get { return sampleRate; } }
public float LengthInSeconds { get { return AudReader.SoundLength(sourceStream); } } public float LengthInSeconds { get { return AudReader.SoundLength(sourceStream); } }
@@ -58,6 +58,7 @@ namespace OpenRA.Mods.Cnc.AudioLoaders
readonly Stream sourceStream; readonly Stream sourceStream;
readonly Func<Stream> audStreamFactory; readonly Func<Stream> audStreamFactory;
readonly int channels;
readonly int sampleBits; readonly int sampleBits;
readonly int sampleRate; readonly int sampleRate;
@@ -65,7 +66,7 @@ namespace OpenRA.Mods.Cnc.AudioLoaders
{ {
sourceStream = stream; sourceStream = stream;
if (!AudReader.LoadSound(stream, out audStreamFactory, out sampleRate, out sampleBits)) if (!AudReader.LoadSound(stream, out audStreamFactory, out sampleRate, out sampleBits, out channels))
throw new InvalidDataException(); throw new InvalidDataException();
} }
} }

View File

@@ -49,7 +49,7 @@ namespace OpenRA.Mods.Cnc.FileFormats
return (float)samples / sampleRate; return (float)samples / sampleRate;
} }
public static bool LoadSound(Stream s, out Func<Stream> result, out int sampleRate, out int sampleBits) public static bool LoadSound(Stream s, out Func<Stream> result, out int sampleRate, out int sampleBits, out int channels)
{ {
result = null; result = null;
var startPosition = s.Position; var startPosition = s.Position;
@@ -60,6 +60,7 @@ namespace OpenRA.Mods.Cnc.FileFormats
var outputSize = s.ReadInt32(); var outputSize = s.ReadInt32();
var readFlag = s.ReadByte(); var readFlag = s.ReadByte();
sampleBits = (readFlag & (int)SoundFlags._16Bit) == 0 ? 8 : 16; sampleBits = (readFlag & (int)SoundFlags._16Bit) == 0 ? 8 : 16;
channels = (readFlag & (int)SoundFlags.Stereo) == 0 ? 1 : 2;
var readFormat = s.ReadByte(); var readFormat = s.ReadByte();
if (!Enum.IsDefined(typeof(SoundFormat), readFormat)) if (!Enum.IsDefined(typeof(SoundFormat), readFormat))