I'm trying to make a very simple DAW in C# with NAudio and winforms. The goal of the program at this stage is to be able to record from a microphone while playing back a couple of audio files. The project so far is a combination of the ASIO-samples that came with NAudio and information on the Internet.
I have one audiofilereader-object for each audiofile I want to play:
reader = new AudioFileReader("Audio 8_01.wav");
reader2 = new AudioFileReader("Audio 9_04.wav");
reader3 = new AudioFileReader("Click.L.wav");
reader4 = new AudioFileReader("Click.R.wav");
When pressing the play-button the audio-clips should start playing and recording should start on channel 1:
private void Play()
{
// allow change device
if (asioOut != null &&
(asioOut.DriverName != GetDriverOutComboBoxText() ||
asioOut.ChannelOffset != 0))
{
asioOut.Dispose();
asioOut = null;
}
int recordChannelCount = 0;
mix = new MixingWaveProvider32();
//Console.WriteLine("CHannels: " + mix.WaveFormat.Channels );
mix.AddInputStream(reader);
mix.AddInputStream(reader2);
mix.AddInputStream(reader3);
mix.AddInputStream(reader4);
Console.WriteLine("CHannels: " + mix.WaveFormat.Channels);
if (asioOut == null)
{
asioOut = new AsioOut(GetDriverOutComboBoxText());
recordChannelCount = 1;
asioOut.ChannelOffset = 0;
asioOut.InitRecordAndPlayback(mix , recordChannelCount, 96000);
asioOut.AudioAvailable += OnAsioOutAudioAvailable;
}
outFileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".wav");
Console.WriteLine("File: " + outFileName);
writer = new WaveFileWriter(outFileName, new WaveFormat(96000, recordChannelCount));
reader.Position = 0;
asioOut.Play();
timer1.Enabled = true;
//SetButtonStates();
}
I use a mixingwaveprovider to be able to play multiple files at the same time. It works somewhat, if the audiofiles in the readers are stereo audio I get sound in both speakers and the mix.WaveFormat.Channels is 2 before and after adding the file-readers to the mixer. If the files are mono-audio they all get played in either left or right speaker depending on the asioOut.ChannelOffset being set to zero or one. I don't know how to set to which channel each audiofile is played, and I want to be able to adjust panning, ie. a mono-sound being played in both speakers to some degrees. I feel there is something that I'm missing...I have seen the Patchbay-example program that Mark Heath has written but I don't really know how to apply that to my project. All audio files are in the same format by the way.
The other problem that might be related, otherwise I'll post a new question, is that the audio being recorded(which works fine by the way) is not audible in the speakers during recording, ie. no monitoring during recording. How can I send this signal being recorded to the same mixer as the files are being sent to?
Thanks!