From 85cf1096fb1c2d18f06a3f87af648c7bc3dbb487 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Fri, 3 Feb 2023 12:56:28 +0100 Subject: Minor, .NET wrapper --- WhisperNet/ExtensionMethods.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'WhisperNet/ExtensionMethods.cs') diff --git a/WhisperNet/ExtensionMethods.cs b/WhisperNet/ExtensionMethods.cs index 73ca15c..1bb594b 100644 --- a/WhisperNet/ExtensionMethods.cs +++ b/WhisperNet/ExtensionMethods.cs @@ -1,4 +1,5 @@ -using System.Runtime.InteropServices; +using System.Diagnostics; +using System.Runtime.InteropServices; using Whisper.Internal; namespace Whisper @@ -33,7 +34,7 @@ namespace Whisper /// List capture devices public static CaptureDeviceId[]? listCaptureDevices( this iMediaFoundation mf ) { - List? list = null; + CaptureDeviceId[]? result = null; pfnFoundCaptureDevices pfn = delegate ( int len, sCaptureDevice[]? arr, IntPtr pv ) { @@ -41,10 +42,11 @@ namespace Whisper { if( len == 0 || arr == null ) return 1; + Debug.Assert( len == arr.Length ); - list = new List( len ); - foreach( var i in arr ) - list.Add( new CaptureDeviceId( i ) ); + result = new CaptureDeviceId[ len ]; + for( int i = 0; i < len; i++ ) + result[ i ] = new CaptureDeviceId( arr[ i ] ); return 0; } catch( Exception ex ) @@ -56,7 +58,7 @@ namespace Whisper mf.listCaptureDevices( pfn, IntPtr.Zero ); - return list?.ToArray(); + return result; } /// Open audio capture device -- cgit v1.2.3