mirror of
https://github.com/crskycode/GARbro.git
synced 2026-07-08 01:30:18 +08:00
IBinaryStream migration - continued.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user