SlimDX 录音(OK)然后播放(问题!)

发布于 2024-11-11 13:51:19 字数 1237 浏览 2 评论 0原文

我目前正在使用 directsound 来录制音频的浮点数组。

现在我想使用 XAudio2 (也有 SlimDX)播放该浮点数组,但我不确定该怎么做,因为 SlimDX 的示例示例播放 .wav 文件。

他们是这样做的:

        XAudio2 device = new XAudio2();
        MasteringVoice masteringVoice = new MasteringVoice(device);

        var s = System.IO.File.OpenRead(fileName);
        WaveStream stream = new WaveStream(s);
        s.Close();

        AudioBuffer buffer = new AudioBuffer();
        buffer.AudioData = stream;
        buffer.AudioBytes = (int)stream.Length;
        buffer.Flags = BufferFlags.EndOfStream;

        SourceVoice sourceVoice = new SourceVoice(device, stream.Format);
        sourceVoice.SubmitSourceBuffer(buffer);
        sourceVoice.Start();

        // loop until the sound is done playing
        while (sourceVoice.State.BuffersQueued > 0)
        {
            if (GetAsyncKeyState(VK_ESCAPE) != 0)
                break;

            Thread.Sleep(10);
        }

        // wait until the escape key is released
        while (GetAsyncKeyState(VK_ESCAPE) != 0)
            Thread.Sleep(10);

        // cleanup the voice
        buffer.Dispose();
        sourceVoice.Dispose();
        stream.Dispose();

基本上,我想知道如何使用 slimDX 播放浮点数组?

提前致谢

I'm currently getting a float array using directsound to record audio.

Now I would like to play that float array using XAudio2 (SlimDX also), but I'm not sure what to do since the sample example from SlimDX plays a .wav file.

here is how they do this:

        XAudio2 device = new XAudio2();
        MasteringVoice masteringVoice = new MasteringVoice(device);

        var s = System.IO.File.OpenRead(fileName);
        WaveStream stream = new WaveStream(s);
        s.Close();

        AudioBuffer buffer = new AudioBuffer();
        buffer.AudioData = stream;
        buffer.AudioBytes = (int)stream.Length;
        buffer.Flags = BufferFlags.EndOfStream;

        SourceVoice sourceVoice = new SourceVoice(device, stream.Format);
        sourceVoice.SubmitSourceBuffer(buffer);
        sourceVoice.Start();

        // loop until the sound is done playing
        while (sourceVoice.State.BuffersQueued > 0)
        {
            if (GetAsyncKeyState(VK_ESCAPE) != 0)
                break;

            Thread.Sleep(10);
        }

        // wait until the escape key is released
        while (GetAsyncKeyState(VK_ESCAPE) != 0)
            Thread.Sleep(10);

        // cleanup the voice
        buffer.Dispose();
        sourceVoice.Dispose();
        stream.Dispose();

Basically, what I would like to know is how to play a float array using slimDX?

Thanks in advance

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

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

发布评论

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

评论(1

硬不硬你别怂 2024-11-18 13:51:19

我不是音频方面的专家,但我知道您可以创建 IeeeFloat 的 WaveFormat。填写所有其他信息,然后将数据写入 DataStream 并将其提供给 AudioBuffer。然后就可以正常调用Submit了。

I'm not an expert on audio stuff, but I do know that you can create a WaveFormat of IeeeFloat. Fill in all the other information, and then write your data to a DataStream and give that to the AudioBuffer. Then you can call Submit as normal.

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