Providing streaming WavFormat data.
WavFormat.GetPCMInputStream now returns data that is streamed, rather than a MemoryStream.
This commit is contained in:
committed by
Paul Chote
parent
4ae92a5c22
commit
7ed769421e
@@ -50,37 +50,25 @@ namespace OpenRA.Mods.Common.AudioLoaders
|
||||
|
||||
public sealed class WavFormat : ISoundFormat
|
||||
{
|
||||
public int Channels { get { return reader.Value.Channels; } }
|
||||
public int SampleBits { get { return reader.Value.BitsPerSample; } }
|
||||
public int SampleRate { get { return reader.Value.SampleRate; } }
|
||||
public float LengthInSeconds { get { return WavReader.WaveLength(stream); } }
|
||||
public Stream GetPCMInputStream() { return new MemoryStream(reader.Value.RawOutput); }
|
||||
public void Dispose() { stream.Dispose(); }
|
||||
public int Channels { get { return channels; } }
|
||||
public int SampleBits { get { return sampleBits; } }
|
||||
public int SampleRate { get { return sampleRate; } }
|
||||
public float LengthInSeconds { get { return WavReader.WaveLength(sourceStream); } }
|
||||
public Stream GetPCMInputStream() { return wavStreamFactory(); }
|
||||
public void Dispose() { sourceStream.Dispose(); }
|
||||
|
||||
Lazy<WavReader> reader;
|
||||
|
||||
readonly Stream stream;
|
||||
readonly Stream sourceStream;
|
||||
readonly Func<Stream> wavStreamFactory;
|
||||
readonly short channels;
|
||||
readonly int sampleBits;
|
||||
readonly int sampleRate;
|
||||
|
||||
public WavFormat(Stream stream)
|
||||
{
|
||||
this.stream = stream;
|
||||
sourceStream = stream;
|
||||
|
||||
var position = stream.Position;
|
||||
reader = Exts.Lazy(() =>
|
||||
{
|
||||
var wavReader = new WavReader();
|
||||
try
|
||||
{
|
||||
if (!wavReader.LoadSound(stream))
|
||||
throw new InvalidDataException();
|
||||
}
|
||||
finally
|
||||
{
|
||||
stream.Position = position;
|
||||
}
|
||||
|
||||
return wavReader;
|
||||
});
|
||||
if (!WavReader.LoadSound(stream, out wavStreamFactory, out channels, out sampleBits, out sampleRate))
|
||||
throw new InvalidDataException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user