HRESULT AudioDevice::openForPlayback() { HRESULT hr; hr = openAudioDevice(); return hr; }
static void* runThread(void * arg) { inputThread_t *sphinxThread = (inputThread_t*) arg; // sphinx creates own thread for audio device // sphinx thread shall inherit attributes of input thread if(openAudioDevice(sphinxThread) != 0) exit(-1); PRINT_INFO("InputThread started.\n"); sphinxThread->running = 1; sphinxThread->exitCode = 0; unsigned int retries = 0; while(sphinxThread->keepRunning) { //EXEC RESTART_TIME_TAKING(inputExecutionTime); sphinxThread->exitCode = record(sphinxThread); //EXEC STOP_TIME_TAKING(inputExecutionTime); // if decoding failed retry MAX_RETRIES times if(sphinxThread->exitCode != 0) ++retries; else retries = 0; //terminate input thread, beacause max number of retries reached if(retries >= MAX_RETRIES) { PRINT_ERR("Recording failed. Retries: %d. Aborting.\n", retries); break; } } closeAudioDevice(sphinxThread); sphinxThread->running = 0; PRINT_INFO("InputThread terminated.\n"); pthread_exit(&sphinxThread->exitCode); }
HRESULT AudioDevice::openForCapture() { HRESULT hr; WAVEFORMATEX* pwfx; UINT32 bufferFrameCount; if (m_pCaptureClient != NULL) { printf("Failed to open for capture: already opened\n"); return E_FAIL; } hr = openAudioDevice(); if (hr == S_OK) { hr = m_pAudioClient->GetMixFormat(&pwfx); if (hr != S_OK) { printf("Failed to start capture: cannot get mix format, 0x%08x\n", hr); } else { if (pwfx->wFormatTag != WAVE_FORMAT_EXTENSIBLE) { printf("Failed to start capture: mix format not of extensible type\n"); } else { m_audioFormat = *(WAVEFORMATEXTENSIBLE*)pwfx; hr = m_pAudioClient->Initialize( AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_LOOPBACK, m_msBuffersize * 1000 * 10, 0, pwfx, NULL); if (hr != S_OK) { printf("Failed to start capture: cannot initialize, 0x%08x\n", hr); } else { hr = m_pAudioClient->GetBufferSize(&bufferFrameCount); if (hr != S_OK) { printf("Failed to start capture: cannot get buffer size, 0x%08x\n", hr); } else { printf("Allocated capture buffer size in samples:%d\n", bufferFrameCount); hr = m_pAudioClient->GetService(__uuidof(IAudioCaptureClient), (void**)&m_pCaptureClient); if (hr != S_OK) { printf("Failed to start capture: cannot open capture client, 0x%08x\n", hr); } } } } } if (hr != S_OK) { m_pAudioClient->Release(); m_pAudioClient = NULL; } } return hr; }