开发者

SlimDX Recording(OK) then playing (Problem!)

开发者 https://www.devze.com 2023-03-09 06:11 出处:网络
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 fr

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.Cl开发者_Python百科ose();

        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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号