DirectSound 中的 C# 不明确调用

发布于 2024-07-25 11:27:42 字数 2114 浏览 7 评论 0原文

我正在尝试使用 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 抛出以下错误:

以下方法或属性之间的调用不明确: 'Microsoft.DirectX.DirectSound.CaptureBufferDescription.CaptureBufferDescription()' 和 'Microsoft.DirectX.DirectSound.CaptureBufferDescription.CaptureBufferDescription()'

调用之间不明确 以下方法或属性: 'Microsoft.DirectX.DirectSound.WaveFormat.WaveFormat()' 和 'Microsoft.DirectX.DirectSound.WaveFormet.WaveFormat()'

我尝试了几种不同的声明命名空间和 using 语句的组合,但没有成功。

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

仅包含 Microsoft.DirectX.DirectSound 引用而没有其他任何内容的全新测试项目仍然会引发相同的错误。

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

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

参考资料

  • Graph
  • Microsoft.DirectX.DirectSound
  • Microsoft.DirectX.DirectInputPresentationCorePresentationFrameworkServiceSystemSystem.CoreSystem.DataSystem.Data.DataSetExtensionsSystem.DeploymentSystem.DrawingSystem.Runtime.SerializationSystem.ServiceModelSystem.Windows
  • 以下
  • ​.Forms
  • System.Xml
  • System.Xml.Linq
  • UIAutomationProvider
  • WindowsBase
  • WindowsFormsIntegration

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

以酷 2024-08-01 11:27:42

我有同样的错误,这不是双重引用。 单击运行,编译器会神奇地忘记它,或者您可以使用以下命令完全停止烦恼。

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

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
陌伤浅笑 2024-08-01 11:27:42

听起来您可能正在引用 directx 程序集的多个版本。 也许仔细检查你的参考资料。 如果您需要多个版本,那么extern alias可能会有所帮助 - 但它并不漂亮。


在 Visual Studio 中,查找“解决方案资源管理器”(通常位于右侧) - 这是项目中所有内容的树。 该树中的项目之一是“参考文献”。 这是您的代码配置使用的外部 dll 的直观表示。

(有很多很多 .NET dll - 您需要告诉每个项目它可能需要哪些 dll)

展开此节点,并查找 2 个看起来像 directx 的条目。 如果有两个,请删除其中一个(最好是版本较低的那个)。 然后尝试重建。

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.

偏爱你一生 2024-08-01 11:27:42

您已包含对包含该函数的程序集的不同版本的两个引用。 删除参考文献之一。

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

单调的奢华 2024-08-01 11:27:42

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

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.

吃素的狼 2024-08-01 11:27:42

这是 DirectSound 的常见问题。 您还会发现许多其他问题;)请记住,对于 DS,一切都不是它看起来那样。 当缓冲区返回 null 时,可能只是因为“读取位置”只是内部缓冲区写入指针。 因此,当您要求读取或写入指针时,始终计算至少一个块安全区;)并且当您从 ds 方法获取缓冲区位置时,请使用 try 强制转换,因为它可能会引发随机错误。

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.

鸠魁 2024-08-01 11:27:42

强制您的软件在 x86 或 x64 中编译而不是“任何 CPU”将解决该问题。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文