Question

I'm trying to use DirectSound to capture sound from a microphone. Here's my code:

    using Microsoft.DirectX.DirectSound;
    public MicrophoneSensor()
    {
            CaptureBufferDescription micBufferDesc = new CaptureBufferDescription();
            WaveFormat format = new WaveFormat();
            format.SamplesPerSecond = 22000;
            format.Channels = 1;
            format.BitsPerSample = 8;
            format.AverageBytesPerSecond = 22000;
            format.BlockAlign = 1;

            micBufferDesc.Format = format;
            micBufferDesc.BufferBytes = 100000;
            micBufferDesc.ControlEffects = false;
            micBufferDesc.WaveMapped = true;

            micBuffer = new CaptureBuffer(micBufferDesc, microphone);
     }

The instantiations of the micBufferDesc and format variables cause Visual Studio 2008 to throw the following error:

The call is ambiguous between the following methods or properties: 'Microsoft.DirectX.DirectSound.CaptureBufferDescription.CaptureBufferDescription()' and 'Microsoft.DirectX.DirectSound.CaptureBufferDescription.CaptureBufferDescription()'

and

The call is ambiguous between the following methods or properties: 'Microsoft.DirectX.DirectSound.WaveFormat.WaveFormat()' and 'Microsoft.DirectX.DirectSound.WaveFormet.WaveFormat()'

I've tried quite a few different combinations of stating the namespace and using statements but no luck.

I've also checked the references in the solution explorer and as far as I can tell there are no duplicates.

A brand new test project with only the Microsoft.DirectX.DirectSound reference and nothing else still throws the same error.

I have also uninstalled and reinstalled the DirectX SDK (March 2009) as well as the DirectX SDK (November 2008). Still no luck.

Finally, I've tried a new project on another computer here in the lab and it still doesn't work.

Here are the references I have:

  • Graph
  • Microsoft.DirectX.DirectSound
  • Microsoft.DirectX.DirectInput
  • PresentationCore
  • PresentationFramework
  • Service
  • System
  • System.Core
  • System.Data
  • System.Data.DataSetExtensions
  • System.Deployment
  • System.Drawing
  • System.Runtime.Serialization
  • System.ServiceModel
  • System.Windows.Forms
  • System.Xml
  • System.Xml.Linq
  • UIAutomationProvider
  • WindowsBase
  • WindowsFormsIntegration
Was it helpful?

Solution

I had the same error, it's not a double reference. Click run and the compiler magically forgets it, or you can stop the annoyance completely with the following.

using System.Reflection;

// then instead of WaveFormat fmt = new WaveFormat()

ConstructorInfo constructor = typeof(WaveFormat).GetConstructor(Type.EmptyTypes);
WaveFormat fmt = (WaveFormat)constructor.Invoke(null);

// do the same for CaptureBufferDescription

OTHER TIPS

It sounds like maybe you are referencing multiple versions of the directx assembly. Perhaps double-check your references. If you need multiple versions, then extern alias may help - but it isn't pretty.


In Visual Studio, look for the "solution explorer" (commonly on the right hand side) - this is the tree of everything in your project. One of the items in this tree is the "References". This is a visual representation of the external dlls that your code is configured to make use of.

(there are many, many .NET dlls - you need to tell each project what dlls it might need)

Expand this node, and look for 2 entries that look like directx. If there are two, get rid of one of them (ideally the one with the lower version). Then try and rebuild.

you've included two references to different versions of the assembly that contains that function. Remove one of the references.

You may have multiple references to the DirectX assembly. Check your project, in the References folder. Look for duplicate entries, specifically references to multiple version of microsoft.directx.directsound.dll. If there are duplicates remove one and try again.

This is common problem with DirectSound. You will find also many many other problems ;) Remember that with DS nothing is what it looks. When buffer return null it probably cause only because "read position" is just inner buffer write pointer. So when you ask read or write pointers calculate allways at least one block safe zone ;) and when you get buffer positions from ds methods use try cast because it can throw random errors.

Force your soft to compile in x86 or x64 instead of 'Any CPU' will fix the problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top