HRESULT WasapiWrap::DoDeviceEnumeration(void) { HRESULT hr = 0; IMMDeviceEnumerator *deviceEnumerator = nullptr; m_deviceInfo.clear(); HRR(CoCreateInstance(__uuidof(MMDeviceEnumerator), nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&deviceEnumerator))); HRR(deviceEnumerator->EnumAudioEndpoints( eRender, DEVICE_STATE_ACTIVE, &m_deviceCollection)); UINT nDevices = 0; HRG(m_deviceCollection->GetCount(&nDevices)); for (UINT i = 0; i<nDevices; ++i) { wchar_t name[WW_DEVICE_NAME_COUNT]; HRG(DeviceNameGet(m_deviceCollection, i, name, sizeof name)); m_deviceInfo.push_back(WWDeviceInfo(i, name)); } end: SafeRelease(&deviceEnumerator); return hr; }
static HRESULT DeviceNameGet( IMMDeviceCollection *dc, UINT id, wchar_t *name, size_t nameBytes) { HRESULT hr = 0; IMMDevice *device = nullptr; LPWSTR deviceId = nullptr; IPropertyStore *ps = nullptr; PROPVARIANT pv; assert(dc); assert(name); name[0] = 0; assert(0 < nameBytes); PropVariantInit(&pv); HRR(dc->Item(id, &device)); HRR(device->GetId(&deviceId)); HRR(device->OpenPropertyStore(STGM_READ, &ps)); HRG(ps->GetValue(PKEY_Device_FriendlyName, &pv)); SafeRelease(&ps); wcsncpy_s(name, nameBytes / sizeof name[0], pv.pwszVal, _TRUNCATE); end: PropVariantClear(&pv); CoTaskMemFree(deviceId); SafeRelease(&ps); return hr; }
static HRESULT Run(int deviceId, int latencyMillisec, WWPcmData &pcm) { HRESULT hr; WasapiWrap ww; HRR(ww.Init()); HRG(ww.DoDeviceEnumeration()); HRG(ww.ChooseDevice(deviceId)); WWSetupArg setupArg; setupArg.Set(pcm.bitsPerSample,pcm.validBitsPerSample, pcm.nSamplesPerSec, pcm.nChannels, latencyMillisec); HRG(ww.Setup(setupArg)); ww.SetOutputData(pcm); ww.Start(); while (!ww.Run(1000)) { printf("%d / %d\n", ww.GetPosFrame(), ww.GetTotalFrameNum()); } hr = S_OK; end: ww.Stop(); ww.Unsetup(); ww.Term(); return hr; }
static HRESULT PrintDeviceList(void) { HRESULT hr; WasapiWrap ww; HRR(ww.Init()); HRG(ww.DoDeviceEnumeration()); printf("Device list:\n"); for (int i=0; i<ww.GetDeviceCount(); ++i) { wchar_t namew[WW_DEVICE_NAME_COUNT]; ww.GetDeviceName(i, namew, sizeof namew); char namec[WW_DEVICE_NAME_COUNT]; memset(namec, 0, sizeof namec); WideCharToMultiByte(CP_ACP, 0, namew, -1, namec, sizeof namec-1, NULL, NULL); printf(" deviceId=%d: %s\n", i, namec); } printf("\n"); end: ww.Term(); return hr; }
static HRESULT Test(int deviceId) { HRESULT hr; WasapiWrap ww; HRR(ww.Init()); HRG(ww.DoDeviceEnumeration()); HRG(ww.ChooseDevice(deviceId)); ww.PrintMixFormat(); WWInspectArg inspectArg; inspectArg.Set(16, 16, 44100, 2); ww.Inspect(inspectArg); inspectArg.Set(16, 16, 48000, 2); ww.Inspect(inspectArg); inspectArg.Set(24, 24, 176400, 2); ww.Inspect(inspectArg); inspectArg.Set(32, 24, 176400, 2); ww.Inspect(inspectArg); end: ww.Unsetup(); ww.Term(); return hr; }
// конструктор Patch::Patch(NumXY<int> bottomLeftCorner, bool* result) { // переменные int vertNumber = 0; verticesData = new VertMap[patchVertSize * patchVertSize]; // создать данные для патча for (int i(bottomLeftCorner.x); i < patchVertSize + bottomLeftCorner.x; i++) for (int j(bottomLeftCorner.y); j < patchVertSize + bottomLeftCorner.y; j++) { verticesData[vertNumber].color = XMFLOAT3(0.0f, 0.0f, 0.0f); verticesData[vertNumber].position = XMFLOAT3((float)i + 0.5f, (float)j + 0.5f, Const::mapDepth); vertNumber++; } // создание буфера вершин D3D11_BUFFER_DESC bufferVertDesc = { 0 }; bufferVertDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; bufferVertDesc.ByteWidth = sizeof(VertMap)* patchVertSize * patchVertSize; bufferVertDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; bufferVertDesc.MiscFlags = 0; bufferVertDesc.StructureByteStride = 0; bufferVertDesc.Usage = D3D11_USAGE_DYNAMIC; D3D11_SUBRESOURCE_DATA subVertData = { 0 }; subVertData.pSysMem = (void*)verticesData; HRR(Mediator::pDev->CreateBuffer(&bufferVertDesc, &subVertData, &pVertexBuffer)); }
// конструктор Map::Map(bool* result) { // проверка правильности данных BRR(Const::patchCellSize % Const::regionCellSize == 0); // переменные int indicesAmount = Const::patchCellSize * Const::patchCellSize * 6; UINT* indicesData = new UINT[indicesAmount]; int vertNumber = 0; int indNumber = 0; // заполнисть статические переменные Patch::FillStatic(indicesAmount); // инициализация индексов for (int i(0); i < Const::patchCellSize; i++) for (int j(0); j < Const::patchCellSize; j++) { indicesData[indNumber + 0] = 0 + j + i * patchVertSize; indicesData[indNumber + 1] = 1 + j + i * patchVertSize; indicesData[indNumber + 2] = patchVertSize + 0 + j + i * patchVertSize; indicesData[indNumber + 3] = patchVertSize + 0 + j + i * patchVertSize; indicesData[indNumber + 4] = 1 + j + i * patchVertSize; indicesData[indNumber + 5] = patchVertSize + 1 + j + i * patchVertSize; indNumber += 6; } // создание буфера индексов D3D11_BUFFER_DESC bufferIndDesc = { 0 }; bufferIndDesc.BindFlags = D3D11_BIND_INDEX_BUFFER; bufferIndDesc.ByteWidth = sizeof(UINT)* indicesAmount; bufferIndDesc.CPUAccessFlags = 0; bufferIndDesc.MiscFlags = 0; bufferIndDesc.StructureByteStride = 0; bufferIndDesc.Usage = D3D11_USAGE_IMMUTABLE; D3D11_SUBRESOURCE_DATA subIndData = { 0 }; subIndData.pSysMem = indicesData; HRR(Mediator::pDev->CreateBuffer(&bufferIndDesc, &subIndData, &pIndexBuffer)); // удаление данных ReleaseNULLS(indicesData); // создание поля указателей патчей patchField = new Patch**[Const::patchFieldSize]; for (UINT i(0); i < Const::patchFieldSize; i++) { patchField[i] = new Patch*[Const::patchFieldSize]; for (UINT j(0); j < Const::patchFieldSize; j++) { patchField[i][j] = NULL; } } // ??? пробный патч patchField[0][0] = new Patch(NumXY<int>(), result); Mediator::map = this; }
HRESULT WWAudioDeviceEnumerator::BuildDeviceList(WWDeviceType t) { HRESULT hr = 0; switch (t) { case WWDTPlay: m_dataFlow = eRender; break; case WWDTRec: m_dataFlow = eCapture; break; default: assert(0); return E_FAIL; } HRR(CoCreateInstance(__uuidof(MMDeviceEnumerator), nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&m_deviceEnumerator))); if (m_deviceEnumerator) { for (auto it = m_notificationClientList.begin(); it != m_notificationClientList.end(); ++it) { m_deviceEnumerator->RegisterEndpointNotificationCallback(*it); } } HRR(m_deviceEnumerator->EnumAudioEndpoints(m_dataFlow, DEVICE_STATE_ACTIVE, &m_deviceCollection)); UINT nDevices = 0; HRG(m_deviceCollection->GetCount(&nDevices)); for (UINT i=0; i<nDevices; ++i) { wchar_t name[WW_DEVICE_NAME_COUNT]; wchar_t idStr[WW_DEVICE_IDSTR_COUNT]; HRG(DeviceNameGet(m_deviceCollection, i, name, sizeof name)); HRG(DeviceIdStringGet(m_deviceCollection, i, idStr, sizeof idStr)); m_deviceInfo.push_back(WWDeviceInfo(i, name, idStr)); } end: return hr; }
// конструктор спрайта Sprite::Sprite(wchar_t* filePath, XMFLOAT3 position, NumXY<float> dimentions, SPRITE_ALIGN spriteAlign, bool* result) : position(position), dimentions(dimentions), spriteAlign(spriteAlign) { if (filePath) { textured = true; HRR(D3DX11CreateShaderResourceViewFromFile(Mediator::pDev, filePath, NULL, NULL, &pSRtexture, NULL)); } // создать буфер вершин BRR(CreateVertexBuffer()); // создание матрицы перемещения BRR(UpdateMatrixTranslation(*Mediator::winDimentions)); *result = true; }