Skip to content

Commit

Permalink
fix STAThread
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyovelt committed Sep 24, 2021
1 parent 755bfa6 commit 0c31f5d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
11 changes: 7 additions & 4 deletions Native-Modem/Program.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
using System;
using Microsoft.Win32;
using NAudio.Wave;
using NAudio.Wave.Asio;
using System;
using System.Runtime.InteropServices;

namespace Native_Modem
{


class Program
{
[STAThread]
static void Main(string[] args)
{
var Recorder = new Recorder();
Recorder.printASIODriver();
Recorder.setupRecordArgs();
}
}
}
37 changes: 28 additions & 9 deletions Native-Modem/Recorder.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,43 @@
using NAudio.Wave;
using Microsoft.Win32;
using NAudio.Wave;
using NAudio.Wave.Asio;
using System;
using System.Runtime.InteropServices;

namespace Native_Modem
{
public class Recorder
{
public Recorder(int AsioDriverIndex = 0)
private AsioOut asioOut;
private string[] asioDriverName;
private IWaveProvider iWaveProvider;
public Recorder(int DriverNameIndex =0 )
{
asioOut = new AsioOut(listAsioDricerNames(DriverNameIndex));
Console.WriteLine("Choosing the Sound Card: {0}", asioDriverName[DriverNameIndex]);

}


public void setupRecordArgs(int inputChannelIndex = 0, int recordChannelCount = 1, int sampleRate = 44100 )
{
printASIODriver();
var drivernames = AsioOut.GetDriverNames();
var asioOut = new AsioOut(drivernames[AsioDriverIndex]);
var inputChannels = asioOut.DriverInputChannelCount;
asioOut.InputChannelOffset = inputChannelIndex;
Console.WriteLine("We have {0} input recording Channels, and we are choosing the Channel {1}, recordChannelCount {2}, sampleRate {3}", inputChannels, inputChannelIndex, recordChannelCount, sampleRate);
asioOut.InitRecordAndPlayback(iWaveProvider, recordChannelCount, sampleRate);

}

public void printASIODriver()
private string listAsioDricerNames(int DriverNameIndex = 0)
{
var drivernames = AsioOut.GetDriverNames();
foreach (var drivername in drivernames)
asioDriverName = AsioOut.GetDriverNames();
foreach(var name in asioDriverName)
{
Console.WriteLine(drivername);
Console.WriteLine(name);
}
return asioDriverName[DriverNameIndex];
}


}
}

0 comments on commit 0c31f5d

Please sign in to comment.