IBinaryStream migration - continued.

This commit is contained in:
morkt
2016-10-15 12:21:12 +04:00
parent 503b734645
commit d0c1d5da01
39 changed files with 529 additions and 574 deletions

View File

@@ -41,27 +41,25 @@ namespace GameRes.Formats.Leaf
Extensions = new string[] { "w" };
}
public override SoundInput TryOpen (Stream file)
public override SoundInput TryOpen (IBinaryStream file)
{
var header = new byte[0x12];
if (header.Length != file.Read (header, 0, header.Length))
return null;
var header = file.ReadHeader (0x12);
var format = new WaveFormat
{
FormatTag = 1,
Channels = header[0],
SamplesPerSecond = LittleEndian.ToUInt16 (header, 2),
AverageBytesPerSecond = LittleEndian.ToUInt32 (header, 6),
SamplesPerSecond = header.ToUInt16 (2),
AverageBytesPerSecond = header.ToUInt32 (6),
BlockAlign = header[1],
BitsPerSample = LittleEndian.ToUInt16 (header, 4),
BitsPerSample = header.ToUInt16 (4),
};
uint pcm_size = LittleEndian.ToUInt32 (header, 0xA);
uint pcm_size = header.ToUInt32 (0xA);
if (0 == pcm_size || 0 == format.AverageBytesPerSecond || format.BitsPerSample < 8
|| 0 == format.Channels || format.Channels > 8
|| (format.BlockAlign * format.SamplesPerSecond != format.AverageBytesPerSecond)
|| (pcm_size + 0x12 != file.Length))
return null;
var pcm = new StreamRegion (file, 0x12, pcm_size);
var pcm = new StreamRegion (file.AsStream, 0x12, pcm_size);
return new RawPcmInput (pcm, format);
}
}