How to Mix 2 wav files together?

前端 未结 2 1366
-上瘾入骨i
-上瘾入骨i 2021-01-25 03:08

I\'m trying to record an input and merge it together with a song (not concatenate). I have a guitar that i recorded while listening to a song and I want to put the guitar on the

2条回答
  •  执笔经年
    2021-01-25 03:34

    To mix multiple ISampleProvider sources using a MixingSampleProvider, you can do the following:

    Here SignalGenerator has a Gain property which allows to specify how loud it should be in the mix.

    using System;
    using NAudio.Wave;
    using NAudio.Wave.SampleProviders;
    
    namespace ConsoleApplication1
    {
        internal class Program
        {
            private static void Main(string[] args)
            {
                ISampleProvider provider1 = new SignalGenerator
                {
                    Frequency = 1000.0f,
                    Gain = 0.5f
                };
    
                ISampleProvider provider2 = new SignalGenerator
                {
                    Frequency = 1250.0f,
                    Gain = 0.5f
                };
    
                var takeDuration1 = TimeSpan.FromSeconds(5); // otherwise it would emit indefinitely
                var takeDuration2 = TimeSpan.FromSeconds(10);
    
                var sources = new[]
                {
                    provider1.Take(takeDuration1),
                    provider2.Take(takeDuration2)
                };
    
                var mixingSampleProvider = new MixingSampleProvider(sources);
    
                var waveProvider = mixingSampleProvider.ToWaveProvider();
    
                WaveFileWriter.CreateWaveFile("test.wav", waveProvider);
            }
        }
    }
    

提交回复
热议问题