Example #1
0
void AudioDeviceManager::setCurrentAudioDeviceType (const String& type,
                                                    const bool treatAsChosenDevice)
{
    for (int i = 0; i < availableDeviceTypes.size(); ++i)
    {
        if (availableDeviceTypes.getUnchecked(i)->getTypeName() == type
             && currentDeviceType != type)
        {
            if (currentAudioDevice != nullptr)
            {
                closeAudioDevice();
                Thread::sleep (1500); // allow a moment for OS devices to sort themselves out, to help
                                      // avoid things like DirectSound/ASIO clashes
            }

            currentDeviceType = type;

            AudioDeviceSetup s (*lastDeviceTypeConfigs.getUnchecked(i));
            insertDefaultDeviceNames (s);

            setAudioDeviceSetup (s, treatAsChosenDevice);

            sendChangeMessage();
            break;
        }
    }
}
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);
}
void AudioDeviceManager::audioDeviceListChanged()
{
    if (currentAudioDevice != nullptr)
    {
        auto isCurrentDeviceStillAvailable = [&]
        {
            for (auto* dt : availableDeviceTypes)
                if (currentAudioDevice->getTypeName() == dt->getTypeName())
                    for (auto& dn : dt->getDeviceNames())
                        if (currentAudioDevice->getName() == dn)
                            return true;

            return false;
        };

        if (! isCurrentDeviceStillAvailable())
        {
            closeAudioDevice();

            std::unique_ptr<XmlElement> e (createStateXml());

            if (e == nullptr)
                initialiseDefault (preferredDeviceName, &currentSetup);
            else
                initialiseFromXML (*e, true, preferredDeviceName, &currentSetup);
        }

        if (currentAudioDevice != nullptr)
        {
            currentSetup.sampleRate     = currentAudioDevice->getCurrentSampleRate();
            currentSetup.bufferSize     = currentAudioDevice->getCurrentBufferSizeSamples();
            currentSetup.inputChannels  = currentAudioDevice->getActiveInputChannels();
            currentSetup.outputChannels = currentAudioDevice->getActiveOutputChannels();
        }
    }

    sendChangeMessage();
}
Example #4
0
HRESULT AudioDevice::stopPlayback()
{
	closeAudioDevice();
	return S_OK;
}
Example #5
0
HRESULT AudioDevice::stopCapture()
{
	closeAudioDevice();

	return S_OK;
}
Example #6
0
AudioDevice::~AudioDevice()
{
	closeAudioDevice();
}