Skip to content

Commit

Permalink
try record
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyovelt committed Sep 24, 2021
1 parent 0c31f5d commit 812b4e9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
10 changes: 7 additions & 3 deletions Native-Modem/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@

namespace Native_Modem
{
class Program
class Program
{

[STAThread]
static void Main(string[] args)
{
var Recorder = new Recorder();
Recorder.setupRecordArgs();
var recorder = new Recorder(0);
recorder.setupRecordArgs(0, 1, 48000);
recorder.startRecord();
Console.ReadLine();
recorder.stopRecord();
}
}
}
33 changes: 29 additions & 4 deletions Native-Modem/Recorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,27 @@ public class Recorder
{
private AsioOut asioOut;
private string[] asioDriverName;
private IWaveProvider iWaveProvider;
private WaveFileWriter writer;
public Recorder(int DriverNameIndex =0 )
{
asioOut = new AsioOut(listAsioDricerNames(DriverNameIndex));
Console.WriteLine("Choosing the Sound Card: {0}", asioDriverName[DriverNameIndex]);
var samplesOutWav = @"..\..\..\testOutput";
writer = new WaveFileWriter(samplesOutWav, new WaveFormat(16000, 24, 1));
}

~Recorder()
{
asioOut.Dispose();
}


public void setupRecordArgs(int inputChannelIndex = 0, int recordChannelCount = 1, int sampleRate = 44100 )
public void setupRecordArgs(int inputChannelIndex = 0, int recordChannelCount = 1, int sampleRate = 48000 )
{
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);

asioOut.InitRecordAndPlayback(null, recordChannelCount, sampleRate);
}

private string listAsioDricerNames(int DriverNameIndex = 0)
Expand All @@ -38,6 +43,26 @@ private string listAsioDricerNames(int DriverNameIndex = 0)
return asioDriverName[DriverNameIndex];
}

void OnAsioOutAudioAvailable(object sender, AsioAudioAvailableEventArgs e)
{
var samples = e.GetAsInterleavedSamples();
//foreach (var i in samples)
//{
// Console.Write("{0} ", i);
//}
writer.WriteSamples(samples, 0, samples.Length);
}

public void startRecord()
{
asioOut.AudioAvailable += OnAsioOutAudioAvailable;
asioOut.Play(); // start recording
}

public void stopRecord()
{
asioOut.Stop();
}

}
}
Binary file added Native-Modem/testOutput.wav
Binary file not shown.

0 comments on commit 812b4e9

Please sign in to comment.