public static VoiceChatPacket Compress(float[] sample) { VoiceChatPacket packet = new VoiceChatPacket(); packet.Compression = VoiceChatInnerSettings.Compression; switch (packet.Compression) { /* * case VoiceChatCompression.Raw: * { * short[] buffer = VoiceChatShortPool.Instance.Get(); * * packet.Length = sample.Length * 2; * sample.ToShortArray(shortBuffer); * Buffer.BlockCopy(shortBuffer, 0, byteBuffer, 0, packet.Length); * } * break; * * case VoiceChatCompression.RawZlib: * { * packet.Length = sample.Length * 2; * sample.ToShortArray(shortBuffer); * Buffer.BlockCopy(shortBuffer, 0, byteBuffer, 0, packet.Length); * * packet.Data = ZlibCompress(byteBuffer, packet.Length); * packet.Length = packet.Data.Length; * } * break; */ case VoiceChatCompression.Alaw: { packet.Length = sample.Length; packet.Data = ALawCompress(sample); } break; case VoiceChatCompression.AlawZlib: { byte[] alaw = ALawCompress(sample); packet.Data = ZlibCompress(alaw, sample.Length); packet.Length = packet.Data.Length; VoiceChatBytePool.Instance.Return(alaw); } break; case VoiceChatCompression.Speex: { packet.Data = SpeexCompress(sample, out packet.Length); } break; } return(packet); }
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); }
public static int Decompress(VoiceChatPacket packet, out float[] data) { return(Decompress(null, packet, out data)); }