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 @@ 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 );
}
}

View File

@ -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;