/* * FIXME> Possibly need a "final" flag that would pad with silence, and close the encoding sequence numbering... */ public int EncodeSamplesToFrame(byte[] bufferAudioPCM, out byte[] nCompressed) { byte[] bufferOut = new byte[32768]; int nCompressedBytes = 0; int nSampleCount = bufferAudioPCM.Length / 2; unsafe { nCompressedBytes = SteamVoiceCodecDLL.Compress(ptrSteamVoiceCodec, bufferAudioPCM, nSampleCount, bufferOut, 32768, false); } Console.WriteLine("========================================== Completed compression!"); int dataSize = bufferHeader.Length + nCompressedBytes; byte[] rv = new byte[dataSize + 4 /*CRC*/]; System.Buffer.BlockCopy(bufferHeader, 0, rv, 0, bufferHeader.Length); System.Buffer.BlockCopy(bufferOut, 0, rv, bufferHeader.Length, nCompressedBytes); UInt32 crc = crc32(rv, dataSize); rv[dataSize + 0] = (byte)((crc >> 0) & 0xff); rv[dataSize + 1] = (byte)((crc >> 8) & 0xff); rv[dataSize + 2] = (byte)((crc >> 16) & 0xff); rv[dataSize + 3] = (byte)((crc >> 24) & 0xff); nCompressed = rv; return(dataSize + 4); }
/* * */ public SteamVoiceFrame() { make_crc_table(); unsafe { ptrSteamVoiceCodec = SteamVoiceCodecDLL.CreateSteamCodec(); } }
/* * */ public int DecodePayload(byte[] nCompressedBuffer, int buflen, out byte[] nDecompressedSamples) { // byte [] nCompressedBuffer = { <nPayload Size>, <chunk size>, <seq nr>, <opus data> }; int nDecompressedBytes; byte[] bufferOut = new byte[32768]; unsafe { //int buflen ; //buflen = nCompressedBuffer[1]; //buflen = (buflen << 8) + nCompressedBuffer[0]; nDecompressedBytes = SteamVoiceCodecDLL.Decompress(ptrSteamVoiceCodec, nCompressedBuffer, buflen, bufferOut, 32768); } nDecompressedSamples = bufferOut; return(nDecompressedBytes); }