From e08d5f8991b21b4c8f1884aff0360b2153dd28ba Mon Sep 17 00:00:00 2001 From: Alexander Shabarshov Date: Sat, 4 Jul 2026 13:17:14 +0100 Subject: [PATCH] Audio plays now --- AudioCore/Impl/WasapiOutputDevice.cs | 10 +++++++--- AudioCore_Tests/Pipeline_Integration_Tests.cs | 6 +++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/AudioCore/Impl/WasapiOutputDevice.cs b/AudioCore/Impl/WasapiOutputDevice.cs index e94a39d..5f5d353 100644 --- a/AudioCore/Impl/WasapiOutputDevice.cs +++ b/AudioCore/Impl/WasapiOutputDevice.cs @@ -1,6 +1,7 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; using NAudio.CoreAudioApi; +using NAudio.Dmo; using NAudio.Wave; namespace AudioCore.Impl; @@ -11,6 +12,7 @@ public sealed class WasapiOutputDevice : IAudioOutputDevice, IDisposable private readonly BufferedWaveProvider _buffer; private readonly WaveFormat _mixFormat = null!; private readonly ByteBufferPool _pool; + private readonly bool _isFloat; public int SampleRate { get; } public int Channels { get; } @@ -51,16 +53,18 @@ public sealed class WasapiOutputDevice : IAudioOutputDevice, IDisposable // Use the system mix format (required for shared mode) _mixFormat = device.AudioClient.MixFormat; SampleRate = _mixFormat.SampleRate; + _isFloat = _mixFormat.Encoding == WaveFormatEncoding.Extensible && + ((WaveFormatExtensible)_mixFormat).SubFormat == AudioMediaSubtypes.MEDIASUBTYPE_IEEE_FLOAT; // Create buffer in mix format _buffer = new BufferedWaveProvider(_mixFormat) { - BufferLength = _mixFormat.AverageBytesPerSecond * 4, // 4 seconds + BufferLength = _mixFormat.AverageBytesPerSecond / 2, // 0.5 seconds DiscardOnBufferOverflow = false }; // Event-driven WASAPI mode (true = event mode) - _out = new WasapiOut(device, AudioClientShareMode.Shared, true, 10); + _out = new WasapiOut(device, AudioClientShareMode.Shared, false, 10); _out.Init(_buffer); } @@ -72,7 +76,7 @@ public sealed class WasapiOutputDevice : IAudioOutputDevice, IDisposable // Convert float -> PCM16 or float passthrough depending on mix format byte[] bytes; - if (_mixFormat.Encoding == WaveFormatEncoding.IeeeFloat) + if (_isFloat) { // Device supports float32 directly bytes = MemoryMarshal.AsBytes(samples).ToArray(); diff --git a/AudioCore_Tests/Pipeline_Integration_Tests.cs b/AudioCore_Tests/Pipeline_Integration_Tests.cs index fee8b17..6409e95 100644 --- a/AudioCore_Tests/Pipeline_Integration_Tests.cs +++ b/AudioCore_Tests/Pipeline_Integration_Tests.cs @@ -72,9 +72,9 @@ public sealed class Pipeline_Integration_Tests $"\"{outFlac}\"", RedirectStandardInput = true, RedirectStandardError = true, - UseShellExecute = false, - CreateNoWindow = true, - WindowStyle = ProcessWindowStyle.Hidden, + UseShellExecute = false, + CreateNoWindow = true, + WindowStyle = ProcessWindowStyle.Hidden, }; using var ff = Process.Start(psi);