本文整理汇总了C++中IAudioClient::Stop方法的典型用法代码示例。如果您正苦于以下问题:C++ IAudioClient::Stop方法的具体用法?C++ IAudioClient::Stop怎么用?C++ IAudioClient::Stop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAudioClient
的用法示例。
在下文中一共展示了IAudioClient::Stop方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SafeRelease
~BlankAudioPlayback()
{
mmClient->Stop();
SafeRelease(mmRender);
SafeRelease(mmClient);
SafeRelease(mmDevice);
SafeRelease(mmEnumerator);
}
示例2: stop_patch
HRESULT __stdcall stop_patch(IAudioClient* this_)
{
IAudioClient* proxy = get_duplicate(this_)->proxy;
DWORD_PTR* old_vftptr = swap_vtable(this_);
HRESULT hr = proxy->Stop();
((DWORD_PTR**)this_)[0] = old_vftptr;
if(hr == S_OK)
{
for(iaudioclient_duplicate* next = get_duplicate(this_)->next; next != NULL; next = next->next)
next->proxy->Stop();
}
return hr;
}
示例3: propagateWithRawCurrentFormat
void propagateWithRawCurrentFormat(WAVEFORMATEX *toThis) {
WAVEFORMATEX *pwfx;
IMMDevice *pMMDevice;
IAudioClient *pAudioClient;
HANDLE hTask;
DWORD nTaskIndex = 0;
hTask = AvSetMmThreadCharacteristics(L"Capture", &nTaskIndex);
HRESULT hr = get_default_device(&pMMDevice);
if (FAILED(hr)) {
assert(false);
}
// activate an (the default, for us, since we want loopback) IAudioClient
hr = pMMDevice->Activate(
__uuidof(IAudioClient),
CLSCTX_ALL, NULL,
(void**)&pAudioClient
);
if (FAILED(hr)) {
ShowOutput("IMMDevice::Activate(IAudioClient) failed: hr = 0x%08x", hr);
assert(false);
}
hr = pAudioClient->GetMixFormat(&pwfx);
if (FAILED(hr)) {
ShowOutput("IAudioClient::GetMixFormat failed: hr = 0x%08x\n", hr);
CoTaskMemFree(pwfx);
pAudioClient->Release();
assert(false);
}
pAudioClient->Stop();
AvRevertMmThreadCharacteristics(hTask);
pAudioClient->Release();
pMMDevice->Release();
memcpy(toThis, pwfx, sizeof(WAVEFORMATEX));
CoTaskMemFree(pwfx);
}
示例4: Stop
//
// Stop the capturer.
//
void CWASAPICapture::Stop()
{
HRESULT hr;
//
// Tell the capture thread to shut down, wait for the thread to complete then clean up all the stuff we
// allocated in Start().
//
if (_ShutdownEvent)
{
SetEvent(_ShutdownEvent);
}
hr = _AudioClient->Stop();
PersistentAssert(SUCCEEDED(hr), "_AudioClient->Stop failed");
if (_CaptureThread)
{
WaitForSingleObject(_CaptureThread, INFINITE);
CloseHandle(_CaptureThread);
_CaptureThread = NULL;
}
}
示例5: StopCapture
void MMDeviceAudioSource::StopCapture()
{
if(mmClient)
mmClient->Stop();
}
示例6: PlayAudio
void PlayAudio()
{
REFERENCE_TIME hnsRequestedDuration = REFTIMES_PER_SEC; // microseconds, so this is 1 seconds
REFERENCE_TIME hnsActualDuration;
HRESULT hr;
IMMDeviceEnumerator *pEnumerator = NULL;
IMMDevice *pDevice = NULL;
IAudioClient *pAudioClient = NULL;
IAudioRenderClient *pRenderClient = NULL;
WAVEFORMATEX *pwfx = NULL;
UINT32 bufferFrameCount;
UINT32 numFramesAvailable;
UINT32 numFramesPadding;
BYTE *pData;
DWORD flags = 0;
hr = CoCreateInstance(CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, IID_IMMDeviceEnumerator, (void**)&pEnumerator);
EXIT_ON_ERROR(hr);
hr = pEnumerator->GetDefaultAudioEndpoint(
eRender, eConsole, &pDevice);
EXIT_ON_ERROR(hr);
hr = pDevice->Activate(
IID_IAudioClient, CLSCTX_ALL,
NULL, (void**)&pAudioClient);
EXIT_ON_ERROR(hr);
hr = pAudioClient->GetMixFormat(&pwfx);
EXIT_ON_ERROR(hr);
hr = pAudioClient->Initialize(
AUDCLNT_SHAREMODE_SHARED,
0,
hnsRequestedDuration,
0,
pwfx,
NULL);
EXIT_ON_ERROR(hr);
// Get the actual size of the allocated buffer.
hr = pAudioClient->GetBufferSize(&bufferFrameCount);
EXIT_ON_ERROR(hr);
hr = pAudioClient->GetService(
IID_IAudioRenderClient,
(void**)&pRenderClient);
EXIT_ON_ERROR(hr);
// Grab the entire buffer for the initial fill operation.
hr = pRenderClient->GetBuffer(bufferFrameCount, &pData);
EXIT_ON_ERROR(hr);
// load initial data
hr = LoadAudioBuffer(bufferFrameCount, pData, pwfx, &flags);
EXIT_ON_ERROR(hr);
hr = pRenderClient->ReleaseBuffer(bufferFrameCount, flags);
EXIT_ON_ERROR(hr);
// Calculate the actual duration of the allocated buffer.
hnsActualDuration = (REFERENCE_TIME)((double)REFTIMES_PER_SEC * bufferFrameCount / pwfx->nSamplesPerSec);
hr = pAudioClient->Start(); // Start playing.
EXIT_ON_ERROR(hr);
// Each loop fills about half of the shared buffer.
while (flags != AUDCLNT_BUFFERFLAGS_SILENT)
{
// Sleep for half the buffer duration.
Sleep((DWORD)(hnsActualDuration/REFTIMES_PER_MILLISEC/2));
// See how much buffer space is available.
hr = pAudioClient->GetCurrentPadding(&numFramesPadding);
EXIT_ON_ERROR(hr)
numFramesAvailable = bufferFrameCount - numFramesPadding;
// Grab all the available space in the shared buffer.
hr = pRenderClient->GetBuffer(numFramesAvailable, &pData);
EXIT_ON_ERROR(hr)
// Get next 1/2-second of data from the audio source.
hr = LoadAudioBuffer(numFramesAvailable, pData, pwfx, &flags);
EXIT_ON_ERROR(hr)
hr = pRenderClient->ReleaseBuffer(numFramesAvailable, flags);
EXIT_ON_ERROR(hr)
}
// Wait for last data in buffer to play before stopping.
Sleep((DWORD)(hnsActualDuration/REFTIMES_PER_MILLISEC/2));
hr = pAudioClient->Stop(); // Stop playing.
EXIT_ON_ERROR(hr);
//.........这里部分代码省略.........
示例7: LoopbackCaptureFor
//.........这里部分代码省略.........
DWORD dwErr = GetLastError();
fprintf(stderr, "SetWaitableTimer failed: last error = %u\n", dwErr);
AvRevertMmThreadCharacteristics(hTask);
audioCaptureClient->Release();
CloseHandle(hWakeUp);
audioClient->Release();
return;
}
// call IAudioClient::Start
hr = audioClient->Start();
// loopback capture loop
DWORD dwWaitResult;
UINT32 frames = 0;
for (UINT32 passes = 0; ; passes++)
{
// drain data while it is available
UINT32 nextPacketSize;
for (hr = audioCaptureClient->GetNextPacketSize(&nextPacketSize);
SUCCEEDED(hr) && nextPacketSize > 0;
hr = audioCaptureClient->GetNextPacketSize(&nextPacketSize))
{
// get the captured data
BYTE* data;
UINT32 framesToRead;
DWORD dwFlags;
hr = audioCaptureClient->GetBuffer(&data, &framesToRead, &dwFlags, nullptr, nullptr);
if (FAILED(hr))
{
fprintf(stderr, "IAudioCaptureClient::GetBuffer failed on pass %u after %u frames: hr = 0x%08x\n", passes, frames, hr);
audioClient->Stop();
CancelWaitableTimer(hWakeUp);
AvRevertMmThreadCharacteristics(hTask);
audioCaptureClient->Release();
CloseHandle(hWakeUp);
audioClient->Release();
return;
}
// this type of error seems to happen often, ignore it
if (dwFlags == AUDCLNT_BUFFERFLAGS_DATA_DISCONTINUITY)
;
else if (dwFlags != 0) {
fprintf(stderr, "IAudioCaptureClient::GetBuffer set flags to 0x%08x on pass %u after %u frames\n", dwFlags, passes, frames);
audioClient->Stop();
CancelWaitableTimer(hWakeUp);
AvRevertMmThreadCharacteristics(hTask);
audioCaptureClient->Release();
CloseHandle(hWakeUp);
audioClient->Release();
return;
}
if (framesToRead == 0)
{
fprintf(stderr, "IAudioCaptureClient::GetBuffer said to read 0 frames on pass %u after %u frames\n", passes, frames);
audioClient->Stop();
CancelWaitableTimer(hWakeUp);
AvRevertMmThreadCharacteristics(hTask);
audioCaptureClient->Release();
CloseHandle(hWakeUp);
audioClient->Release();
return;
示例8: Process
//.........这里部分代码省略.........
// set the waitable timer
LARGE_INTEGER liFirstFire;
liFirstFire.QuadPart = -hnsDefaultDevicePeriod / 2; // negative means relative time
LONG lTimeBetweenFires = (LONG)hnsDefaultDevicePeriod / 2 / (10 * 1000); // convert to milliseconds
BOOL bOK = SetWaitableTimer(
hWakeUp,
&liFirstFire,
lTimeBetweenFires,
NULL, NULL, FALSE
);
if (!bOK) {
DWORD dwErr = GetLastError();
printf("SetWaitableTimer failed: last error = %u\n", dwErr);
AvRevertMmThreadCharacteristics(hTask);
pAudioCaptureClient->Release();
CloseHandle(hWakeUp);
pAudioClient->Release();
return HRESULT_FROM_WIN32(dwErr);
}
// call IAudioClient::Start
hr = pAudioClient->Start();
if (FAILED(hr)) {
printf("IAudioClient::Start failed: hr = 0x%08x\n", hr);
AvRevertMmThreadCharacteristics(hTask);
pAudioCaptureClient->Release();
CloseHandle(hWakeUp);
pAudioClient->Release();
return hr;
}
SetEvent(hStartedEvent);
// loopback capture loop
HANDLE waitArray[2] = { hStopEvent, hWakeUp };
DWORD dwWaitResult;
DWORD immdState;
bool bDone = false;
bool bFirstPacket = true;
for (UINT32 nPasses = 0; !bDone; nPasses++) {
dwWaitResult = WaitForMultipleObjects(
ARRAYSIZE(waitArray), waitArray,
FALSE, INFINITE
);
if (WAIT_OBJECT_0 == dwWaitResult) {
//printf("Received stop event after %u passes and %u frames\n", nPasses, nFrames);
bDone = true;
continue; // exits loop
}
if (WAIT_OBJECT_0 + 1 != dwWaitResult) {
printf("Unexpected WaitForMultipleObjects return value %u on pass %u after %u frames\n", dwWaitResult, nPasses, nFrames);
pAudioClient->Stop();
CancelWaitableTimer(hWakeUp);
AvRevertMmThreadCharacteristics(hTask);
pAudioCaptureClient->Release();
CloseHandle(hWakeUp);
pAudioClient->Release();
return E_UNEXPECTED;
}
printf("'");
// got a "wake up" event - see if there's data
UINT32 nNextPacketSize;
示例9: main
//.........这里部分代码省略.........
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();
pAudioClient->Release();
return hr;
}
for (int i = 0; i < 10; ++i)
{
UINT32 nNextPacketSize;
hr = pAudioCaptureClient->GetNextPacketSize(&nNextPacketSize);
if (FAILED(hr)) {
printf("IAudioCaptureClient::GetNextPacketSize failed on pass %u after %u frames: hr = 0x%08x\n", 0, 0, hr);
pAudioClient->Stop();
pAudioCaptureClient->Release();
pAudioClient->Release();
return hr;
}
// get the captured data
BYTE *pData;
UINT32 nNumFramesToRead;
DWORD dwFlags;
hr = pAudioCaptureClient->GetBuffer(&pData, &nNumFramesToRead, &dwFlags, nullptr,
nullptr);
if (FAILED(hr)) {
printf("IAudioCaptureClient::GetBuffer failed on pass %u after %u frames: hr = 0x%08x\n", 0, 0, hr);
pAudioClient->Stop();
pAudioCaptureClient->Release();
pAudioClient->Release();
return hr;
}
DVAR(nNumFramesToRead);
// if (bFirstPacket && AUDCLNT_BUFFERFLAGS_DATA_DISCONTINUITY == dwFlags) {
// printf("Probably spurious glitch reported on first packet\n");
if (0 != dwFlags && AUDCLNT_BUFFERFLAGS_DATA_DISCONTINUITY != dwFlags) {
printf("IAudioCaptureClient::GetBuffer set flags to 0x%08x on pass %u after %u frames\n", dwFlags, 0, 0);
// pAudioClient->Stop();
// pAudioCaptureClient->Release();
// pAudioClient->Release();
// return E_UNEXPECTED;
}
else
DVAR((int)*pData);
if (0 == nNumFramesToRead) {
printf("IAudioCaptureClient::GetBuffer said to read 0 frames on pass %u after %u frames\n", 0, 0);
pAudioClient->Stop();
pAudioCaptureClient->Release();
pAudioClient->Release();
return E_UNEXPECTED;
}
UINT32 nBlockAlign = pwfx->nBlockAlign;
LONG lBytesToWrite = nNumFramesToRead * nBlockAlign;
hr = pAudioCaptureClient->ReleaseBuffer(nNumFramesToRead);
}
pAudioClient->Stop();
pAudioCaptureClient->Release();
pAudioClient->Release();
CoUninitialize();
return 0;
}
示例10: _tmain
//.........这里部分代码省略.........
AUDCLNT_STREAMFLAGS_LOOPBACK,
10000000, 0, waveFormat, 0
);
if (FAILED(hr)) {
printf("IAudioClient::Initialize failed: hr = 0x%08x\n", hr);
audioClient->Release();
return hr;
}
CoTaskMemFree(waveFormat);
// activate an IAudioCaptureClient
IAudioCaptureClient *audioCaptureClient;
hr = audioClient->GetService(__uuidof(IAudioCaptureClient), (void**) &audioCaptureClient);
if (FAILED(hr)) {
printf("IAudioClient::GetService(IAudioCaptureClient) failed: hr 0x%08x\n", hr);
audioClient->Release();
return hr;
}
hr = audioClient->Start();
if (FAILED(hr)) {
printf("IAudioClient::Start failed: hr = 0x%08x\n", hr);
audioCaptureClient->Release();
audioClient->Release();
return hr;
}
// loopback capture loop
for (UINT32 i = 0; true; i++) {
UINT32 nextPacketSize;
hr = audioCaptureClient->GetNextPacketSize(&nextPacketSize);
if (FAILED(hr)) {
printf("IAudioCaptureClient::GetNextPacketSize failed on pass %u: hr = 0x%08x\n", i, hr);
audioClient->Stop();
audioCaptureClient->Release();
audioClient->Release();
return hr;
}
if (nextPacketSize == 0) { // no data yet
continue;
}
// get the captured data
BYTE *data;
UINT32 frameCount;
DWORD bufferFlags;
hr = audioCaptureClient->GetBuffer(&data, &frameCount, &bufferFlags, NULL, NULL);
if (FAILED(hr)) {
printf("IAudioCaptureClient::GetBuffer failed on pass %u: hr = 0x%08x\n", i, hr);
audioClient->Stop();
audioCaptureClient->Release();
audioClient->Release();
return hr;
}
if (bufferFlags & AUDCLNT_BUFFERFLAGS_DATA_DISCONTINUITY) {
printf("IAudioCaptureClient::GetBuffer reports 'data discontinuity' on pass %u\n", i);
}
if (bufferFlags & AUDCLNT_BUFFERFLAGS_SILENT) {
printf("IAudioCaptureClient::GetBuffer reports 'silent' on pass %u\n", i);
}
if (bufferFlags & AUDCLNT_BUFFERFLAGS_TIMESTAMP_ERROR) {
printf("IAudioCaptureClient::GetBuffer reports 'timestamp error' on pass %u\n", i);
}
示例11: 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;
//.........这里部分代码省略.........