NAudio 问题 - 管理相继播放​​的多个声音文件

发布于 2024-09-27 05:08:24 字数 2253 浏览 0 评论 0原文

我一直在尝试解决一个困扰了我几周的问题!基本上,我正在开发的软件可以录制音频,然后播放。该软件可以录制多个声音文件,然后逐个播放它们(使其看起来像是1个连续的声音文件)。然而,我遇到的问题是,从第二个声音文件开始,第二个、第三个、第四个(依此类推)文件的顶部似乎有一个“滴答声”。

此滴答声是第一个声音文件的最后几毫秒。我所说的“滴答声”类似于黑胶唱片快速跳动的声音。

到目前为止,我还没有找到问题的根源,是否有人对可能导致此问题的原因有任何想法?

谢谢

编辑:添加了下面的一些方法。

好的,那么下面的方法就是重播方法。

public override void Replay(long time)
    {
        if(this.StartTime <= time && this.EndTime >= time && (Speed >= 0.95 && Speed <= 1.05))
        {
            if (!locked)
            {
                locked = true;
                //close the previous stream
                CloseWaveOut();
                //open the file
                waveOut = new NativeDirectSoundOut(latency);
                mainOutputStream = CreateInputStream(outputFilename);
                if (waveOut != null && mainOutputStream != null)
                {
                    //set the time position
                    long offset = time - StartTime;
                    if (offset > 0)
                    {
                        mainOutputStream.CurrentTime = TimeSpan.FromMilliseconds(Convert.ToDouble(offset));
                    }
                    //CurrentTime = TimeSpan.FromMilliseconds(Convert.ToDouble(time - StartTime));
                    waveOut.Init(mainOutputStream);
                    ((WaveChannel32)mainOutputStream).Volume = Volume;
                    Console.WriteLine("waveOut Playing");  // Debugging purposes
                    waveOut.Play();
                }
            }
        }
    }

下面的方法是记录方法:

        public override void Record(long time)
    {
        if (waveInStream == null && writer == null && !recorded)
        {
            //for record 
            writer = new WaveFileWriter(outputFilename, recordingFormat);
            waveInStream = new WaveInStream(deviceNumber, recordingFormat, null);
            waveInStream.DataAvailable += new EventHandler<WaveInEventArgs>(waveInStream_DataAvailable);

            waveInStream.StartRecording();
            this.StartTime = time;

            Console.Out.WriteLine("Record Method called"); // Debugging Purposes
        }
    }

I've been trying to solve a problem which I have been stuck for weeks on! Basically, the software I am developing can record audio, and then play it back. The software can record multipule sound files, and then play them one after the other (making it seem like it is 1 continious sound file). However, the problem I am having is that from the second sound file on, there seems to be a 'ticking' over the top of the second, third, fourth (and so on) file.

This ticking is the last few milliseconds of the first sound file. The 'ticking' I am refering to is similar to the sound of a vinyl record skipping very fast.

So far I haven't been able to find the root of the problem, does anyone have any ideas in regards to what could be causing this?

Thanks

EDIT: Added some methods below.

Ok, so the following method is the replay method.

public override void Replay(long time)
    {
        if(this.StartTime <= time && this.EndTime >= time && (Speed >= 0.95 && Speed <= 1.05))
        {
            if (!locked)
            {
                locked = true;
                //close the previous stream
                CloseWaveOut();
                //open the file
                waveOut = new NativeDirectSoundOut(latency);
                mainOutputStream = CreateInputStream(outputFilename);
                if (waveOut != null && mainOutputStream != null)
                {
                    //set the time position
                    long offset = time - StartTime;
                    if (offset > 0)
                    {
                        mainOutputStream.CurrentTime = TimeSpan.FromMilliseconds(Convert.ToDouble(offset));
                    }
                    //CurrentTime = TimeSpan.FromMilliseconds(Convert.ToDouble(time - StartTime));
                    waveOut.Init(mainOutputStream);
                    ((WaveChannel32)mainOutputStream).Volume = Volume;
                    Console.WriteLine("waveOut Playing");  // Debugging purposes
                    waveOut.Play();
                }
            }
        }
    }

The following method is the record method:

        public override void Record(long time)
    {
        if (waveInStream == null && writer == null && !recorded)
        {
            //for record 
            writer = new WaveFileWriter(outputFilename, recordingFormat);
            waveInStream = new WaveInStream(deviceNumber, recordingFormat, null);
            waveInStream.DataAvailable += new EventHandler<WaveInEventArgs>(waveInStream_DataAvailable);

            waveInStream.StartRecording();
            this.StartTime = time;

            Console.Out.WriteLine("Record Method called"); // Debugging Purposes
        }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不及他 2024-10-04 05:08:24

我建议不要关闭和打开 WaveOut,而是始终打开一个 WaveOut 实例。创建一个新的 IWaveProvider,其 Read 方法首先返回第一个 WAV 文件中的所有数据,然后返回第二个 WAV 文件中的所有数据。

为了找到滴答声的来源,我首先在 Windows Media Player 中仔细检查录制的 WAV 文件本身是否有滴答声。

I would recommend not closing and opening WaveOut, but having a single WaveOut instance always open. Create a new IWaveProvider whose Read method first returns all the data from the first WAV file, and then all the data from the second.

To locate the source of the ticking, I would first double check in Windows Media Player that the recorded WAV file itself doesn't have the ticking noise in it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文