C# 4.0 如何使用SlimDX.DirectSound播放波形文件?

C# 4.0 如何使用SlimDX.DirectSound播放波形文件?,c#-4.0,directx,slimdx,managed-directx,C# 4.0,Directx,Slimdx,Managed Directx,我是SlimDX的第一名 我正试着播放一个波形文件。但它不起作用 可能有什么问题吗 使用WinForms、SlimDX.DirectSound、SlimDX.multimedia,我做到了 必须写入缓冲区 public partial class Form1 : Form { SecondarySoundBuffer m_DSoundBuffer; DirectSound m_DirectSound; string fileName = @"F:\\guitar-clas

我是SlimDX的第一名

我正试着播放一个波形文件。但它不起作用

可能有什么问题吗

使用WinForms、SlimDX.DirectSound、SlimDX.multimedia,我做到了

必须写入缓冲区

public partial class Form1 : Form
{
    SecondarySoundBuffer m_DSoundBuffer;
    DirectSound m_DirectSound;
    string fileName = @"F:\\guitar-classical-E-octave0.wav";
    public void setting()
    {
        WaveStream waveFile = new WaveStream(fileName);
        SoundBufferDescription desc = new SoundBufferDescription();
        desc.SizeInBytes = (int)waveFile.Length;
        desc.Flags = BufferFlags.None;
        desc.Format = waveFile.Format;
        m_DirectSound = new DirectSound();
        m_DirectSound.SetCooperativeLevel(this.Handle, CooperativeLevel.Priority);
        m_DSoundBuffer = new SecondarySoundBuffer(m_DirectSound, desc);
    }
    public Form1()
    {
        InitializeComponent(); 
    }
    private void button1_Click(object sender, EventArgs e)
    {
        setting();
        m_DSoundBuffer.Play(0, 0);
    }


}

声音是古老的。你应该使用XAudio2,你可以使用SlimDX。
public void setting()
    {
        m_DirectSound = new DirectSound();
        m_DirectSound.SetCooperativeLevel(this.Handle, CooperativeLevel.Priority);
        m_DirectSound.IsDefaultPool = false;

        using (WaveStream waveFile = new WaveStream(fileName))
        {

            SoundBufferDescription desc = new SoundBufferDescription();
            desc.SizeInBytes = (int)waveFile.Length;
            desc.Flags = BufferFlags.None;
            desc.Format = waveFile.Format;

            m_DSoundBuffer = new SecondarySoundBuffer(m_DirectSound, desc);
            byte[] data = new byte[desc.SizeInBytes];
            waveFile.Read(data, 0, (int)waveFile.Length);
            m_DSoundBuffer.Write(data, 0, LockFlags.None);
        }