SecondaryBuffer using BufferDescription and Value not in Range err

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Nihil (Nihil_at_discussions.microsoft.com)
Date: 07/15/04

  • Next message: Nicolas H.: "user speak detection"
    Date: Thu, 15 Jul 2004 13:40:31 -0700
    
    

    I've been trying to write code to stream audio input from the sound card to the speakers using Managed DirectSound (in C# .NET).

    When I try to instantiate a SecondaryBuffer using the overload that requires BufferDescription and the Device, I get the following error:

    "Value does not fall within the expected range"

    This is a really unhelpful error code for which I haven't found any documentation on MSDN. I had the same problem when instantiating a CaptureBuffer and the problem seemed to be that I hadn't specified the "FormatTag".

    However, in this case I've taken care to do that.

    Could somebody please tell me what's wrong or what else is needed?

    Here's the code:
    ------------------

    public StreamingPlayer(Control owner, Device device, WaveFormat format)
                    {
                            m_Device = device;
                            if (m_Device == null)
                            {
                                    m_Device = new Device();
                                    m_Device.SetCooperativeLevel(owner, CooperativeLevel.Normal);
                                    m_OwnsDevice = true;
                            }

                            BufferDescription desc = new BufferDescription(format);
                            desc.BufferBytes = format.AverageBytesPerSecond;
                            format.FormatTag = WaveFormatTag.Pcm;
                            desc.Format = format;
                            
                            
                             // ***** THIS GIVES ME THE ERROR *****
                            m_Buffer = new SecondaryBuffer(desc, m_Device);
            
                             // other code follows
                            
                    }

    --------------

    P.S: I've been able to code Record and Playback functions without much of a problem. The streaming is getting real frustrating. If somebody out there has successfully implemented streaming, would you be willing to share code / code snippets. I will not rip your code off ... I just want to learn.

    You can contact me by email at mystic_musing@yahoo.com


  • Next message: Nicolas H.: "user speak detection"