2012-02-15 16:17:18 -05:00
|
|
|
#include "audiodevicehelper.h"
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
AudioDeviceHelper::AudioDeviceHelper()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-09-24 15:53:53 -04:00
|
|
|
QAudioInput* AudioDeviceHelper::getDefaultInputDevice()
|
|
|
|
{
|
2012-02-15 16:17:18 -05:00
|
|
|
QAudioFormat fmt;
|
2013-10-19 20:56:34 -04:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0)
|
|
|
|
fmt.setSampleRate(16000);
|
|
|
|
fmt.setChannelCount(1);
|
|
|
|
#else
|
2012-02-15 16:17:18 -05:00
|
|
|
fmt.setFrequency(16000);
|
|
|
|
fmt.setChannels(1);
|
2013-10-19 20:56:34 -04:00
|
|
|
#endif
|
2012-02-15 16:17:18 -05:00
|
|
|
fmt.setSampleSize(16);
|
|
|
|
fmt.setSampleType(QAudioFormat::SignedInt);
|
|
|
|
fmt.setByteOrder(QAudioFormat::LittleEndian);
|
|
|
|
fmt.setCodec("audio/pcm");
|
|
|
|
|
|
|
|
QAudioDeviceInfo it, dev;
|
2012-09-24 15:53:53 -04:00
|
|
|
QList<QAudioDeviceInfo> input_list = QAudioDeviceInfo::availableDevices(QAudio::AudioInput) ;
|
2012-02-15 16:17:18 -05:00
|
|
|
|
|
|
|
dev = QAudioDeviceInfo::defaultInputDevice();
|
|
|
|
if (dev.deviceName() != "pulse") {
|
2012-09-24 15:53:53 -04:00
|
|
|
foreach(it, input_list) {
|
2012-02-15 16:17:18 -05:00
|
|
|
if(it.deviceName() == "pulse") {
|
|
|
|
dev = it;
|
|
|
|
qDebug("Ok.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dev.deviceName() == "null") {
|
2012-09-24 15:53:53 -04:00
|
|
|
foreach(it, input_list) {
|
2012-02-15 16:17:18 -05:00
|
|
|
if(it.deviceName() != "null") {
|
|
|
|
dev = it;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::cerr << "input device : " << dev.deviceName().toStdString() << std::endl;
|
|
|
|
return new QAudioInput(dev, fmt);
|
|
|
|
}
|
|
|
|
QAudioInput* AudioDeviceHelper::getPreferedInputDevice() {
|
|
|
|
return AudioDeviceHelper::getDefaultInputDevice();
|
|
|
|
}
|
|
|
|
|
|
|
|
QAudioOutput* AudioDeviceHelper::getDefaultOutputDevice() {
|
|
|
|
QAudioFormat fmt;
|
2013-10-19 20:56:34 -04:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0)
|
|
|
|
fmt.setSampleRate(16000);
|
|
|
|
fmt.setChannelCount(1);
|
|
|
|
#else
|
2012-02-15 16:17:18 -05:00
|
|
|
fmt.setFrequency(16000);
|
|
|
|
fmt.setChannels(1);
|
2013-10-19 20:56:34 -04:00
|
|
|
#endif
|
2012-02-15 16:17:18 -05:00
|
|
|
fmt.setSampleSize(16);
|
|
|
|
fmt.setSampleType(QAudioFormat::SignedInt);
|
|
|
|
fmt.setByteOrder(QAudioFormat::LittleEndian);
|
|
|
|
fmt.setCodec("audio/pcm");
|
|
|
|
|
2012-09-24 15:53:53 -04:00
|
|
|
QList<QAudioDeviceInfo> list_output = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput) ;
|
|
|
|
|
2012-02-15 16:17:18 -05:00
|
|
|
QAudioDeviceInfo it, dev;
|
|
|
|
dev = QAudioDeviceInfo::defaultOutputDevice();
|
2012-09-24 15:53:53 -04:00
|
|
|
|
2012-02-15 16:17:18 -05:00
|
|
|
if (dev.deviceName() != "pulse") {
|
2012-09-24 15:53:53 -04:00
|
|
|
foreach(it, list_output) {
|
2012-02-15 16:17:18 -05:00
|
|
|
if(it.deviceName() == "pulse") {
|
|
|
|
dev = it;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dev.deviceName() == "null") {
|
2012-09-24 15:53:53 -04:00
|
|
|
foreach(it, list_output) {
|
2012-02-15 16:17:18 -05:00
|
|
|
if(it.deviceName() != "null") {
|
|
|
|
dev = it;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::cerr << "output device : " << dev.deviceName().toStdString() << std::endl;
|
|
|
|
return new QAudioOutput(dev, fmt);
|
|
|
|
}
|
|
|
|
QAudioOutput* AudioDeviceHelper::getPreferedOutputDevice() {
|
|
|
|
return AudioDeviceHelper::getDefaultOutputDevice();
|
|
|
|
}
|