nAudio FadeInOutSampleProvider无效

时间:2015-06-09 20:52:16

标签: c# naudio

我正在编写一个程序,它将从另一个应用程序创建的文件夹中获取一系列.wav文件,从每个示例的开头和结尾修剪指定的时间,并将该操作的结果复制到临时夹。从那里开始,我想获取每个文件,并在文件末尾应用少量淡入淡出,以使文件之间的转换更平滑(之后每个文件将合并在一起),并将该操作的结果输出到另一个临时文件夹,程序将合并该文件夹中的文件以创建最终输出。不幸的是,我无法让FadeInOutSampleProvider工作。

foreach (string file in files) {
    try {
        byte[] buffer = new byte[1024];
        AudioFileReader afr = new AudioFileReader(tempfile2);
        FadeInOutSampleProvider fade = new FadeInOutSampleProvider(afr);

        fade.BeginFadeOut(notes[run2].Length - 100);

        var stwp = new NAudio.Wave.SampleProviders.SampleToWaveProvider(fade);
        WaveFileWriter.CreateWaveFile(tempfile, stwp);

        run2++;
    }
    catch (Exception) { }
}

修改

以下是更多代码:

public void PlaybackTemp(string tempDir, Sheet playbackSheet) {
    string[] files = Directory.GetFiles(tempDir);
    string tempdir = "";

    // Generate trimmed files ready for splicing 
    tempdir = GenEditedFiles(files, playbackSheet.notes);

    // Show the output in explorer if debug mode is on
    if (debug) {
        Process p = new Process();
        p.StartInfo.FileName = tempdir;
        p.Start();
    }

    // Splice the files
    ConcatenateWav(tempdir + "\\render.wav", Directory.GetFiles(tempdir));

    // Play back resulting file
    new System.Media.SoundPlayer(tempdir + "\\render.wav").Play();
}

private string GenEditedFiles(string[] files, List<Note> notes) {
    string tempdir = FluidSys.FluidSys.CreateTempDir();
    string tempdir2 = FluidSys.FluidSys.CreateTempDir();
    string tempfile = "";
    string tempfile2 = "";

    int run = 0;
    int run2 = 0;

    // Trim each note
    foreach (string file in files) {
        tempfile = tempdir + "\\" + run.ToString() + ".wav";
        tempfile2 = tempdir + "\\" + run.ToString() + "0.wav";

        WavFileUtils.TrimWavFile(file, tempfile2, TimeSpan.FromMilliseconds(notes[run].VoiceProperties.Start),
            TimeSpan.FromMilliseconds(notes[run].VoiceProperties.End));

        run++;
    }

    foreach (string file in files) {
        try {
            byte[] buffer = new byte[1024];
            AudioFileReader afr = new AudioFileReader(tempfile2);
            FadeInOutSampleProvider fade = new FadeInOutSampleProvider(afr);

            fade.BeginFadeOut(notes[run2].Length - 10);

            var stwp = new NAudio.Wave.SampleProviders.SampleToWaveProvider(fade);
            WaveFileWriter.CreateWaveFile(tempfile, stwp);

            run2++;
        }
        catch (Exception) { }
    }

    return tempdir;
}

0 个答案:

没有答案