值不在Microsoft.DirectX.DirectSound的预期范围内;

时间:2013-03-14 13:15:58

标签: c# directx directsound

我正在使用托管代码开发音乐播放器,我正在使用Microsoft.DirectX.DirectSound。当我调用play方法时,我收到此错误“值不在预期范围内”。所以,问题只适用于24位WAV文件。这就是例外的原因。对于16位文件工作正常。任何想法如何使其适用于24位文件?

谢谢!

    using Microsoft.DirectX.DirectSound;
    using DS = Microsoft.DirectX.DirectSound;
    .......
    private DS.Device sounddevice;
    private DevicesCollection AuioDevList;
    //Create buffer
    private SecondaryBuffer secondaryBuffer;
    private BufferDescription d = new BufferDescription();

    private void initializeSound()
    {
        // List all Audio Cards
        AuioDevList = new DevicesCollection();
        // Populate cmbAudioCards
        cmbAudioCards.Items.Clear();
        for (int i = 0; i < AuioDevList.Count; i++)
        {
            cmbAudioCards.Items.Add(AuioDevList[i].Description);
        }
        cmbAudioCards.SelectedIndex = 0;
        sounddevice = new DS.Device(AuioDevList[0].DriverGuid);
        sounddevice.SetCooperativeLevel(this.Handle, CooperativeLevel.Normal);

        // Set descriptor’s flags
        d.ControlPan = true;
        d.ControlVolume = true;
        d.ControlFrequency = true;
        d.ControlEffects = true;
    }

    private void prepareSound(string file)
    {

            playing = false;
        //secondaryBuffer.Stop();            
        secondaryBuffer = new SecondaryBuffer(file, d, sounddevice);
        secondaryBuffer.Volume = trkVolume.Value;
    }

    private void btnPlay_Click(object sender, EventArgs e)
    {    
         //Here is throwing exception 
        secondaryBuffer.Play(0, BufferPlayFlags.Default);//
    }

0 个答案:

没有答案