public static byte[] SpeexCompress(float[] input, out int length) { short[] shortBuffer = new short[input.Length]; byte[] encoded = new byte[input.Length]; input.ToShortArray(shortBuffer); length = speexEnc.Encode(shortBuffer, 0, input.Length, encoded, 0, encoded.Length); return(encoded); }
public static void GetClip(ref byte[] samples) { if (AClip == null) { ClientLog.Instance.Log("audioClip == null"); return; } int length = Mathf.CeilToInt(time * AClip.frequency); length = length > AClip.samples ? AClip.samples : length; AClip.GetData(FS, 0); int eLeng = SE.Encode(FS, 0, length, BS, 0, length); samples = new byte[eLeng]; Array.Copy(BS, 0, samples, 0, eLeng); ClientLog.Instance.Log("GetClip === " + eLeng + " bytes."); }
static byte[] SpeexCompress(float[] input, out int length) { short[] shortBuffer = VoiceChatShortPool.Instance.Get(); byte[] encoded = VoiceChatBytePool.Instance.Get(); input.ToShortArray(shortBuffer); length = speexEnc.Encode(shortBuffer, 0, input.Length, encoded, 0, encoded.Length); VoiceChatShortPool.Instance.Return(shortBuffer); return encoded; }
public byte[] Encode(float[] data) { //Convert Convert(data, ref encodingBuffer); int length = encoder.Encode(encodingBuffer, 0, encodingBuffer.Length, encodedBuffer, 0, encodedBuffer.Length); //Copy to temp. var tmp = new byte[length]; Buffer.BlockCopy(encodedBuffer, 0, tmp, 0, tmp.Length); //Return encoded data. return(tmp); }
public static byte[] NSpeexCompress(float[] samplesFloat, out int length) { int sizeOfChunk = 320 * (Mathf.FloorToInt(samplesFloat.Length / 320f) - 1); short[] samplesShort = new short[samplesFloat.Length]; short[] samplesShortForNSpeex = new short[sizeOfChunk]; byte[] encoded = new byte[sizeOfChunk]; samplesFloat.ConvertToShort(samplesShort); for (int i = 0; i < sizeOfChunk; i++) { samplesShortForNSpeex [i] = samplesShort [i]; } length = nspeexEnc.Encode(samplesShortForNSpeex, 0, samplesShortForNSpeex.Length, encoded, 0, encoded.Length); return(encoded); }