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

时间:2011-05-31 14:18:10

标签: record playback slimdx

我目前正在使用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播放浮点数组?

提前致谢

1 个答案:

答案 0 :(得分:0)

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