Skip to content

Commit

Permalink
fixed issue with mono input devices being initialized as stereo
Browse files Browse the repository at this point in the history
  • Loading branch information
joreg committed Nov 4, 2024
1 parent adf504e commit eff655d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ obj/
/.vl/
/lib/net472/
/lib/net6.0-windows/
/lib/net8.0-windows/
4 changes: 2 additions & 2 deletions VL.Audio/src/Core/AudioEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ public bool IsSampleRateSupported(int sampleRate)

public void GetSupportedChannels(out int inputChannels, out int outputChannels)
{
inputChannels = 2;
outputChannels = 2;
inputChannels = 0;
outputChannels = 0;

if (CurrentDevice is AsioOut asioOut)
{
Expand Down
33 changes: 22 additions & 11 deletions VL.Audio/src/Core/WasapiInOut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class WasapiInOut : IDisposable
public bool OutputInitialized { get; private set; }
public bool InputInitialized { get; private set; }

public int DriverOutputChannelCount { get; internal set; } = 2;
public int DriverInputChannelCount { get; internal set; } = 2;
public int DriverOutputChannelCount => Output.OutputWaveFormat.Channels;
public int DriverInputChannelCount => Input.WaveFormat.Channels;
public ISampleProvider InputSampleProvider { get; private set; }

public WasapiInOut(MMDevice outputDevice, MMDevice inputDevice, bool isLoopback)
Expand Down Expand Up @@ -52,17 +52,28 @@ internal void SetupDevices()

internal void InitRecordAndPlayback(MasterWaveProvider masterWaveProvider, int inputChannels, int sampleRate)
{
Output?.Init(masterWaveProvider);
Input?.StartRecording();
OutputInitialized = false;
InputInitialized = false;

OutputInitialized = Output != null;
InputInitialized = Input != null;

if (OutputInitialized)
DriverOutputChannelCount = MMOutDevice.AudioClient.MixFormat.Channels;
try
{
Output?.Init(masterWaveProvider);
OutputInitialized = Output != null;
}
catch (Exception)
{
Output?.Dispose();
}

if (InputInitialized)
DriverInputChannelCount = MMInDevice.AudioClient.MixFormat.Channels;
try
{
Input?.StartRecording();
InputInitialized = Input != null;
}
catch (Exception)
{
Input?.Dispose();
}
}

public void Dispose()
Expand Down
6 changes: 3 additions & 3 deletions VL.Audio/src/VL.Audio.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net8.0-windows</TargetFramework>
<OutputPath>..\lib\</OutputPath>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>

Expand All @@ -10,9 +10,9 @@

<ItemGroup>
<PackageReference Include="FftSharp" Version="1.1.4" />
<PackageReference Include="NAudio" Version="2.0.1" />
<PackageReference Include="NAudio" Version="2.2.1" />
<PackageReference Include="NWaves" Version="0.9.6" />
<PackageReference Include="VL.Core" Version="2023.5.3-0231-g927f01ae18" />
<PackageReference Include="VL.Core" Version="2024.6.6" />
</ItemGroup>

</Project>

0 comments on commit eff655d

Please sign in to comment.