Exemplo n.º 1
0
void AudioDevice::printAll() {
    for(int i=0; i<numDevices(); i++) {
        printf("[%2d] ", i);
        AudioDevice dev(i);
        dev.print();
        //print(i);
    }
}
Exemplo n.º 2
0
int AudioDevice::getId(std::string dev_name)
{
	unsigned int n_devices = numDevices();

	for(unsigned int i = 0; i < n_devices; i++)
	{
		RtAudio::DeviceInfo info = g_audio->getDeviceInfo(i);
		if(info.name == dev_name)
			return i;
	}

	return -1;
}
Exemplo n.º 3
0
AudioDevice::AudioDevice(const std::string& nameKeyword, bool input, bool output)
:	mID(-1), mImpl(0)
{
	for(int i=0; i<numDevices(); ++i){
		AudioDevice d(i);
		std::string n = d.name();
		if(	((input & d.hasInput()) || (output & d.hasOutput())) &&
			n.find(nameKeyword) != std::string::npos
		){
			setImpl(i);
			break;
		}
	}
}
Exemplo n.º 4
0
AudioDevice::AudioDevice(const std::string& nameKeyword, StreamMode stream)
    :	mID(-1), mImpl(0)
{
    for(int i=0; i<numDevices(); ++i) {
        AudioDevice d(i);
        bool bi = (stream &  INPUT) && d.hasInput();
        bool bo = (stream & OUTPUT) && d.hasOutput();
        std::string n = d.name();

        if(	(bi || bo) && n.find(nameKeyword) != std::string::npos) {
            setImpl(i);
            break;
        }
    }
}
Exemplo n.º 5
0
bool AudioInDevice::init(unsigned int device_id, unsigned int sample_rate, unsigned int chunk_size, unsigned int num_channels, AudioCallback callback_func)
{
	bool status = true;

	deviceId = device_id;
	sampleRate = sample_rate;
	chunkSize = chunk_size;
	numChannels = num_channels;
	callback = callback_func;
	
	unsigned int n_devices = numDevices();

	if(n_devices > 0 && device_id < n_devices)
	{
		RtAudio::DeviceInfo info = g_audio->getDeviceInfo(deviceId);

		audioDev = new RtAudio();

		RtAudio::StreamParameters param;
		param.deviceId = deviceId;//audioOut->getDefaultOutputDevice();
		param.nChannels = numChannels;
		param.firstChannel = 0;

		try
		{
			audioDev->openStream(nullptr, &param, RTAUDIO_SINT16, sampleRate, &chunkSize, &AudioInDevice::audioCallback, (void*)this);
		}
		catch(RtAudioError &e)
		{
			std::cout << e.getMessage() << "\n";
			status = false;
		}
	}
	else
	{
		std::cout << "The requested device ID does not exist.\n";
		status = false;
	}

	return status;
}
Exemplo n.º 6
0
bool AudioDevice::initDevices()
{
	bool status = true;

	if(!g_audio)
	{
		g_audio = new RtAudio();
	
		if(numDevices() < 1)
		{
			std::cout << "No AudioDevices to connect to.\n";
			status = false;
		}
	}
	else
	{
		std::cout << "AudioDevice has already been initialized.\n";
		status = false;
	}

	return status;
}
Exemplo n.º 7
0
//-----------------------------------------------------------------------------
Device::Device(int _deviceID)
    : deviceID(-1)
    , clockRateInKHz(0)
{
    if (!numDevices()) // No CUDA capable devices
    {
        return;
    }
    DeviceMap::const_iterator it = deviceMap.find(_deviceID);
    if (it != deviceMap.end())
    {
        deviceID = it->second;
        setDevice();

        cudaDeviceProp deviceProp;
        CCT_CHECK_GPU(cudaGetDeviceProperties(&deviceProp, deviceID));
        clockRateInKHz = deviceProp.clockRate;
    }
    else
    {
        CCT_WARN("Improper GPU device");
    }
}
Exemplo n.º 8
0
bool AudioDevice::printDevices()
{
	bool status = true;

	if(g_audio)
	{
		unsigned int n_devices = numDevices();
		if(n_devices != 1)
			std::cout << "There are " << n_devices << " audio output devices available.\n";
		else
			std::cout << "There is " << n_devices << " audio output device available.\n";

		if(n_devices != 0)
			std::cout << "\n------------------------\nAudio Devices:\n";

		for(unsigned int i = 0; i < n_devices; i++)
		{
			RtAudio::DeviceInfo info = g_audio->getDeviceInfo(i);

			std::string default_specifier = (info.isDefaultOutput ? "Default Output" : "");
			default_specifier += (info.isDefaultInput && info.isDefaultOutput ? ", " : "");
			default_specifier += (info.isDefaultInput ? "Default Input" : "");
			default_specifier = (info.isDefaultInput || info.isDefaultOutput ? ("(" + default_specifier + ")") : default_specifier);
		
			if(info.probed)
			{
				//Print device info

				std::cout << "\t" << i << ":\t" << info.name << "  " << default_specifier << "\n";
				std::cout << "\t        " << "Max output channels:\t" << info.outputChannels << "\n";
				std::cout << "\t        " << "Max input channels:\t" << info.inputChannels << "\n";
				std::cout << "\t        " << "Max duplex channels:\t" << info.duplexChannels << "\n";
				std::cout << "\t        " << "Supported sample rates:\n\t\t   ";

				int counter = 0;
				for(auto sr : info.sampleRates)
				{
					std::cout << sr << ", ";
					if(++counter % 4 == 0)
						std::cout << "\n\t\t   ";
				}
				std::cout << "\n";

				std::cout << "\t        " << "Native formats:\n";
				if(info.nativeFormats & RTAUDIO_SINT8)
					std::cout << "\t\t   8-bit Signed Integers\n";
				if(info.nativeFormats & RTAUDIO_SINT16)
					std::cout << "\t\t   16-bit Signed Integers\n";
				if(info.nativeFormats & RTAUDIO_SINT24)
					std::cout << "\t\t   24-bit Signed Integers\n";
				if(info.nativeFormats & RTAUDIO_SINT32)
					std::cout << "\t\t   32-bit Signed Integers\n";
				if(info.nativeFormats & RTAUDIO_FLOAT32)
					std::cout << "\t\t   32-bit Floats\n";
				if(info.nativeFormats & RTAUDIO_FLOAT64)
					std::cout << "\t\t   64-bit Floats\n";
			}
			std::cout << "\n";
		}
	}
	else
	{
		std::cout << "AudioDevice has yet to be successfully initialized.\n";
		status = false;
	}

	return status;
}