在 .NET 应用程序中处理音频的推荐方式?

发布于 2024-08-14 17:14:04 字数 913 浏览 3 评论 0原文

我正在尝试在 .NET 3.5 下开始使用一个简单的音频应用程序(最好是在 VB.NET 中,但很乐意使用 C#)。我想做的是:

  • 以每样本 8 位 PCM 格式连续记录来自(默认)Windows 音频输入设备的音频
  • 对于捕获的每 N 个字节,对原始音频进行一些分析(一些 RMS 和/或SPL 计算——基本上是一个漂亮的 VU 条形图所需要的)
  • 如果分析后发现音频片段有趣,请使用压缩文件格式保存它(例如 MP3)

我注意到的第一件事是基本的音频支持.NET Framework 几乎不存在。谷歌搜索了一下发现了一些示例代码,大部分使用 Managed DirectX。然而,缺乏 MSDN 文档、库的过时(2004 年)以及 VS.NET 2008 中以下威胁性的 MDA 异常,让我相信这是一个死胡同:

Message: DLL 'Microsoft.DirectX.dll' is attempting managed execution inside 
OS Loader lock. Do not attempt to run managed code inside a DllMain or image
initialization function since doing so can cause the application to hang.

...我认为可以粗略地翻译为“甚至不<我>尝试使用这个东西。”我是否在这里遗漏了一些东西,或者 Managed DirectX 真的已经死了吗?另一个 StackOverlow 问题表明 XNA 是 Managed DirectX 的替代品,但它缺乏我需要的那种低级功能。

那么,哪个 API 或第三方库对于 .NET 下的音频开发实际上有用呢?使用 COM 互操作或 P/Invoke 是可以接受的,只要有一些合适的 .NET 示例代码可供开始使用...

I'm trying to get started with a simple audio application under .NET 3.5 (preferably in VB.NET, but will happily use C#). What I'd like to do is:

  • Continuously record audio from (the default) Windows audio input device in 8-bits-per-sample PCM format
  • For every N bytes captured, do some analysis on the raw audio (some RMS and/or SPL calculations -- basically what you'd need for a pretty VU bar graph thingy)
  • If the audio fragment is found interesting after analysis, save it using a compressed file format (e.g. MP3)

First thing I noticed is that audio support in the basic .NET Framework is pretty much nonexistent. Googling around a bit found some sample code, mostly using Managed DirectX. However, the lack of MSDN documentation, vintage of the libraries (2004) and the following menacing MDA exception in VS.NET 2008, convinced me this is a dead end:

Message: DLL 'Microsoft.DirectX.dll' is attempting managed execution inside 
OS Loader lock. Do not attempt to run managed code inside a DllMain or image
initialization function since doing so can cause the application to hang.

...which I think loosely translates as "don't even try to use this stuff." Am I missing something here, or is Managed DirectX really dead? Another StackOverlow question suggests that XNA is a replacement for Managed DirectX, but it lacks the kind of low-level functionality I need.

So, which API or third-party library is actually useful for audio development under .NET? Using COM interop or P/Invoke is acceptable, as long as there's some decent .NET example code available to get started with...

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

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

发布评论

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

评论(4

双马尾 2024-08-21 17:14:04

您是否研究过 CodePlex 上的 NAudio?看起来它具有您需要的功能。

Have you looked into NAudio on CodePlex? It looks like it has the features you need.

我的黑色迷你裙 2024-08-21 17:14:04

我一直是 BASS 库 的粉丝,它具有 .NET API。

I've been a fan of the BASS library which has a .NET API.

彻夜缠绵 2024-08-21 17:14:04

如果您想尝试基于 DirectX 的声音解决方案,可以使用 SlimDX。它支持 DirectSound 和 XAudio 接口。

If you want to try a DirectX based sound solution you can use SlimDX. It supports DirectSound and XAudio interfaces.

妄想挽回 2024-08-21 17:14:04

另一个是FMOD

Another is FMOD.

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