少年修仙传客户端代码仓库
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
namespace NSpeex
{
    using System;
 
    public class SpeexEncoder
    {
        private readonly Bits bits = new Bits();
        private readonly IEncoder encoder;
        private readonly int frameSize;
        private readonly float[] rawData;
        public const string Version = ".Net Speex Encoder v0.0.1";
 
        public SpeexEncoder(BandMode mode)
        {
            switch (mode)
            {
                case BandMode.Narrow:
                    this.encoder = new NbEncoder();
                    break;
 
                case BandMode.Wide:
                    this.encoder = new SbEncoder(false);
                    break;
 
                case BandMode.UltraWide:
                    this.encoder = new SbEncoder(true);
                    break;
 
                default:
                    throw new ArgumentException("Invalid mode", "mode");
            }
            this.frameSize = this.encoder.FrameSize;
            this.rawData = new float[this.frameSize];
        }
 
        public int Encode(short[] inData, int inOffset, int inCount, byte[] outData, int outOffset, int outCount)
        {
            this.bits.Reset();
            int num = 0;
            int num2 = 0;
            while (num < inCount)
            {
                for (int i = 0; i < this.frameSize; i++)
                {
                    this.rawData[i] = inData[(inOffset + i) + num];
                }
                num2 += this.encoder.Encode(this.bits, this.rawData);
                num += this.frameSize;
            }
            if (num2 == 0)
            {
                return 0;
            }
            return this.bits.Write(outData, outOffset, outCount);
        }
 
        public int FrameSize {
            get { return this.frameSize; }
        }
 
        public int Quality {
            set {
                this.encoder.Quality = value;
            }
        }
 
        public int SampleRate {
            get { return this.encoder.SamplingRate; }
        }
 
        public bool VBR {
            get {
                return this.encoder.Vbr;
            }
            set {
                this.encoder.Vbr = value;
            }
        }
    }
}