本文整理汇总了C++中IAudioClient::GetDevicePeriod方法的典型用法代码示例。如果您正苦于以下问题:C++ IAudioClient::GetDevicePeriod方法的具体用法?C++ IAudioClient::GetDevicePeriod怎么用?C++ IAudioClient::GetDevicePeriod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAudioClient
的用法示例。
在下文中一共展示了IAudioClient::GetDevicePeriod方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getdeviceperiod_patch
HRESULT __stdcall getdeviceperiod_patch(
IAudioClient* this_,
REFERENCE_TIME* phnsDefaultDevicePeriod, REFERENCE_TIME* phnsMinimumDevicePeriod)
{
// STATIC FUNCTION
IAudioClient* proxy = get_duplicate(this_)->proxy;
DWORD_PTR* old_vftptr = swap_vtable(this_);
HRESULT hr = proxy->GetDevicePeriod(phnsDefaultDevicePeriod, phnsMinimumDevicePeriod);
((DWORD_PTR**)this_)[0] = old_vftptr;
for(iaudioclient_duplicate* next = get_duplicate(this_)->next; next != NULL; next = next->next)
{
REFERENCE_TIME def, min;
next->proxy->GetDevicePeriod(&def, &min);
assert(def == *phnsDefaultDevicePeriod && min == *phnsMinimumDevicePeriod);
}
return hr;
}
示例2: LoopbackCaptureFor
void LoopbackCaptureFor(IMMDevice* mmDevice, std::string filename, int secs)
{
// open new file
MMIOINFO mi = { 0 };
// some flags cause mmioOpen write to this buffer
// but not any that we're using
std::wstring wsFilename(filename.begin(), filename.end()); // mmioOpen wants a wstring
HMMIO file = mmioOpen(const_cast<LPWSTR>(wsFilename.c_str()), &mi, MMIO_WRITE | MMIO_CREATE);
time_t startTime = time(nullptr);
// activate an IAudioClient
IAudioClient* audioClient;
HRESULT hr = mmDevice->Activate(__uuidof(IAudioClient), CLSCTX_ALL, nullptr, (void**)&audioClient);
if (FAILED(hr))
{
fprintf(stderr, "IMMDevice::Activate(IAudioClient) failed: hr = 0x%08x", hr);
return;
}
// get the default device periodicity
REFERENCE_TIME hnsDefaultDevicePeriod;
hr = audioClient->GetDevicePeriod(&hnsDefaultDevicePeriod, nullptr);
if (FAILED(hr))
{
fprintf(stderr, "IAudioClient::GetDevicePeriod failed: hr = 0x%08x\n", hr);
audioClient->Release();
return;
}
// get the default device format
WAVEFORMATEX* waveform;
hr = audioClient->GetMixFormat(&waveform);
if (FAILED(hr))
{
fprintf(stderr, "IAudioClient::GetMixFormat failed: hr = 0x%08x\n", hr);
CoTaskMemFree(waveform);
audioClient->Release();
return;
}
// coerce int-16 wave format
// can do this in-place since we're not changing the size of the format
// also, the engine will auto-convert from float to int for us
switch (waveform->wFormatTag)
{
case WAVE_FORMAT_IEEE_FLOAT:
waveform->wFormatTag = WAVE_FORMAT_PCM;
waveform->wBitsPerSample = BITS_PER_SAMPLE;
waveform->nBlockAlign = BLOCK_ALIGN;
waveform->nAvgBytesPerSec = BYTE_RATE;
break;
case WAVE_FORMAT_EXTENSIBLE:
{
// naked scope for case-local variable
PWAVEFORMATEXTENSIBLE pEx = reinterpret_cast<PWAVEFORMATEXTENSIBLE>(waveform);
if (IsEqualGUID(KSDATAFORMAT_SUBTYPE_IEEE_FLOAT, pEx->SubFormat))
{
pEx->SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
pEx->Samples.wValidBitsPerSample = BITS_PER_SAMPLE;
waveform->wBitsPerSample = BITS_PER_SAMPLE;
waveform->nBlockAlign = waveform->nChannels * BYTE_PER_SAMPLE;
waveform->nAvgBytesPerSec = waveform->nBlockAlign * waveform->nSamplesPerSec;
}
break;
}
}
MMCKINFO ckRIFF = { 0 };
MMCKINFO ckData = { 0 };
hr = WriteWaveHeader(file, waveform, &ckRIFF, &ckData);
// create a periodic waitable timer
HANDLE hWakeUp = CreateWaitableTimer(nullptr, FALSE, nullptr);
UINT32 nBlockAlign = waveform->nBlockAlign;
// call IAudioClient::Initialize
// note that AUDCLNT_STREAMFLAGS_LOOPBACK and AUDCLNT_STREAMFLAGS_EVENTCALLBACK
// do not work together...
// the "data ready" event never gets set
// so we're going to do a timer-driven loop
hr = audioClient->Initialize(AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_LOOPBACK, 0, 0, waveform, 0);
if (FAILED(hr))
{
fprintf(stderr, "IAudioClient::Initialize failed: hr = 0x%08x\n", hr);
CloseHandle(hWakeUp);
audioClient->Release();
return;
}
// free up waveform
CoTaskMemFree(waveform);
// activate an IAudioCaptureClient
IAudioCaptureClient* audioCaptureClient;
hr = audioClient->GetService(__uuidof(IAudioCaptureClient), (void**)&audioCaptureClient);
// register with MMCSS
DWORD nTaskIndex = 0;
//.........这里部分代码省略.........
示例3: main
int main(int argc, char *argv[])
{
CoInitialize(nullptr);
listDevices();
IAudioClient *pAudioClient;
IMMDevice *device;
getDefaultDevice(&device);
HRESULT hr = device->Activate(__uuidof(IAudioClient),
CLSCTX_ALL, nullptr, (void**)&pAudioClient);
if (FAILED(hr)) {
printf("IMMDevice::Activate(IAudioClient) failed: hr = 0x%08x", hr);
return hr;
}
REFERENCE_TIME hnsDefaultDevicePeriod;
hr = pAudioClient->GetDevicePeriod(&hnsDefaultDevicePeriod, nullptr);
if (FAILED(hr)) {
printf("IAudioClient::GetDevicePeriod failed: hr = 0x%08x\n", hr);
pAudioClient->Release();
return hr;
}
// get the default device format
WAVEFORMATEX *pwfx;
hr = pAudioClient->GetMixFormat(&pwfx);
if (FAILED(hr)) {
printf("IAudioClient::GetMixFormat failed: hr = 0x%08x\n", hr);
CoTaskMemFree(pwfx);
pAudioClient->Release();
return hr;
}
DVAR(pwfx->wFormatTag);
DVAR(pwfx->wBitsPerSample);
DVAR(pwfx->nBlockAlign);
DVAR(pwfx->nAvgBytesPerSec);
switch (pwfx->wFormatTag) {
case WAVE_FORMAT_IEEE_FLOAT:
pwfx->wFormatTag = WAVE_FORMAT_PCM;
pwfx->wBitsPerSample = 16;
pwfx->nBlockAlign = pwfx->nChannels * pwfx->wBitsPerSample / 8;
pwfx->nAvgBytesPerSec = pwfx->nBlockAlign * pwfx->nSamplesPerSec;
break;
case WAVE_FORMAT_EXTENSIBLE:
{
// naked scope for case-local variable
PWAVEFORMATEXTENSIBLE pEx = reinterpret_cast<PWAVEFORMATEXTENSIBLE>(pwfx);
if (IsEqualGUID(KSDATAFORMAT_SUBTYPE_IEEE_FLOAT, pEx->SubFormat)) {
pEx->SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
pEx->Samples.wValidBitsPerSample = 16;
pwfx->wBitsPerSample = 16;
pwfx->nBlockAlign = pwfx->nChannels * pwfx->wBitsPerSample / 8;
pwfx->nAvgBytesPerSec = pwfx->nBlockAlign * pwfx->nSamplesPerSec;
} else {
printf("Don't know how to coerce mix format to int-16\n");
CoTaskMemFree(pwfx);
pAudioClient->Release();
return E_UNEXPECTED;
}
}
break;
default:
printf("Don't know how to coerce WAVEFORMATEX with wFormatTag = 0x%08x to int-16\n", pwfx->wFormatTag);
CoTaskMemFree(pwfx);
pAudioClient->Release();
return E_UNEXPECTED;
}
DVAR(pwfx->wFormatTag);
DVAR(pwfx->wBitsPerSample);
DVAR(pwfx->nBlockAlign);
DVAR(pwfx->nAvgBytesPerSec);
hr = pAudioClient->Initialize(AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_LOOPBACK, 0, 0, pwfx, 0 );
if (FAILED(hr)) {
printf("IAudioClient::Initialize failed: hr = 0x%08x\n", hr);
pAudioClient->Release();
return hr;
}
IAudioCaptureClient *pAudioCaptureClient;
hr = pAudioClient->GetService(__uuidof(IAudioCaptureClient), (void**)&pAudioCaptureClient);
if (FAILED(hr)) {
printf("IAudioClient::GetService(IAudioCaptureClient) failed: hr 0x%08x\n", hr);
pAudioClient->Release();
return hr;
}
hr = pAudioClient->Start();
if (FAILED(hr)) {
printf("IAudioClient::Start failed: hr = 0x%08x\n", hr);
pAudioCaptureClient->Release();
//.........这里部分代码省略.........
示例4: __uuidof
//HRESULT LoopbackCapture(
// IMMDevice *pMMDevice,
// bool bInt16,
// HANDLE hStartedEvent,
// HANDLE hStopEvent,
// PUINT32 pnFrames,
// HMMIO hFile,
// AudioBuffer *pBuffer
//)
HRESULT LoopbackCapture::Process()
{
HRESULT hr;
// activate an IAudioClient
IAudioClient *pAudioClient;
hr = pMMDevice->Activate(
__uuidof(IAudioClient),
CLSCTX_ALL, NULL,
(void**)&pAudioClient
);
if (FAILED(hr)) {
printf("IMMDevice::Activate(IAudioClient) failed: hr = 0x%08x", hr);
return hr;
}
// get the default device periodicity
REFERENCE_TIME hnsDefaultDevicePeriod;
hr = pAudioClient->GetDevicePeriod(&hnsDefaultDevicePeriod, NULL);
if (FAILED(hr)) {
printf("IAudioClient::GetDevicePeriod failed: hr = 0x%08x\n", hr);
pAudioClient->Release();
return hr;
}
// get the default device format
WAVEFORMATEX *pwfx;
hr = pAudioClient->GetMixFormat(&pwfx);
if (FAILED(hr)) {
printf("IAudioClient::GetMixFormat failed: hr = 0x%08x\n", hr);
CoTaskMemFree(pwfx);
pAudioClient->Release();
return hr;
}
if (pwfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE)
{
PWAVEFORMATEXTENSIBLE pEx = reinterpret_cast<PWAVEFORMATEXTENSIBLE>(pwfx);
//pEx->SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
printf("WAVE_FORMAT_EXTENSIBLE\n");
if (IsEqualGUID(KSDATAFORMAT_SUBTYPE_IEEE_FLOAT, pEx->SubFormat))
{
printf("float\n");
}//
else if (IsEqualGUID(KSDATAFORMAT_SUBTYPE_PCM, pEx->SubFormat))
{
printf("PCM\n");
}//KSDATAFORMAT_SUBTYPE_WAVEFORMATEX
else if (IsEqualGUID(KSDATAFORMAT_SUBTYPE_WAVEFORMATEX, pEx->SubFormat))
{
printf("WAVEFORMATEX\n");
}
}
if (bInt16) {
// coerce int-16 wave format
// can do this in-place since we're not changing the size of the format
// also, the engine will auto-convert from float to int for us
switch (pwfx->wFormatTag) {
case WAVE_FORMAT_IEEE_FLOAT:
pwfx->wFormatTag = WAVE_FORMAT_PCM;
pwfx->wBitsPerSample = 16;
pwfx->nBlockAlign = pwfx->nChannels * pwfx->wBitsPerSample / 8;
pwfx->nAvgBytesPerSec = pwfx->nBlockAlign * pwfx->nSamplesPerSec;
break;
case WAVE_FORMAT_EXTENSIBLE:
{
// naked scope for case-local variable
PWAVEFORMATEXTENSIBLE pEx = reinterpret_cast<PWAVEFORMATEXTENSIBLE>(pwfx);
if (IsEqualGUID(KSDATAFORMAT_SUBTYPE_IEEE_FLOAT, pEx->SubFormat)) {
pEx->SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
pEx->Samples.wValidBitsPerSample = 16;
pwfx->wBitsPerSample = 16;
pwfx->nBlockAlign = pwfx->nChannels * pwfx->wBitsPerSample / 8;
pwfx->nAvgBytesPerSec = pwfx->nBlockAlign * pwfx->nSamplesPerSec;
} else {
printf("Don't know how to coerce mix format to int-16\n");
CoTaskMemFree(pwfx);
pAudioClient->Release();
return E_UNEXPECTED;
}
}
break;
default:
printf("Don't know how to coerce WAVEFORMATEX with wFormatTag = 0x%08x to int-16\n", pwfx->wFormatTag);
CoTaskMemFree(pwfx);
pAudioClient->Release();
return E_UNEXPECTED;
}
//.........这里部分代码省略.........
示例5: LoopbackCapture
HRESULT LoopbackCapture(
IMMDevice *pMMDevice,
bool bInt16,
HANDLE hStartedEvent,
HANDLE hStopEvent,
PUINT32 pnFrames,
bool bMono,
INT32 iSampleRateDivisor
) {
HRESULT hr;
SimpleTcpServer server;
// Wait for client connection before attempting any audio capture
server.setup();
server.waitForClient();
// activate an IAudioClient
IAudioClient *pAudioClient;
hr = pMMDevice->Activate(
__uuidof(IAudioClient),
CLSCTX_ALL, NULL,
(void**)&pAudioClient
);
if (FAILED(hr)) {
printf("IMMDevice::Activate(IAudioClient) failed: hr = 0x%08x", hr);
return hr;
}
// get the default device periodicity
REFERENCE_TIME hnsDefaultDevicePeriod;
hr = pAudioClient->GetDevicePeriod(&hnsDefaultDevicePeriod, NULL);
if (FAILED(hr)) {
printf("IAudioClient::GetDevicePeriod failed: hr = 0x%08x\n", hr);
pAudioClient->Release();
return hr;
}
// get the default device format
WAVEFORMATEX *pwfx;
hr = pAudioClient->GetMixFormat(&pwfx);
if (FAILED(hr)) {
printf("IAudioClient::GetMixFormat failed: hr = 0x%08x\n", hr);
CoTaskMemFree(pwfx);
pAudioClient->Release();
return hr;
}
if (bInt16) {
// coerce int-16 wave format
// can do this in-place since we're not changing the size of the format
// also, the engine will auto-convert from float to int for us
switch (pwfx->wFormatTag) {
case WAVE_FORMAT_IEEE_FLOAT:
pwfx->wFormatTag = WAVE_FORMAT_PCM;
pwfx->wBitsPerSample = 16;
pwfx->nBlockAlign = pwfx->nChannels * pwfx->wBitsPerSample / 8;
pwfx->nAvgBytesPerSec = pwfx->nBlockAlign * pwfx->nSamplesPerSec;
break;
case WAVE_FORMAT_EXTENSIBLE:
{
// naked scope for case-local variable
PWAVEFORMATEXTENSIBLE pEx = reinterpret_cast<PWAVEFORMATEXTENSIBLE>(pwfx);
if (IsEqualGUID(KSDATAFORMAT_SUBTYPE_IEEE_FLOAT, pEx->SubFormat)) {
pEx->SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
pEx->Samples.wValidBitsPerSample = 16;
pwfx->wBitsPerSample = 16;
pwfx->nBlockAlign = pwfx->nChannels * pwfx->wBitsPerSample / 8;
pwfx->nAvgBytesPerSec = pwfx->nBlockAlign * pwfx->nSamplesPerSec;
} else {
printf("Don't know how to coerce mix format to int-16\n");
CoTaskMemFree(pwfx);
pAudioClient->Release();
return E_UNEXPECTED;
}
}
break;
default:
printf("Don't know how to coerce WAVEFORMATEX with wFormatTag = 0x%08x to int-16\n", pwfx->wFormatTag);
CoTaskMemFree(pwfx);
pAudioClient->Release();
return E_UNEXPECTED;
}
}
// create a periodic waitable timer
HANDLE hWakeUp = CreateWaitableTimer(NULL, FALSE, NULL);
if (NULL == hWakeUp) {
DWORD dwErr = GetLastError();
printf("CreateWaitableTimer failed: last error = %u\n", dwErr);
CoTaskMemFree(pwfx);
pAudioClient->Release();
return HRESULT_FROM_WIN32(dwErr);
}
UINT32 nBlockAlign = pwfx->nBlockAlign;
UINT32 nBufferSize;
*pnFrames = 0;
//.........这里部分代码省略.........