так?
#define INITGUID
#include <MMDeviceAPI.h>
#include <endpointvolume.h>
#include <audioclient.h>
#include <Functiondiscoverykeys_devpkey.h>
#include <locale.h>
#include <string>
#include <iostream>
#pragma comment(lib, "winmm.lib")
#pragma comment(lib, "strmiids.lib")
#pragma comment(lib, "quartz.lib")
#pragma comment(lib, "uuid.lib")
int changer()
{
setlocale(LC_ALL, "Russian");
HRESULT hr = CoInitialize(NULL);
if (FAILED(hr)) { printf("CoInitialize fail: HRESULT 0x%x", hr); return 1; }
IMMDeviceEnumerator* deviceEnumerator = NULL;
IMMDeviceCollection* deviceCollection = NULL;
IMMDevice* dev = NULL;
IPropertyStore* propertyStore = NULL;
WAVEFORMATEX wex, newWex; //буфер для данных о формате
WAVEFORMATEX pcmWaveFormat;
DWORD dwMode = STGM_READWRITE;
hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&deviceEnumerator));
if (FAILED(hr)) { printf("CoCreateInstance fail: HRESULT 0x%x", hr); goto End; }
hr = deviceEnumerator->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE, &deviceCollection);
if (FAILED(hr)) { printf("EnumAudioEndpoints fail: HRESULT 0x%x", hr); goto End; }
UINT deviceCount;
hr = deviceCollection->GetCount(&deviceCount);
if (FAILED(hr)) { printf("GetCount fail: HRESULT 0x%x", hr); goto End; }
for (UINT DeviceIndex = 0; DeviceIndex < deviceCount; DeviceIndex++)
{
PROPVARIANT format, newFormat{}, checkFormat;
deviceCollection->Item(DeviceIndex, &dev);
if (DeviceIndex != 0) { goto Next; }
if (FAILED(hr)) { printf("Item fail: 0x%x\n", hr); goto Next; }
hr = dev->OpenPropertyStore(dwMode, &propertyStore);
if (FAILED(hr)) { printf("Can't open property store: HRESULT 0x%x", hr); goto Next; }
PROPVARIANT friendlyName;
PropVariantInit(&friendlyName);
hr = propertyStore->GetValue(PKEY_Device_FriendlyName, &friendlyName);
if (FAILED(hr)) { printf("Can't get device name: HRESULT 0x%x", hr); goto Next; }
PropVariantInit(&format);
PropVariantInit(&checkFormat);
hr = propertyStore->GetValue(PKEY_AudioEngine_DeviceFormat, &format);
if (FAILED(hr)) { printf("Can't get format: HRESULT 0x%x", hr); goto Next; }
memcpy_s(&wex, sizeof(wex), format.blob.pBlobData, sizeof(wex)); //копировать данные формата в буфер
pcmWaveFormat.wFormatTag = 0x0000FFFE;
pcmWaveFormat.nChannels = 2;
pcmWaveFormat.nSamplesPerSec = 32000L;
pcmWaveFormat.nAvgBytesPerSec = 128000L;
pcmWaveFormat.nBlockAlign = 4;
pcmWaveFormat.wBitsPerSample = 16;
pcmWaveFormat.cbSize = 22;
newFormat = format;
PropVariantClear(&format);
newFormat.vt = VT_BLOB;
newFormat.blob.cbSize = sizeof(wex);
newFormat.blob.pBlobData = (BYTE*)&wex;
hr = propertyStore->SetValue(PKEY_AudioEngine_DeviceFormat, newFormat);
if (FAILED(hr)) { printf("Can't set format: HRESULT 0x%x", hr); goto Next; }
hr = propertyStore->GetValue(PKEY_AudioEngine_DeviceFormat, &checkFormat);
if (FAILED(hr)) { printf("Can't get format: HRESULT 0x%x", hr); goto Next; }
// Вывод нового значения
memcpy_s(&newWex, sizeof(newWex), checkFormat.blob.pBlobData, sizeof(newWex));
PropVariantClear(&checkFormat);
std::cout << "New Frequency: " << newWex.nSamplesPerSec << std::endl;
Next:
if (dev != NULL) { dev->Release(); dev = NULL; }
if (propertyStore != NULL) { propertyStore->Release(); propertyStore = NULL; }
}
End:
if (dev != NULL) { dev->Release(); dev = NULL; }
if (propertyStore != NULL) { propertyStore->Release(); propertyStore = NULL; }
if (deviceEnumerator != NULL) { deviceEnumerator->Release(); deviceEnumerator = NULL; }
if (deviceCollection != NULL) { deviceCollection->Release(); deviceCollection = NULL; }
CoUninitialize();
return 0;
}
например не читаешь описание чата, и кросспостишь во все чаты подряд
Отправил сюда и в винапи чат. Правила сейчас прочитал, с этим действительно упущение.
Обсуждают сегодня