Skip to content

Commit eff655d

Browse files
committed
fixed issue with mono input devices being initialized as stereo
1 parent adf504e commit eff655d

File tree

4 files changed

+28
-16
lines changed

4 files changed

+28
-16
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ obj/
44
/.vl/
55
/lib/net472/
66
/lib/net6.0-windows/
7+
/lib/net8.0-windows/

VL.Audio/src/Core/AudioEngine.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ public bool IsSampleRateSupported(int sampleRate)
307307

308308
public void GetSupportedChannels(out int inputChannels, out int outputChannels)
309309
{
310-
inputChannels = 2;
311-
outputChannels = 2;
310+
inputChannels = 0;
311+
outputChannels = 0;
312312

313313
if (CurrentDevice is AsioOut asioOut)
314314
{

VL.Audio/src/Core/WasapiInOut.cs

+22-11
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public class WasapiInOut : IDisposable
2222
public bool OutputInitialized { get; private set; }
2323
public bool InputInitialized { get; private set; }
2424

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;
2727
public ISampleProvider InputSampleProvider { get; private set; }
2828

2929
public WasapiInOut(MMDevice outputDevice, MMDevice inputDevice, bool isLoopback)
@@ -52,17 +52,28 @@ internal void SetupDevices()
5252

5353
internal void InitRecordAndPlayback(MasterWaveProvider masterWaveProvider, int inputChannels, int sampleRate)
5454
{
55-
Output?.Init(masterWaveProvider);
56-
Input?.StartRecording();
55+
OutputInitialized = false;
56+
InputInitialized = false;
5757

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+
}
6367

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+
}
6677
}
6778

6879
public void Dispose()

VL.Audio/src/VL.Audio.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0-windows</TargetFramework>
4+
<TargetFramework>net8.0-windows</TargetFramework>
55
<OutputPath>..\lib\</OutputPath>
66
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
77

@@ -10,9 +10,9 @@
1010

1111
<ItemGroup>
1212
<PackageReference Include="FftSharp" Version="1.1.4" />
13-
<PackageReference Include="NAudio" Version="2.0.1" />
13+
<PackageReference Include="NAudio" Version="2.2.1" />
1414
<PackageReference Include="NWaves" Version="0.9.6" />
15-
<PackageReference Include="VL.Core" Version="2023.5.3-0231-g927f01ae18" />
15+
<PackageReference Include="VL.Core" Version="2024.6.6" />
1616
</ItemGroup>
1717

1818
</Project>

0 commit comments

Comments
 (0)