public float[] Decode(byte[] data) { var decoded = decoder.Decode(data, 0, data.Length, decodeBuffer, 0, false); Convert(decodeBuffer, ref decodedBuffer); return(decodedBuffer); }
private void Client_OnReceivedMessage(Byn.Net.NetworkEvent message) { int resLen = speexDec.Decode(message.MessageData.Buffer, message.MessageData.Offset, message.MessageData.ContentLength, outBufferShort, 0, false); ToFloatArray(outBufferShort, outBufferFloat, resLen); player.PlayAudio(outBufferFloat, 0, resLen); }
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(byte[] data, int dataLength) { float[] decoded = new float[VoiceChatSettings.sampleSize]; short[] shortBuffer = new short[VoiceChatSettings.sampleSize]; //Debug.Log("data.len="+ data .Length + "dataLength=" + dataLength); 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); }
private short[] DecodeAudio(byte[] encodedData) { var decoder = new NSpeex.SpeexDecoder(NSpeex.BandMode.Wide, false); var outBuffer = new List <byte[]>(); var tmpBuffer = new short[1024]; int numPackets = BitConverter.ToInt32(encodedData, 0); List <int> packet_sizes = new List <int>(); for (int i = 0; i < numPackets; i++) { int frame_size = BitConverter.ToInt32(encodedData, 4 + (i * 4)); packet_sizes.Add(frame_size); } int fr_index = 0; for (var idx = 4 + (numPackets * 4); idx + packet_sizes[fr_index] < encodedData.Length; idx += packet_sizes[fr_index]) { var read = decoder.Decode(encodedData, idx, packet_sizes[fr_index], tmpBuffer, 0, false); var tmpData = new byte[read * 2]; for (var i = 0; i < read; i++) { var ba = BitConverter.GetBytes(tmpBuffer[i]); System.Array.Copy(ba, 0, tmpData, i * 2, 2); } outBuffer.Add(tmpData); fr_index++; } var fullSize = outBuffer.Sum(delegate(byte[] m) { return(m.Length); }); var retData = new byte[fullSize]; var offset = 0; for (int i = 0; i < outBuffer.Count; i++) { var b = outBuffer[i]; System.Array.Copy(b, 0, retData, offset, b.Length); offset += b.Length; } short[] pcm = new short[retData.Length / sizeof(short)]; Buffer.BlockCopy(retData, 0, pcm, 0, retData.Length); return(pcm); }
private short[] SpeexDecode(byte[] input, BandMode mode) { NSpeex.SpeexDecoder speexDec = null; int shortLen = 320; switch (mode) { case BandMode.Narrow: speexDec = m_narrow_dec; shortLen = 320; break; case BandMode.Wide: speexDec = m_wide_dec; shortLen = 640; break; case BandMode.UltraWide: speexDec = m_ultrawide_dec; shortLen = 1280; break; } byte[] len_bytes = USpeakPoolUtils.GetByte(4); System.Array.Copy(input, len_bytes, 4); int dataLength = BitConverter.ToInt32(len_bytes, 0); USpeakPoolUtils.Return(len_bytes); byte[] actual_bytes = USpeakPoolUtils.GetByte(input.Length - 4); Buffer.BlockCopy(input, 4, actual_bytes, 0, input.Length - 4); short[] decoded = USpeakPoolUtils.GetShort(shortLen); speexDec.Decode(actual_bytes, 0, dataLength, decoded, 0, false); USpeakPoolUtils.Return(actual_bytes); return(decoded); }
private void Client_OnReceivedMessage(Byn.Net.NetworkEvent message) { if (message.MessageData.ContentLength < 5) { return; } int offset = message.MessageData.Offset; byte[] messageBuffer = message.MessageData.Buffer; int messageId = messageBuffer[offset]; int pid = BitConverter.ToInt32(messageBuffer, offset + 1); offset += 5; if (messageId == isSpeechId) { int resLen = speexDec.Decode(message.MessageData.Buffer, offset, message.MessageData.ContentLength, outBufferShort, 0, false); ToFloatArray(outBufferShort, outBufferFloat, resLen); int bean = message.ConnectionId.id; player.PlayAudio(outBufferFloat, 0, resLen, pid); } }