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; }
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; }