public int Decode(byte[] inData, int inOffset, int inCount, short[] outData, int outOffset, bool lostFrame) { if (this.decodedData.Length < outData.Length * 2) { this.decodedData = new float[outData.Length * 2]; } if (lostFrame || inData == null) { this.decoder.Decode(null, this.decodedData); int i = 0; while (i < this.frameSize) { outData[outOffset] = SpeexDecoder.ConvertToShort(this.decodedData[i]); i++; outOffset++; } return(this.frameSize); } this.bits.ReadFrom(inData, inOffset, inCount); int num = 0; while (this.decoder.Decode(this.bits, this.decodedData) == 0) { int j = 0; while (j < this.frameSize) { outData[outOffset] = SpeexDecoder.ConvertToShort(this.decodedData[j]); j++; outOffset++; } num += this.frameSize; } return(num); }
public static float[] DeCompress(NSpeex.SpeexDecoder speexDec, byte[] data, int dataLength) { float[] decoded = new float[data.Length]; short[] shortBuffer = new short[data.Length]; speexDec.Decode(data, 0, dataLength, shortBuffer, 0, false); shortBuffer.ToFloatArray(decoded, shortBuffer.Length); return(decoded); }
static float[] SpeexDecompress(NSpeex.SpeexDecoder speexDec, byte[] data, int dataLength) { float[] decoded = VoiceChatFloatPool.Instance.Get(); short[] shortBuffer = VoiceChatShortPool.Instance.Get(); speexDec.Decode(data, 0, dataLength, shortBuffer, 0, false); shortBuffer.ToFloatArray(decoded, shortBuffer.Length); VoiceChatShortPool.Instance.Return(shortBuffer); return(decoded); }
public SpeexJitterBuffer(SpeexDecoder decoder) { if (decoder == null) { throw new ArgumentNullException("decoder"); } this.decoder = decoder; this.inPacket.sequence = 0L; this.inPacket.span = 1L; this.inPacket.timestamp = 1L; this.buffer.DestroyBufferCallback = delegate(byte[] x) { }; this.buffer.Init(1); }
public static int Decompress(NSpeex.SpeexDecoder speexDecoder, VoiceChatPacket packet, out float[] data) { switch (packet.Compression) { /* * case VoiceChatCompression.Raw: * { * short[9 buffer * * Buffer.BlockCopy(packet.Data, 0, shortBuffer, 0, packet.Length); * shortBuffer.ToFloatArray(data, packet.Length / 2); * return packet.Length / 2; * } * * case VoiceChatCompression.RawZlib: * { * byte[] unzipedData = ZlibDecompress(packet.Data, packet.Length); * * Buffer.BlockCopy(unzipedData, 0, shortBuffer, 0, unzipedData.Length); * shortBuffer.ToFloatArray(data, unzipedData.Length / 2); * return unzipedData.Length / 2; * } */ case VoiceChatCompression.Speex: { data = SpeexDecompress(speexDecoder, packet.Data, packet.Length); return(data.Length); } case VoiceChatCompression.Alaw: { data = ALawDecompress(packet.Data, packet.Length); return(packet.Length); } case VoiceChatCompression.AlawZlib: { byte[] alaw = ZlibDecompress(packet.Data, packet.Length); data = ALawDecompress(alaw, alaw.Length); return(alaw.Length); } } data = new float[0]; return(0); }
/// <summary> /// Creates a new instance using the given <paramref name="decoder"/> /// </summary> /// <param name="decoder"></param> public SpeexJitterBuffer(SpeexDecoder decoder) { if (decoder == null) { throw new ArgumentNullException("decoder"); } this.decoder = decoder; inPacket.sequence = 0; inPacket.span = 1; inPacket.timestamp = 1; buffer.DestroyBufferCallback = (x) => { // GC handles that }; buffer.Init(1); }
public SpeexCodex(BandMode mode) { this.mode = mode; encoder = new NSpeex.SpeexEncoder(SpeedxMode); decoder = new NSpeex.SpeexDecoder(SpeedxMode, false); encoder.VBR = true; encoder.Quality = 4; dataSize = encoder.FrameSize * (mode == BandMode.Narrow ? 8 : mode == BandMode.Wide ? 8 : 2); encodingBuffer = new short[dataSize]; encodedBuffer = new byte[dataSize]; decodeBuffer = new short[dataSize]; decodedBuffer = new float[dataSize]; int frequency = AudioUtils.GetFrequency(mode); var time = frequency / (float)dataSize; UnityEngine.Debug.Log("SpeedCodex created mode:" + mode + " dataSize:" + dataSize + " time:" + time); }