2009-06-23 64 views
1

我试图使用DirectSound从麦克风捕捉声音。这里是我的代码:C#DirectSound中的模糊呼叫

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); 
    } 

的micBufferDesc和格式变量的实例导致Visual Studio 2008年抛出了以下错误:

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()'

我试图说明的命名空间的好几个不同的组合和使用陈述,但没有运气。

我也检查了解决方案资源管理器中的引用,并且据我所知,没有重复。

一个全新的测试项目只有Microsoft.DirectX.DirectSound引用,没有其他东西仍然抛出相同的错误。

我还卸载并重新安装了DirectX SDK(2009年3月)以及DirectX SDK(2008年11月)。仍然没有运气。

最后,我在实验室的另一台计算机上尝试了一个新项目,但它仍然无法工作。

下面是引用我有:

  • Microsoft.DirectX.DirectSound
  • Microsoft.DirectX.DirectInput
  • PresentationCore
  • PresentationFramework
  • 服务
  • 系统
  • System.Core程序
  • System.Data
  • System.Data.DataSetExtensions
  • System.Deployment
  • System.Drawing中
  • System.Runtime.Serialization
  • System.ServiceModel
  • 系统。 Windows.Forms
  • System.Xml
  • System.Xml.Linq
  • UIAutomationProvider
  • WindowsBase
  • WindowsFormsIntegration程序
+0

我在帖子中增加了一些信息。这是一个奇怪的问题。 – JohnS 2009-06-24 14:56:13

回答

2

我有同样的错误,它不是一个双引用。点击运行,编译器神奇地忘记它,或者你可以完全停止下面的烦恼。

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 
1

听起来也许你引用了DirectX组件的多个版本。也许仔细检查你的参考。如果您需要需要多个版本,那么extern alias可能会有所帮助 - 但它并不漂亮。


在Visual Studio中,找到“解决方案资源管理”(常见于右侧) - 这是在您的项目一切的树。此树中的一项是“参考”。这是您的代码被配置为使用的外部dll的可视化表示。

(有很多很多的.NET的DLL - 你需要告诉每一个项目是什么DLL文件可能需要)

展开这个节点,并查找条目2看起来像的DirectX。如果有二,摆脱其中之一(理想情况下与较低版本)。然后尝试重建。

+0

是的,我检查了参考文件夹。据我所知,唯一包含这些类的是Microsoft.DirectX.DirectSound,而没有其他。即使我删除了其他DirectX引用(Microsoft.DirectX.DirectInput),它仍然不起作用。我应该在我的参考文件夹中发布所有条目吗? – JohnS 2009-06-23 19:33:21

+0

嗯....你让我在那里... – 2009-06-23 19:52:06

+0

这没关系。谢谢您的帮助! – JohnS 2009-06-23 19:54:30

0

你已经包含了对包含该函数的程序集的不同版本的两个引用。删除其中一个参考。

0

您可能有多个对DirectX程序集的引用。检查您的项目,在参考文件夹。查找重复的条目,特别是对多个版本的microsoft.directx.directsound.dll的引用。如果有重复,请删除并重试。

0

这是DirectSound的常见问题。你会发现许多其他问题;)请记住,DS没有什么是它看起来。当缓冲区返回null时,它可能只是因为“读取位置”只是内部缓冲区写入指针。因此,当你要求读或写指针至少计算一个块安全区时);并且当你从ds方法获得缓冲区位置时,使用try cast因为它可能抛出随机错误。

0

强制你的软件在x86或x64而不是'任何CPU'编译将解决这个问题。