From e70f1b738b871c9b68416245a1f91dd23a7ba15a Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Mon, 18 Jul 2016 12:48:22 +0100 Subject: [PATCH] Voice, decompress --- .../{Client.Voice.cs => Client/Voice.cs} | 31 +++++++++++++++++++ .../Facepunch.Steamworks.csproj | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) rename Facepunch.Steamworks/{Client.Voice.cs => Client/Voice.cs} (76%) diff --git a/Facepunch.Steamworks/Client.Voice.cs b/Facepunch.Steamworks/Client/Voice.cs similarity index 76% rename from Facepunch.Steamworks/Client.Voice.cs rename to Facepunch.Steamworks/Client/Voice.cs index 5a9a155..6ed87dc 100644 --- a/Facepunch.Steamworks/Client.Voice.cs +++ b/Facepunch.Steamworks/Client/Voice.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; @@ -110,5 +111,35 @@ internal unsafe void Update() IsRecording = false; } } + + public unsafe bool Decompress( byte[] input, int inputoffset, int inputsize, MemoryStream output, uint samepleRate = 0 ) + { + if ( samepleRate == 0 ) + samepleRate = OptimalSampleRate; + + // + // Guessing the uncompressed size cuz we're dicks + // + { + var targetBufferSize = inputsize * 10; + + if ( output.Capacity < targetBufferSize ) + output.Capacity = targetBufferSize; + + output.SetLength( targetBufferSize ); + } + + fixed ( byte* pout = output.GetBuffer() ) + fixed ( byte* p = input ) + { + uint bytesOut = 0; + var result = (Valve.Steamworks.EVoiceResult) client.native.user.DecompressVoice( (IntPtr)( p + inputoffset ), (uint) inputsize, (IntPtr) pout, (uint) output.Length, ref bytesOut, (uint)samepleRate ); + + if ( bytesOut > 0 ) + output.SetLength( bytesOut ); + + return result == Valve.Steamworks.EVoiceResult.k_EVoiceResultOK; + } + } } } diff --git a/Facepunch.Steamworks/Facepunch.Steamworks.csproj b/Facepunch.Steamworks/Facepunch.Steamworks.csproj index b0b1cb0..5dce677 100644 --- a/Facepunch.Steamworks/Facepunch.Steamworks.csproj +++ b/Facepunch.Steamworks/Facepunch.Steamworks.csproj @@ -117,7 +117,6 @@ - @@ -125,6 +124,7 @@ +