Properly instantiate ASIO recording

This commit is contained in:
Mercurio 2024-09-09 21:12:20 +02:00
parent 390dc02117
commit f62c51729f

View file

@ -3,8 +3,7 @@ using System.Net.WebSockets;
using System.Text; using System.Text;
using NAudio.CoreAudioApi; using NAudio.CoreAudioApi;
using NAudio.Wave; using NAudio.Wave;
using NAudio.Wave.Asio; #pragma warning disable CA1416
using System.IO;
namespace _2dxAutoClip namespace _2dxAutoClip
{ {
@ -219,8 +218,13 @@ namespace _2dxAutoClip
private static void StartAudioRecording(string songName) private static void StartAudioRecording(string songName)
{ {
if (_useAsio) if (_useAsio)
{
var staThread = new Thread(() =>
{ {
StartAsioAudioRecording(songName); StartAsioAudioRecording(songName);
});
staThread.SetApartmentState(ApartmentState.STA);
staThread.Start();
} }
else else
{ {
@ -228,6 +232,7 @@ namespace _2dxAutoClip
} }
} }
private static void StartWasapiAudioRecording(string songName) private static void StartWasapiAudioRecording(string songName)
{ {
try try
@ -261,7 +266,7 @@ namespace _2dxAutoClip
Directory.CreateDirectory(Path.GetDirectoryName(_audioFilePath)!); Directory.CreateDirectory(Path.GetDirectoryName(_audioFilePath)!);
_asioSource = new AsioOut(0); _asioSource = new AsioOut(0);
_asioSource.InitRecordAndPlayback(null, 2, 48000); _asioSource.InitRecordAndPlayback(null, 0, 48000);
_writer = new WaveFileWriter(_audioFilePath, new WaveFormat(44100, 16, 2)); _writer = new WaveFileWriter(_audioFilePath, new WaveFormat(44100, 16, 2));