如何选择“行中"?音频输入和设置输入“音量".等级 [英] How to select "line in" audio input and set input "volume" level

查看:94
本文介绍了如何选择“行中"?音频输入和设置输入“音量".等级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很乐意看到一个排他模式音频应用程序的显式示例,该应用程序以一定的输入电平(音量)从线路输入(而不是麦克风)获取输入,并尽了最大的努力来实现这一目标.(首选C ++,但总比没有好)

I'd really love to see an explicit example of an exclusive-mode audio application which takes its input from line in (not microphone) at a certain input level (volume), and does the absolute minimum to achieve this. (C++ preferred, but anything is better than nothing)

听起来应该很简单,但要弄清它的难度是多么令人沮丧.

This sounds like it should be simple, but finding out how has been frustratingly hard.

例如,Microsoft的设备拓扑文档使您听起来像是如果您具有简单的通用音频硬件(例如在大多数台式机上),而您只想设置音量,静音或选择频道,则无需担心设备拓扑,因为设备拓扑API适用于复杂得多的设备.

For example, the Device Topologies documentation from Microsoft makes it sound like if you have simple common audio hardware (like on most desktop PCs) and you only want to set volume, mute, or select channel, then you won't need to worry about device topologies because the Device Topologies API is for much more complex devices.

那真是太棒了,但是它简直是不说怎么做,并引发了其他问题:常见的台式PC音频是否有一种始终可以提供扬声器输出,线路输入和麦克风输入的标准?这样的标准会导致线路输入和麦克风始终混合或复用吗?设备拓扑文档指示多路复用;我有旧的 mixerXXX()代码,我正在尝试升级以指示混合.

That would be terrific, but it stops short of saying how, and raises other questions: is there a standard for the common desktop PC audio that always seems to provide speaker out, line in, and microphone in? Will line in and microphone always be mixed or multiplexed as a result of such a standard? The diagram in this Device Topologies documentation indicates multiplexing; I have old mixerXXX() code I am trying to upgrade that indicates mixing.

此外,进一步阅读 Endpoint Volume Controls 建议使用 IAudioEndpointVolume 接口可以做到这一点,但是Win 7.1 SDK中的音频示例并未提供带有输入的 IAudioEndpointVolume 的示例.设备.单独的 IAudioEndpointVolume 函数的文档指出了对输入和输出(进入或离开音频终结点设备的音频流")的支持,但是这些功能似乎都不支持多路复用,并且再次表明混合了行输入和麦克风信号.

Also, further reading about Endpoint Volume Controls suggests that this may be doable using the IAudioEndpointVolume interface, but the audio examples in the Win 7.1 SDK did not give examples of IAudioEndpointVolume with input devices. The documentation on individual IAudioEndpointVolume functions indicates support for both input and output ("audio stream that enters or leaves the audio endpoint device") but none of those functions seem to support multiplexing, and again indicate mixing of line in and microphone signals.

推荐答案

与旧的 waveXXX() mixerXXX() API相比,它们复杂,令人困惑有时甚至在事情发生变化时甚至都不起作用,新的Core Audio API(通常称为WASAPI)仍然很复杂且令人困惑,但旨在预见一个不断变化和网络化的世界.因此,在这一水平上,这是一个重大进步.但是仍然存在着各种各样的音频世界,为所有人创建所有示例是不切实际的.

In contrast to the old waveXXX() and mixerXXX() APIs, which were complex, confusing and sometimes just didn't even work when things changed, the new Core Audio APIs (often just called WASAPI) are still complex and confusing, but designed to anticipate a changing and networked world. So on that level it is significant progress. But there is still a big diverse audio world out there, and creating all examples for all people is impractical.

如果您需要一个简单的示例,请先下载Windows SDK,然后查看音频示例(也许 CaptureSharedEventDriven CaptureSharedTimerDriven ),然后开始删除其中一些在您的上下文中无关紧要的事情.重构剩余的内容将是一个很好的练习,以确保您了解正在发生的事情以及您拥有哪些选择.例如,如果您确实需要排他捕获(对吗?),则需要相应地更改 IAudioClient :: Initialize()参数.

If you want a minimal example, start by downloading the Windows SDK, take a look at the audio samples (perhaps CaptureSharedEventDriven or CaptureSharedTimerDriven) and start deleting some of the things that do not matter in your context. Refactoring what remains will be a good exercise to make sure you understand what is going on, and what options you have. For example, if you really need exclusive capture (do you?) you will need to change the IAudioClient::Initialize() parameters accordingly.

要设置输入音量,请查看 EndpointVolume 示例.您会发现,本示例以及其他提到的示例都是从选择端点设备开始的.之后,您激活 IAudioEndpointVolume 接口,并使用它设置所需的音量,以便轻松识别代码并将其复制到重构的示例中.

To set the input volume level, take a look at the EndpointVolume example. You'll find that this and the other examples mentioned start from selecting an endpoint device. After that, you activate the IAudioEndpointVolume interface, and use it set the desired volume, so that code will be easy to identify and copy across to your refactored example.

但是,出于神秘的原因,在某些硬件上(至少是我的), IMMDeviceEnumerator 实例将不会将line-in枚举为音频端点,除非将某些物理插入行中插孔...,而无论插入或未插入麦克风输入,都能找到.这突显了Windows音频的复杂性和混乱性,并导致这样的问题.

However, for mysterious reasons, on some hardware (mine at least) line-in will not be enumerated as an audio endpoint by the IMMDeviceEnumerator instance unless there is something physically plugged into the line-in jack... whereas the microphone input will be found regardless of what is or isn't plugged into it. Which underscores the complex and confusing nature of Windows audio, and leads to questions like this.

这篇关于如何选择“行中"?音频输入和设置输入“音量".等级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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