From ebfecfe25c918c3c7ca9763adf68c01ec9498693 Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Mon, 6 May 2019 10:31:28 +0100 Subject: [PATCH] Added ReadVoiceDataBytes --- Facepunch.Steamworks/SteamUser.cs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Facepunch.Steamworks/SteamUser.cs b/Facepunch.Steamworks/SteamUser.cs index 2fffd84..264b94b 100644 --- a/Facepunch.Steamworks/SteamUser.cs +++ b/Facepunch.Steamworks/SteamUser.cs @@ -175,6 +175,33 @@ public static unsafe int ReadVoiceData( System.IO.Stream stream ) return (int) szWritten; } + /// + /// Reads the voice data and returns the bytes. You should obviously ideally be using + /// ReadVoiceData because it won't be creating a new byte array every call. But this + /// makes it easier to get it working, so let the babies have their bottle. + /// + public static unsafe byte[] ReadVoiceDataBytes() + { + if ( !HasVoiceData ) + return null; + + uint szWritten = 0; + uint deprecated = 0; + + fixed ( byte* b = readBuffer ) + { + if ( Internal.GetVoice( true, (IntPtr)b, (uint)readBuffer.Length, ref szWritten, false, IntPtr.Zero, 0, ref deprecated, 0 ) != VoiceResult.OK ) + return null; + } + + if ( szWritten == 0 ) + return null; + + var arry = new byte[szWritten]; + Array.Copy( readBuffer, 0, arry, 0, szWritten ); + return arry; + } + static uint sampleRate = 48000; public static uint SampleRate