I am currently working on a SR. design project which is a windows forms app which will allow for users to plug in their guitar and create distortions in real time and play it with input and output, and auto tab it into ASCII tabs. Currently I am trying to get the real time listening portion working, I have the recording and implementation of distortions working just fine just having some issues using ASIO. I've looked at this post How to record and playback with NAudio using AsioOut but it was not of much help with my issue, here is my code:
private BufferedWaveProvider buffer;
private AsioOut input;
private AsioOut output;
private void listenBtn_Click(object sender, EventArgs e)
{
input = new AsioOut(RecordInCbox.SelectedIndex);
WaveFormat format = new WaveFormat();
buffer = new BufferedWaveProvider(format);
buffer.DiscardOnBufferOverflow = true;
input.InitRecordAndPlayback(buffer, 1, 44100);
input.AudioAvailable += new EventHandler<AsioAudioAvailableEventArgs>(AudioAvailable);
//output = new AsioOut(RecordInCbox.SelectedIndex);
//output.Init(buffer);
input.Play();
//output.Play();
}
public void AudioAvailable(object sender, AsioAudioAvailableEventArgs e)
{
byte[] buf = new byte[e.SamplesPerBuffer];
e.WrittenToOutputBuffers = true;
for (int i = 0; i < e.InputBuffers.Length; i++)
{
Array.Copy(e.InputBuffers, e.OutputBuffers, 1);
Marshal.Copy(e.InputBuffers[i], buf, 0, e.SamplesPerBuffer);
buffer.AddSamples(buf, 0, buf.Length);
}
}
Currently it is getting the audio and pushing it into the buffer but the output is not working. I am able to get it to play the guitar if I set the recording setting to Listen on windows but feel this is unnecessary as how I want to be able to perform my distortion and hear that as the output. Thanks!