From aa1aac50afd7910d8eb9fc300266d01821ca27e3 Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Fri, 7 Oct 2016 09:49:50 +0100 Subject: [PATCH] Added test GetVoice_Compressed_Only, GetVoice_UnCompressed_Only --- Facepunch.Steamworks.Test/Client/Client.cs | 74 ++++++++++++++++++++-- Facepunch.Steamworks/Client/Voice.cs | 4 +- 2 files changed, 71 insertions(+), 7 deletions(-) diff --git a/Facepunch.Steamworks.Test/Client/Client.cs b/Facepunch.Steamworks.Test/Client/Client.cs index 995ed21..9bbfc70 100644 --- a/Facepunch.Steamworks.Test/Client/Client.cs +++ b/Facepunch.Steamworks.Test/Client/Client.cs @@ -87,28 +87,92 @@ public void GetVoice() { using ( var client = new Facepunch.Steamworks.Client( 252490 ) ) { - int dataRead = 0; + int unCompressed = 0; + int compressed = 0; client.Voice.OnCompressedData = ( data ) => { - dataRead += data.Length; + compressed += data.Length; }; client.Voice.OnUncompressedData = ( data ) => { - dataRead += data.Length; + unCompressed += data.Length; }; client.Voice.WantsRecording = true; - for ( int i = 0; i < 32; i++ ) + var sw = Stopwatch.StartNew(); + + while ( sw.Elapsed.TotalSeconds < 3 ) { client.Update(); System.Threading.Thread.Sleep( 10 ); } + Assert.AreNotEqual( unCompressed, 0 ); + Assert.AreNotEqual( compressed, 0 ); + // Should really be > 0 if the mic was getting audio - Console.Write( dataRead ); + Console.WriteLine( "unCompressed: {0}", unCompressed ); + Console.WriteLine( "compressed: {0}", compressed ); + } + } + + [TestMethod] + public void GetVoice_Compressed_Only() + { + using ( var client = new Facepunch.Steamworks.Client( 252490 ) ) + { + int compressed = 0; + + client.Voice.OnCompressedData = ( data ) => + { + compressed += data.Length; + }; + + client.Voice.WantsRecording = true; + + var sw = Stopwatch.StartNew(); + + while ( sw.Elapsed.TotalSeconds < 3 ) + { + client.Update(); + System.Threading.Thread.Sleep( 10 ); + } + + Assert.AreNotEqual( compressed, 0 ); + Console.WriteLine( "compressed: {0}", compressed ); + } + } + + [TestMethod] + public void GetVoice_UnCompressed_Only() + { + using ( var client = new Facepunch.Steamworks.Client( 252490 ) ) + { + int unCompressed = 0; + + client.Voice.OnUncompressedData = ( data ) => + { + unCompressed += data.Length; + }; + + client.Voice.WantsRecording = true; + + var sw = Stopwatch.StartNew(); + + while ( sw.Elapsed.TotalSeconds < 3 ) + { + client.Update(); + System.Threading.Thread.Sleep( 10 ); + } + + Assert.AreNotEqual( unCompressed, 0 ); + + // Should really be > 0 if the mic was getting audio + Console.WriteLine( "unCompressed: {0}", unCompressed ); + } } diff --git a/Facepunch.Steamworks/Client/Voice.cs b/Facepunch.Steamworks/Client/Voice.cs index 6ed87dc..803491a 100644 --- a/Facepunch.Steamworks/Client/Voice.cs +++ b/Facepunch.Steamworks/Client/Voice.cs @@ -87,8 +87,8 @@ internal unsafe void Update() bufferRegularLastWrite = 0; bufferCompressedLastWrite = 0; - Valve.Steamworks.EVoiceResult result = (Valve.Steamworks.EVoiceResult) client.native.user.GetVoice( OnUncompressedData != null, (IntPtr) pbufferCompressed, (uint) bufferCompressed.Length, ref bufferCompressedLastWrite, - OnCompressedData != null, (IntPtr) pbufferRegular, (uint) bufferRegular.Length, ref bufferRegularLastWrite, + Valve.Steamworks.EVoiceResult result = (Valve.Steamworks.EVoiceResult) client.native.user.GetVoice( OnCompressedData != null, (IntPtr) pbufferCompressed, (uint) bufferCompressed.Length, ref bufferCompressedLastWrite, + OnUncompressedData != null, (IntPtr) pbufferRegular, (uint) bufferRegular.Length, ref bufferRegularLastWrite, DesiredSampleRate == 0 ? OptimalSampleRate : DesiredSampleRate ); IsRecording = true;