如何将2个WAV文件混合在一起? [英] How to Mix 2 wav files together?

查看:515
本文介绍了如何将2个WAV文件混合在一起?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试记录输入并将其与歌曲(未连接)合并在一起.我有我在听歌曲时录制的吉他,并且想将吉他放在歌曲上(例如响度). 有什么办法吗?如果无法实时混音-录制后是否可以合并它们?就像我录制吉他后,现在录制了一个WAV文件一样,我想将2个WAV文件混合在一起. 多数民众赞成在输入设备:

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 song (like audcaity). Is there any way for doing it? If its not possible on real time mixing - is it possible to merge them after i recorded? Like after I recorded the guitar and now its a wav file and i want to mix 2 wav files together. Thats the input device:

 private void Capture()
    {
        input = new WasapiCapture((MMDevice)inputCombo.SelectedItem);
        bufferedWaveProvider = new BufferedWaveProvider(input.WaveFormat);
        input.DataAvailable += WaveInOnDataAvailable;
        input.StartRecording();
        write = new WaveFileWriter(System.IO.Path.GetTempFileName(), input.WaveFormat);
    }

 private void WaveInOnDataAvailable(object sender, WaveInEventArgs e)
    {
        bufferedWaveProvider.AddSamples(e.Buffer, 0, e.BytesRecorded);
        write.Write(e.Buffer, 0, e.BytesRecorded);
        write.Flush();
    }

我不想将其写入空白文件,而是要将其写入已经存在的wav文件中,而不要覆盖它. MixingSampleProvider是否有可能?

Instead of writing it into a blank file i want to write it into a wav file thats already exists and not override it. Is it maybe possible with the MixingSampleProvider?

推荐答案

要使用MixingSampleProvider混合多个ISampleProvider源,可以执行以下操作:

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

此处SignalGenerator具有Gain属性,该属性可以指定在混音中应该有多响.

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);
        }
    }
}

这篇关于如何将2个WAV文件混合在一起?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆