管理访问麦克风输入和系统卷 [英] Managed access to microphone input and system volume

查看:175
本文介绍了管理访问麦克风输入和系统卷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望做三件事情:

访问数据。真的所有我想知道的是由设备感知的声音的总音量。

Access data from the microphone. Really all I want to know is the overall volume of the sound sensed by the device.

设置麦克风增益。

设置系统音量。

我所有的Windows开发人员的经验是C#/ WPF,所以我想留管理。我并不需要极高的性能和实时处理或任何东西。

All of my windows dev experience is C#/WPF, so I'd like to stay managed. I do not need exceptionally high performance or realtime processing or anything.

我环顾四周,似乎像SlimDX可能是一个很好的包装,但即使没有我不知道从哪里开始。

I've looked around and it seems like SlimDX might be a good wrapper for this, but even there I'm not sure where to start.

当然,它不可能是那么难?

Surely it can't be that hard?

推荐答案

下面是一个链接,显示了如何从C#访问混音器在Windows:

Here's a link that shows how to access the audio mixer in Windows from C#:

<一个href=\"http://www.$c$cguru.com/csharp/csharp/cs%5Fgraphics/sound/article.php/c10931\">http://www.$c$cguru.com/csharp/csharp/cs_graphics/sound/article.php/c10931

这将让您设定麦克风增益和系统音量。第一部分是有点复杂,但。基本上,你需要开始记录输入(使用的DirectSound或waveInXXXX API [我个人最喜欢的])。由于每个缓冲区被充满音频,可以计算出均方根为缓冲区,并以此来估算量。

This will let you set the microphone gain and the system volume. The first part is a little more complicated, though. Basically, you need to start recording the input (using DirectSound or the waveInXXXX API [my personal favorite]). As each buffer gets filled with audio, you can calculate the Root Mean Square for the buffer and use this to estimate volume.

修改:这里有一个项目的链接(我已经使用并修改成功,所以我知道它的工作原理)展示了如何使用API​​ waveInXXXX录制音频:

Edit: here's a link to a project (that I've used and modified successfully, so I know it works) that shows how to record audio using the waveInXXXX API:

<一个href=\"http://www.$c$cproject.com/KB/audio-video/cswavrec.aspx?df=90&fid=16677&mpp=25&noise=3&sort=Position&view=Quick&select=3005817\">http://www.$c$cproject.com/KB/audio-video/cswavrec.aspx?df=90&fid=16677&mpp=25&noise=3&sort=Position&view=Quick&select=3005817

编辑2 :既然我已经厌倦了张贴的联系,这里的计算音频缓冲区的均方根(这里的类型是浮动[],但它可以是一个实际的公式易于修改以处理短期[],这是你通常从waveInXXXX获得):

Edit 2: and since I'm tired of posting links, here's an actual formula for calculating the Root Mean Square of an audio buffer (the type here is float[], but it can be easily modified to handle short[], which is what you'd normally get from waveInXXXX):

public static float RootMeanSquared(ref float[] audio)
{
    double sumOfSquared = 0;
    for (int i = 0; i < audio.Length; i++)
    {
        sumOfSquared += audio[i] * audio[i];
    }
    return (float)Math.Sqrt(sumOfSquared / (double)audio.Length);
}

这篇关于管理访问麦克风输入和系统卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆