From f62c51729f674a1d6c95fbc461946186a3d5975b Mon Sep 17 00:00:00 2001 From: Mercurio <47455213+NotLugozzi@users.noreply.github.com> Date: Mon, 9 Sep 2024 21:12:20 +0200 Subject: [PATCH] Properly instantiate ASIO recording --- 2dxAutoClip/iidxAutoClip.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/2dxAutoClip/iidxAutoClip.cs b/2dxAutoClip/iidxAutoClip.cs index f6289de..48ce9e4 100644 --- a/2dxAutoClip/iidxAutoClip.cs +++ b/2dxAutoClip/iidxAutoClip.cs @@ -3,8 +3,7 @@ using System.Net.WebSockets; using System.Text; using NAudio.CoreAudioApi; using NAudio.Wave; -using NAudio.Wave.Asio; -using System.IO; +#pragma warning disable CA1416 namespace _2dxAutoClip { @@ -220,7 +219,12 @@ namespace _2dxAutoClip { if (_useAsio) { - StartAsioAudioRecording(songName); + var staThread = new Thread(() => + { + StartAsioAudioRecording(songName); + }); + staThread.SetApartmentState(ApartmentState.STA); + staThread.Start(); } else { @@ -228,6 +232,7 @@ namespace _2dxAutoClip } } + private static void StartWasapiAudioRecording(string songName) { try @@ -261,7 +266,7 @@ namespace _2dxAutoClip Directory.CreateDirectory(Path.GetDirectoryName(_audioFilePath)!); _asioSource = new AsioOut(0); - _asioSource.InitRecordAndPlayback(null, 2, 48000); + _asioSource.InitRecordAndPlayback(null, 0, 48000); _writer = new WaveFileWriter(_audioFilePath, new WaveFormat(44100, 16, 2));