From 3bf64fe7721bf6427514d1d6387de00d5645b8be Mon Sep 17 00:00:00 2001 From: Figo Zhao Date: Wed, 13 Nov 2019 10:56:59 +0800 Subject: [PATCH] Size computation with channels --- WavUtility.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WavUtility.cs b/WavUtility.cs index 4268e93..4fbd881 100644 --- a/WavUtility.cs +++ b/WavUtility.cs @@ -204,7 +204,7 @@ public static byte[] FromAudioClip (AudioClip audioClip, out string filepath, bo //Debug.AssertFormat (bitDepth == 16, "Only converting 16 bit is currently supported. The audio clip data is {0} bit.", bitDepth); // total file size = 44 bytes for header format and audioClip.samples * factor due to float to Int16 / sbyte conversion - int fileSize = audioClip.samples * BlockSize_16Bit + headerSize; // BlockSize (bitDepth) + int fileSize = audioClip.samples * BlockSize_16Bit * audioClip.channels + headerSize; // BlockSize (bitDepth) // chunk descriptor (riff) WriteFileHeader (ref stream, fileSize); @@ -304,7 +304,7 @@ private static int WriteFileData (ref MemoryStream stream, AudioClip audioClip, byte[] id = Encoding.ASCII.GetBytes ("data"); count += WriteBytesToMemoryStream (ref stream, id, "DATA_ID"); - int subchunk2Size = Convert.ToInt32 (audioClip.samples * BlockSize_16Bit); // BlockSize (bitDepth) + int subchunk2Size = Convert.ToInt32 (audioClip.samples * BlockSize_16Bit * audioClip.channels); // BlockSize (bitDepth) count += WriteBytesToMemoryStream (ref stream, BitConverter.GetBytes (subchunk2Size), "SAMPLES"); // Validate header