This project has moved and is read-only. For the latest updates, please go here.

Visualization/Waveforms with mixed wav files

Oct 24, 2015 at 4:22 AM
So I've started using NAudio and it's AWESOME. I had an application in mind and started using Naudio and everything is working perfectly. I've only run into one issue: I'm taking lots of small wav file samples and concatenating them, truncatiing, adding extra blank audio, etc to create my music. I tried out the WaveForm Demo to create a visualization and it worked great for a single wave file.

Then I got really advanced and started mixing wav files together. The mixing demo worked great for playing the different wav files, but then I realized... getting that Visualization to work might be tough when mixing. I can go through the waveform demo where it reads through an AudioFilereader and finds the max value of each sample and then I could loop through the other wave files, making sure the buffer size is the same and comparing the max values to the previous max values. BUT before I go through all that I guess the one question I wanted to ask to make my life easier would be.... Can the mixing sample provider, instead of just PLAYING multiple inputs to waveout... can it actually OUTPUT the audio of the mixed wav files to one single wav file? IF that's possible I could save myself a lot of trouble and when rendering the waveform, just read through the one mixed/master wav file.
Oct 27, 2015 at 3:26 AM
BAM. Solved:
    private WaveFileReader reader1;
    private WaveFileReader reader2;
    private WaveFileReader reader3;
    private WaveFileReader readerMaster;



string myinfile1 = "C:\samples\00test\test1.wav";
string myinfile2 = "C:\samples\00test\test2.wav";
string myinfile3 = "C:\samples\00test\test3.wav";
string mymainfile = "C:\samples\00test\testmaster.wav";
       reader1 = new WaveFileReader(myfile1);
        reader2 = new WaveFileReader(myfile2);
        reader3 = new WaveFileReader(myfile3);
        WaveChannel32 stream1 = new WaveChannel32(reader1);
        WaveChannel32 stream2 = new WaveChannel32(reader2);
        WaveChannel32 stream3 = new WaveChannel32(reader3);

        WaveMixerStream32 mixer = new WaveMixerStream32();
        mixer.AddInputStream(stream1);
        mixer.AddInputStream(stream2);
        mixer.AddInputStream(stream3);

        Wave32To16Stream wavmixer = new Wave32To16Stream(mixer);

        WaveFileWriter.CreateWaveFile(mymainfile, wavmixer);
Oct 28, 2015 at 12:33 PM
Great, glad you got it working. You could also have used MixingSampleProvider and CreateWaveFile16