Added test GetVoice_Compressed_Only, GetVoice_UnCompressed_Only

This commit is contained in:
Garry Newman 2016-10-07 09:49:50 +01:00
parent d4eb325606
commit aa1aac50af
2 changed files with 71 additions and 7 deletions

View File

@ -87,28 +87,92 @@ namespace Facepunch.Steamworks.Test
{ {
using ( var client = new Facepunch.Steamworks.Client( 252490 ) ) using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
{ {
int dataRead = 0; int unCompressed = 0;
int compressed = 0;
client.Voice.OnCompressedData = ( data ) => client.Voice.OnCompressedData = ( data ) =>
{ {
dataRead += data.Length; compressed += data.Length;
}; };
client.Voice.OnUncompressedData = ( data ) => client.Voice.OnUncompressedData = ( data ) =>
{ {
dataRead += data.Length; unCompressed += data.Length;
}; };
client.Voice.WantsRecording = true; client.Voice.WantsRecording = true;
for ( int i = 0; i < 32; i++ ) var sw = Stopwatch.StartNew();
while ( sw.Elapsed.TotalSeconds < 3 )
{ {
client.Update(); client.Update();
System.Threading.Thread.Sleep( 10 ); System.Threading.Thread.Sleep( 10 );
} }
Assert.AreNotEqual( unCompressed, 0 );
Assert.AreNotEqual( compressed, 0 );
// Should really be > 0 if the mic was getting audio // 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 );
} }
} }

View File

@ -87,8 +87,8 @@ namespace Facepunch.Steamworks
bufferRegularLastWrite = 0; bufferRegularLastWrite = 0;
bufferCompressedLastWrite = 0; bufferCompressedLastWrite = 0;
Valve.Steamworks.EVoiceResult result = (Valve.Steamworks.EVoiceResult) client.native.user.GetVoice( OnUncompressedData != null, (IntPtr) pbufferCompressed, (uint) bufferCompressed.Length, ref bufferCompressedLastWrite, Valve.Steamworks.EVoiceResult result = (Valve.Steamworks.EVoiceResult) client.native.user.GetVoice( OnCompressedData != null, (IntPtr) pbufferCompressed, (uint) bufferCompressed.Length, ref bufferCompressedLastWrite,
OnCompressedData != null, (IntPtr) pbufferRegular, (uint) bufferRegular.Length, ref bufferRegularLastWrite, OnUncompressedData != null, (IntPtr) pbufferRegular, (uint) bufferRegular.Length, ref bufferRegularLastWrite,
DesiredSampleRate == 0 ? OptimalSampleRate : DesiredSampleRate ); DesiredSampleRate == 0 ? OptimalSampleRate : DesiredSampleRate );
IsRecording = true; IsRecording = true;