少年修仙传客户端代码仓库
client_Hale
2019-04-15 f99a0cd6ed9f5df666b19549e6a7de9bf9b9e9c8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
namespace NSpeex
{
    using System;
 
    internal class Stereo
    {
        private float balance = 1f;
        private float e_ratio = 0.5f;
        private static readonly float[] e_ratio_quant = new float[] { 0.25f, 0.315f, 0.397f, 0.5f };
        private float smooth_left = 1f;
        private float smooth_right = 1f;
        private const int SPEEX_INBAND_STEREO = 9;
 
        public void Decode(float[] data, int frameSize)
        {
            int num;
            float num2 = 0f;
            for (num = frameSize - 1; num >= 0; num--)
            {
                num2 += data[num] * data[num];
            }
            float num5 = num2 / this.e_ratio;
            float num3 = (num5 * this.balance) / (1f + this.balance);
            float num4 = num5 - num3;
            num3 = (float)Math.Sqrt((double)(num3 / (num2 + 0.01f)));
            num4 = (float)Math.Sqrt((double)(num4 / (num2 + 0.01f)));
            for (num = frameSize - 1; num >= 0; num--)
            {
                float num6 = data[num];
                this.smooth_left = (0.98f * this.smooth_left) + (0.02f * num3);
                this.smooth_right = (0.98f * this.smooth_right) + (0.02f * num4);
                data[2 * num] = this.smooth_left * num6;
                data[(2 * num) + 1] = this.smooth_right * num6;
            }
        }
 
        public static void Encode(Bits bits, float[] data, int frameSize)
        {
            float num3 = 0f;
            float num4 = 0f;
            float num5 = 0f;
            for (int i = 0; i < frameSize; i++)
            {
                num3 += data[2 * i] * data[2 * i];
                num4 += data[(2 * i) + 1] * data[(2 * i) + 1];
                data[i] = 0.5f * (data[2 * i] + data[(2 * i) + 1]);
                num5 += data[i] * data[i];
            }
            float num6 = (num3 + 1f) / (num4 + 1f);
            float num7 = num5 / ((1f + num3) + num4);
            bits.Pack(14, 5);
            bits.Pack(9, 4);
            num6 = (float)(4.0 * Math.Log((double)num6));
            if (num6 > 0f)
            {
                bits.Pack(0, 1);
            }
            else
            {
                bits.Pack(1, 1);
            }
            num6 = (float)Math.Floor((double)(0.5f + Math.Abs(num6)));
            if (num6 > 30f)
            {
                num6 = 31f;
            }
            bits.Pack((int)num6, 5);
            int num2 = VQ.Index(num7, e_ratio_quant, 4);
            bits.Pack(num2, 2);
        }
 
        public void Init(Bits bits)
        {
            float num = 1f;
            if (bits.Unpack(1) != 0)
            {
                num = -1f;
            }
            int index = bits.Unpack(5);
            this.balance = (float)Math.Exp((num * 0.25) * index);
            index = bits.Unpack(2);
            this.e_ratio = e_ratio_quant[index];
        }
    }
}