Ejemplo n.º 1
0
        public static void Write32Bit(BinaryFile waveFile, float[][] sound, int sampleCount, int channels)
        {
            for (int i = 0; i < sampleCount; i++)
            {
                for (int ic = 0; ic < channels; ic++)
                {
                    int val = SoundIOUtils.RoundToClosestInt(sound[ic][i] * 2147483648);

                    if (val > 2147483647)
                    {
                        val = 2147483647;
                    }
                    if (val < -2147483648)
                    {
                        val = -2147483648;
                    }

                    waveFile.Write((int)val);
                }
            }
        }
Ejemplo n.º 2
0
        public static void Write16Bit(BinaryFile waveFile, float[][] sound, int sampleCount, int channels)
        {
            for (int i = 0; i < sampleCount; i++)
            {
                for (int ic = 0; ic < channels; ic++)
                {
                    int val = SoundIOUtils.RoundToClosestInt(sound[ic][i] * 32768.0f);

                    if (val > 32767)
                    {
                        val = 32767;
                    }
                    if (val < -32768)
                    {
                        val = -32768;
                    }

                    waveFile.Write((Int16)val);
                }
            }
        }
Ejemplo n.º 3
0
        public static void Write8Bit(BinaryFile waveFile, float[][] sound, int sampleCount, int channels)
        {
            for (int i = 0; i < sampleCount; i++)
            {
                for (int ic = 0; ic < channels; ic++)
                {
                    int val = SoundIOUtils.RoundToClosestInt((sound[ic][i] + 1) * 128);

                    if (val > 255)
                    {
                        val = 255;
                    }
                    if (val < 0)
                    {
                        val = 0;
                    }

                    byte b = (byte)val;

                    waveFile.Write(b);
                }
            }
        }