コード例 #1
0
        /// <summary>
        /// Convert audio data to a short array
        /// </summary>
        /// <param name="clip">The audio clip to convert</param>
        /// <returns>A short array</returns>
        public static short[] AudioDataToShorts(float[] samples, int channels, float gain = 1.0f)
        {
            short[] data = USpeakPoolUtils.GetShort(samples.Length * channels);
            for (int i = 0; i < samples.Length; i++)
            {
                //convert to the -3267 to +3267 range
                float g = samples[i] * gain;
                if (Mathf.Abs(g) > 1.0f)
                {
                    if (g > 0)
                    {
                        g = 1.0f;
                    }
                    else
                    {
                        g = -1.0f;
                    }
                }
                float conv = g * 3267.0f;
                //int c = Mathf.RoundToInt( conv );

                data[i] = (short)conv;
            }

            return(data);
        }
コード例 #2
0
 // Token: 0x06004CA9 RID: 19625 RVA: 0x0019B53C File Offset: 0x0019993C
 public static short[] AudioDataToShorts(float[] samples, int channels, float gain = 1f)
 {
     short[] @short = USpeakPoolUtils.GetShort(samples.Length * channels);
     for (int i = 0; i < samples.Length; i++)
     {
         float num = samples[i] * gain * 3267f;
         @short[i] = (short)((num >= -3267f) ? ((num <= 3267f) ? num : 3267f) : -3267f);
     }
     return(@short);
 }
コード例 #3
0
ファイル: MuLawCodec.cs プロジェクト: sknchan/LegacyRust
            public static short[] MuLawDecode(byte[] data)
            {
                int length = (int)data.Length;

                short[] num = USpeakPoolUtils.GetShort(length);
                for (int i = 0; i < length; i++)
                {
                    num[i] = MuLawCodec.MuLawDecoder.muLawToPcmMap[data[i]];
                }
                return(num);
            }
コード例 #4
0
            public static short[] MuLawDecode(byte[] data)
            {
                int length = data.Length;

                short[] @short = USpeakPoolUtils.GetShort(length);
                for (int i = 0; i < length; i++)
                {
                    @short[i] = muLawToPcmMap[data[i]];
                }
                return(@short);
            }
コード例 #5
0
ファイル: MuLawCodec.cs プロジェクト: Smoothstep/VRChat
            // Token: 0x06004C34 RID: 19508 RVA: 0x00197840 File Offset: 0x00195C40
            public static short[] MuLawDecode(byte[] data)
            {
                int num = data.Length;

                short[] @short = USpeakPoolUtils.GetShort(num);
                for (int i = 0; i < num; i++)
                {
                    @short[i] = MuLawCodec.MuLawDecoder.muLawToPcmMap[(int)data[i]];
                }
                return(@short);
            }
コード例 #6
0
ファイル: MuLawCodec.cs プロジェクト: 602147629/GDGJ_Script
            public static short[] MuLawDecode(byte[] data)
            {
                var size    = data.Length;
                var decoded = USpeakPoolUtils.GetShort(size);

                for (var i = 0; i < size; i++)
                {
                    decoded[i] = muLawToPcmMap[data[i]];
                }
                return(decoded);
            }
コード例 #7
0
ファイル: ADPCMCodec.cs プロジェクト: 602147629/GDGJ_Script
 public short[] Decode(byte[] data, BandMode mode)
 {
     Init();
     short[] temp = USpeakPoolUtils.GetShort(data.Length * 2);
     for (int i = 0; i < data.Length; i++)
     {
         byte c = data[i];
         byte d = (byte)(c & 0x0f);
         byte e = (byte)(c >> 4);
         temp[i * 2]       = ADPCM_Decode(d);
         temp[(i * 2) + 1] = ADPCM_Decode(e);
     }
     return(temp);
 }
コード例 #8
0
 public static short[] AudioDataToShorts(float[] samples, int channels, float gain = 1f)
 {
     short[] num = USpeakPoolUtils.GetShort((int)samples.Length * channels);
     for (int i = 0; i < (int)samples.Length; i++)
     {
         float single = samples[i] * gain;
         if (Mathf.Abs(single) > 1f)
         {
             single = (single <= 0f ? -1f : 1f);
         }
         num[i] = (short)(single * 3267f);
     }
     return(num);
 }
コード例 #9
0
 public short[] Decode(byte[] data, BandMode mode)
 {
     this.Init();
     short[] @short = USpeakPoolUtils.GetShort(data.Length * 2);
     for (int i = 0; i < data.Length; i++)
     {
         byte num2           = data[i];
         byte originalSample = (byte)(num2 & 15);
         byte num4           = (byte)(num2 >> 4);
         @short[i * 2]       = this.ADPCM_Decode(originalSample);
         @short[(i * 2) + 1] = this.ADPCM_Decode(num4);
     }
     return(@short);
 }
コード例 #10
0
ファイル: ADPCMCodec.cs プロジェクト: sknchan/LegacyRust
 public short[] Decode(byte[] data, BandMode mode)
 {
     this.Init();
     short[] num = USpeakPoolUtils.GetShort((int)data.Length * 2);
     for (int i = 0; i < (int)data.Length; i++)
     {
         byte num1 = data[i];
         byte num2 = (byte)(num1 & 15);
         byte num3 = (byte)(num1 >> 4);
         num[i * 2]     = this.ADPCM_Decode(num2);
         num[i * 2 + 1] = this.ADPCM_Decode(num3);
     }
     return(num);
 }
コード例 #11
0
ファイル: ADPCMCodec.cs プロジェクト: Smoothstep/VRChat
 // Token: 0x06004C1D RID: 19485 RVA: 0x001975A4 File Offset: 0x001959A4
 public short[] Decode(byte[] data, BandMode mode)
 {
     this.Init();
     short[] @short = USpeakPoolUtils.GetShort(data.Length * 2);
     for (int i = 0; i < data.Length; i++)
     {
         byte b = data[i];
         byte m = 15;
         byte originalSample  = (byte)(b & m);
         byte originalSample2 = (byte)(b >> 4);
         @short[i * 2]     = this.ADPCM_Decode(originalSample);
         @short[i * 2 + 1] = this.ADPCM_Decode(originalSample2);
     }
     return(@short);
 }
コード例 #12
0
ファイル: SpeexCodec.cs プロジェクト: 602147629/GDGJ_Script
        private short[] SpeexDecode(byte[] input, BandMode mode)
        {
            NSpeex.SpeexDecoder speexDec = null;
            int shortLen = 320;

            switch (mode)
            {
            case BandMode.Narrow:
                speexDec = m_narrow_dec;
                shortLen = 320;
                break;

            case BandMode.Wide:
                speexDec = m_wide_dec;
                shortLen = 640;
                break;

            case BandMode.UltraWide:
                speexDec = m_ultrawide_dec;
                shortLen = 1280;
                break;
            }

            byte[] len_bytes = USpeakPoolUtils.GetByte(4);
            System.Array.Copy(input, len_bytes, 4);

            int dataLength = BitConverter.ToInt32(len_bytes, 0);

            USpeakPoolUtils.Return(len_bytes);

            byte[] actual_bytes = USpeakPoolUtils.GetByte(input.Length - 4);
            Buffer.BlockCopy(input, 4, actual_bytes, 0, input.Length - 4);

            short[] decoded = USpeakPoolUtils.GetShort(shortLen);

            speexDec.Decode(actual_bytes, 0, dataLength, decoded, 0, false);

            USpeakPoolUtils.Return(actual_bytes);

            return(decoded);
        }
コード例 #13
0
ファイル: OpusCodec.cs プロジェクト: Smoothstep/VRChat
    // Token: 0x06004C3B RID: 19515 RVA: 0x00197B6C File Offset: 0x00195F6C
    public short[] Decode(byte[] data, BandMode mode)
    {
        if (!this.isInitialized)
        {
            this.CreateEncoders();
        }
        if (mode != BandMode.Opus48k)
        {
            Debug.LogError(string.Concat(new string[]
            {
                "OpusCodec: Decode: bandwidth mode must be ",
                BandMode.Opus48k.ToString(),
                "! (set to ",
                mode.ToString(),
                ")"
            }));
        }
        int num = 0;

        byte[] array = this._decoder.Decode(data, (data == null) ? 0 : data.Length, out num);
        if (num != this._bytesPerSegment)
        {
            int num2 = (data == null) ? 0 : data.Length;
            Debug.LogError(string.Concat(new object[]
            {
                "OpusCodec: Decode failed! Output PCM data is ",
                num,
                " bbytes, expected ",
                this._bytesPerSegment,
                " (compressed packet size was ",
                num2,
                ")"
            }));
            USpeakPoolUtils.Return(array);
        }
        short[] @short = USpeakPoolUtils.GetShort(this._bytesPerSegment / 2);
        Buffer.BlockCopy(array, 0, @short, 0, this._bytesPerSegment);
        USpeakPoolUtils.Return(array);
        return(@short);
    }
コード例 #14
0
 public static short[] AudioDataToShorts(float[] samples, int channels, float gain = 1f)
 {
     short[] @short = USpeakPoolUtils.GetShort(samples.Length * channels);
     for (int i = 0; i < samples.Length; i++)
     {
         float f = samples[i] * gain;
         if (Mathf.Abs(f) > 1f)
         {
             if (f > 0f)
             {
                 f = 1f;
             }
             else
             {
                 f = -1f;
             }
         }
         float num3 = f * 3267f;
         @short[i] = (short)num3;
     }
     return(@short);
 }
コード例 #15
0
        // Token: 0x06004C40 RID: 19520 RVA: 0x00197DDC File Offset: 0x001961DC
        private short[] SpeexDecode(byte[] input, global::BandMode mode)
        {
            SpeexDecoder speexDecoder = null;
            int          length       = 320;

            if (mode != global::BandMode.Narrow)
            {
                if (mode != global::BandMode.Wide)
                {
                    if (mode == global::BandMode.UltraWide)
                    {
                        speexDecoder = this.m_ultrawide_dec;
                        length       = 1280;
                    }
                }
                else
                {
                    speexDecoder = this.m_wide_dec;
                    length       = 640;
                }
            }
            else
            {
                speexDecoder = this.m_narrow_dec;
                length       = 320;
            }
            byte[] @byte = USpeakPoolUtils.GetByte(4);
            Array.Copy(input, @byte, 4);
            int inCount = BitConverter.ToInt32(@byte, 0);

            USpeakPoolUtils.Return(@byte);
            byte[] byte2 = USpeakPoolUtils.GetByte(input.Length - 4);
            Buffer.BlockCopy(input, 4, byte2, 0, input.Length - 4);
            short[] @short = USpeakPoolUtils.GetShort(length);
            speexDecoder.Decode(byte2, 0, inCount, @short, 0, false);
            USpeakPoolUtils.Return(byte2);
            return(@short);
        }