我正在使用Windows (也称为MME或多媒体扩展) mmsystem.h。一些程序改变音频回放采样率(例如。(从44.1kHz到48 the ),对我的程序来说,检测当前的回放采样率是非常有用的,因此它可以警告用户Windows将重放程序的输出。
根据这个文档http://msdn.microsoft.com/en-us/library/aa909811.aspx,waveOutGetPlaybackRate返回设备当前正在执行的重采样%(例如,设备以44.1播放,程序在44.1播放音频,因此它将返回1.0)。我很好奇是否有一种方法可以得到设备的绝对采样率,而不是相对的。在Windows /7/8中,您可以手动找到这个值,方法是:“控制面板”>“声音”>“播放”,右键单击“默认播放设备”并选择“属性”,然后选择“高级”选项卡。因此,我试图通过查询操作系统来获得这个“默认格式”值。
所讨论的程序是用Pascal编写的,但是我通常使用C/C++引用。
发布于 2014-10-21 23:23:44
//#include <iostream>
//#include <initguid.h>
//#include <Mmdeviceapi.h>
int main() {
HRESULT hr;
IMMDevice * pDevice = NULL;
IMMDeviceEnumerator * pEnumerator = NULL;
IPropertyStore* store = nullptr;
PWAVEFORMATEX deviceFormatProperties;
PROPVARIANT prop;
CoInitialize(NULL);
// get the device enumerator
hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (LPVOID *)&pEnumerator);
// get default audio endpoint
hr = pEnumerator->GetDefaultAudioEndpoint(eRender, eMultimedia, &pDevice);
hr = pDevice->OpenPropertyStore(STGM_READ, &store);
if (FAILED(hr)) {
std::cout << "OpenPropertyStore failed!" << std::endl;
}
hr = store->GetValue(PKEY_AudioEngine_DeviceFormat, &prop);
if (FAILED(hr)) {
std::cout << "GetValue failed!" << std::endl;
}
deviceFormatProperties = (PWAVEFORMATEX)prop.blob.pBlobData;
std::cout << "Channels = " << deviceFormatProperties->nChannels << std::endl;
std::cout << "Sample rate = " << deviceFormatProperties->nSamplesPerSec << std::endl;
std::cout << "Bit depth = " << deviceFormatProperties->wBitsPerSample << std::endl;
system("pause");
return 0;
}
https://stackoverflow.com/questions/26286131
复制相似问题