(WaveAudio.WriteRiffHeader): new public static method.

This commit is contained in:
morkt 2017-01-31 15:34:33 +04:00
parent c0f26a0341
commit 8e48c06aaf

View File

@ -139,26 +139,30 @@ namespace GameRes
public override void Write (SoundInput source, Stream output)
{
using (var buffer = new BinaryWriter (output, Encoding.ASCII, true))
{
uint total_size = (uint)(0x2e - 8 + source.PcmSize);
buffer.Write (Signature);
buffer.Write (total_size);
buffer.Write (0x45564157); // 'WAVE'
buffer.Write (0x20746d66); // 'fmt '
buffer.Write (0x12);
buffer.Write (source.Format.FormatTag);
buffer.Write (source.Format.Channels);
buffer.Write (source.Format.SamplesPerSecond);
buffer.Write (source.Format.AverageBytesPerSecond);
buffer.Write (source.Format.BlockAlign);
buffer.Write (source.Format.BitsPerSample);
buffer.Write ((ushort)0);
buffer.Write (0x61746164); // 'data'
buffer.Write ((uint)source.PcmSize);
WriteRiffHeader (output, source.Format, (uint)source.PcmSize);
source.Position = 0;
source.CopyTo (output);
}
public static void WriteRiffHeader (Stream output, WaveFormat format, uint pcm_size)
{
using (var buffer = new BinaryWriter (output, Encoding.ASCII, true))
{
uint total_size = (uint)(0x24 + pcm_size);
buffer.Write (Wav.Signature);
buffer.Write (total_size);
buffer.Write (0x45564157); // 'WAVE'
buffer.Write (0x20746d66); // 'fmt '
buffer.Write (0x10);
buffer.Write (format.FormatTag);
buffer.Write (format.Channels);
buffer.Write (format.SamplesPerSecond);
buffer.Write (format.AverageBytesPerSecond);
buffer.Write (format.BlockAlign);
buffer.Write (format.BitsPerSample);
buffer.Write (0x61746164); // 'data'
buffer.Write (pcm_size);
}
}
}
}