Mixing multiple wave files...

Jun 26, 2008 at 3:19 AM
Edited Jun 26, 2008 at 3:42 AM

I'm not 100% sure NAudio can do this functionality right now but... 

Is there some sample code for using NAudio to :

  1) mix multiple wave files simultaneously for audio (taking multiple wave files as input and mixing simultaneously to soundcard via ASIO or whatever driver)

  2) mix multiple wave files for file output (taking the current "mix" from #1 and then exporting the whole mix to a single wav file?)

The goal here is obviously to see if NAudio can be used to create an audio mixer that will allow the user to mix multiple wav files in realtime to adjust volumes, panning, etc and allow the user to export the "current mix" to a wav file.

Also, how feasible is this to do this with NAudio?  Will NAudio work ok with 5-10 wave files simultaneously?   How about 1-20, 1-30, 1-50?  I know it's impossible to tell without serious performance testing, but just some thoughts ideas from you guys would be helpful.  Some of my projects in Sonar have 50+ tracks... 

Does it matter which sound driver is used when doing this real-time audio mixing?  Is using an ASIO driver the most optimum driver to use for this real-time mixing scenario because it has the lowest latency of all the driver types? 

I'm a relative newbie to the "coding" side of digital audio obviously... (though I am an experienced .NET programmer)  Thanks for any help and your thoughts!

Alex

PS-Great job with NAudio by the way!  I look forward to seeing where you guys take it.  I'm especially impressed with the ASIO (low latency) support and MIDI reading/writing from .NET.  :)  I also love that you've made it open source and put it on CodePlex.  Really cool!  Please don't stop working on it.  :)

Coordinator
Jun 26, 2008 at 7:27 AM
Hi Alex,
Yes NAudio can mix multiple streams together. Have a look at this post on my blog for a bit more information:
http://mark-dot-net.blogspot.com/2008/06/naudio-wave-stream-architecture.html
The MixDiff application currently uses a mixer, although it only plays one of its inputs at a time, so you could look at the code.

Streams that are mixed can just as easily be written to a WAV file as to the soundcard. Look at the WavFileWriter class for creating WAV files. NAudio demo shows WAV files being created in the ACM and WaveIn recording pages.

As for performance, I have used NAudio to mix over 30 streams together on a fairly low spec PC, but they were only 8kHz audio. You should not expect performance to be anything like what you will get in SONAR, due to limitations of .NET and the fact that NAudio has not been as heavily optimised as we would like.

The ASIO output driver is still in its early stages and is not working with every soundcard we have tested yet. Let us know if you get it working, and what soundcard you are using.

The most reliable output driver at the moment is WaveOut. If you are using Vista, you should experiment to see whether WASAPI or ASIO give you the best performance.

Mark

alexrandall2005 wrote:

I'm not 100% sure NAudio can do this functionality right now but... 

Is there some sample code for using NAudio to :

  1) mix multiple wave files simultaneously for audio (taking multiple wave files as input and mixing simultaneously to soundcard via ASIO or whatever driver)

  2) mix multiple wave files for file output (taking the current "mix" from #1 and then exporting the whole mix to a single wav file?)

The goal here is obviously to see if NAudio can be used to create an audio mixer that will allow the user to mix multiple wav files in realtime to adjust volumes, panning, etc and allow the user to export the "current mix" to a wav file.

Also, how feasible is this to do this with NAudio?  Will NAudio work ok with 5-10 wave files simultaneously?   How about 1-20, 1-30, 1-50?  I know it's impossible to tell without serious performance testing, but just some thoughts ideas from you guys would be helpful.  Some of my projects in Sonar have 50+ tracks... 

Does it matter which sound driver is used when doing this real-time audio mixing?  Is using an ASIO driver the most optimum driver to use for this real-time mixing scenario because it has the lowest latency of all the driver types? 

I'm a relative newbie to the "coding" side of digital audio obviously... (though I am an experienced .NET programmer)  Thanks for any help and your thoughts!

Alex

PS-Great job with NAudio by the way!  I look forward to seeing where you guys take it.  I'm especially impressed with the ASIO (low latency) support and MIDI reading/writing from .NET.  :)  I also love that you've made it open source and put it on CodePlex.  Really cool!  Please don't stop working on it.  :)




Jun 26, 2008 at 7:18 PM

Helllo Mark,

  Thanks very much for your detailed reply and your honest answers. Keep up the great work as I will keep checking out NAudio in the future see how you guys are progressing.

  Alex


markheath wrote:
Hi Alex,
Yes NAudio can mix multiple streams together. Have a look at this post on my blog for a bit more information:
http://mark-dot-net.blogspot.com/2008/06/naudio-wave-stream-architecture.html
The MixDiff application currently uses a mixer, although it only plays one of its inputs at a time, so you could look at the code.

Streams that are mixed can just as easily be written to a WAV file as to the soundcard. Look at the WavFileWriter class for creating WAV files. NAudio demo shows WAV files being created in the ACM and WaveIn recording pages.

As for performance, I have used NAudio to mix over 30 streams together on a fairly low spec PC, but they were only 8kHz audio. You should not expect performance to be anything like what you will get in SONAR, due to limitations of .NET and the fact that NAudio has not been as heavily optimised as we would like.

The ASIO output driver is still in its early stages and is not working with every soundcard we have tested yet. Let us know if you get it working, and what soundcard you are using.

The most reliable output driver at the moment is WaveOut. If you are using Vista, you should experiment to see whether WASAPI or ASIO give you the best performance.

Mark

alexrandall2005 wrote:

I'm not 100% sure NAudio can do this functionality right now but... 

Is there some sample code for using NAudio to :

  1) mix multiple wave files simultaneously for audio (taking multiple wave files as input and mixing simultaneously to soundcard via ASIO or whatever driver)

  2) mix multiple wave files for file output (taking the current "mix" from #1 and then exporting the whole mix to a single wav file?)

The goal here is obviously to see if NAudio can be used to create an audio mixer that will allow the user to mix multiple wav files in realtime to adjust volumes, panning, etc and allow the user to export the "current mix" to a wav file.

Also, how feasible is this to do this with NAudio?  Will NAudio work ok with 5-10 wave files simultaneously?   How about 1-20, 1-30, 1-50?  I know it's impossible to tell without serious performance testing, but just some thoughts ideas from you guys would be helpful.  Some of my projects in Sonar have 50+ tracks... 

Does it matter which sound driver is used when doing this real-time audio mixing?  Is using an ASIO driver the most optimum driver to use for this real-time mixing scenario because it has the lowest latency of all the driver types? 

I'm a relative newbie to the "coding" side of digital audio obviously... (though I am an experienced .NET programmer)  Thanks for any help and your thoughts!

Alex

PS-Great job with NAudio by the way!  I look forward to seeing where you guys take it.  I'm especially impressed with the ASIO (low latency) support and MIDI reading/writing from .NET.  :)  I also love that you've made it open source and put it on CodePlex.  Really cool!  Please don't stop working on it.  :)