@@ -22,8 +22,8 @@ public class WasapiInOut : IDisposable
22
22
public bool OutputInitialized { get ; private set ; }
23
23
public bool InputInitialized { get ; private set ; }
24
24
25
- public int DriverOutputChannelCount { get ; internal set ; } = 2 ;
26
- public int DriverInputChannelCount { get ; internal set ; } = 2 ;
25
+ public int DriverOutputChannelCount => Output . OutputWaveFormat . Channels ;
26
+ public int DriverInputChannelCount => Input . WaveFormat . Channels ;
27
27
public ISampleProvider InputSampleProvider { get ; private set ; }
28
28
29
29
public WasapiInOut ( MMDevice outputDevice , MMDevice inputDevice , bool isLoopback )
@@ -52,17 +52,28 @@ internal void SetupDevices()
52
52
53
53
internal void InitRecordAndPlayback ( MasterWaveProvider masterWaveProvider , int inputChannels , int sampleRate )
54
54
{
55
- Output ? . Init ( masterWaveProvider ) ;
56
- Input ? . StartRecording ( ) ;
55
+ OutputInitialized = false ;
56
+ InputInitialized = false ;
57
57
58
- OutputInitialized = Output != null ;
59
- InputInitialized = Input != null ;
60
-
61
- if ( OutputInitialized )
62
- DriverOutputChannelCount = MMOutDevice . AudioClient . MixFormat . Channels ;
58
+ try
59
+ {
60
+ Output ? . Init ( masterWaveProvider ) ;
61
+ OutputInitialized = Output != null ;
62
+ }
63
+ catch ( Exception )
64
+ {
65
+ Output ? . Dispose ( ) ;
66
+ }
63
67
64
- if ( InputInitialized )
65
- DriverInputChannelCount = MMInDevice . AudioClient . MixFormat . Channels ;
68
+ try
69
+ {
70
+ Input ? . StartRecording ( ) ;
71
+ InputInitialized = Input != null ;
72
+ }
73
+ catch ( Exception )
74
+ {
75
+ Input ? . Dispose ( ) ;
76
+ }
66
77
}
67
78
68
79
public void Dispose ( )
0 commit comments