本文整理汇总了C++中QAudioDeviceInfo::deviceName方法的典型用法代码示例。如果您正苦于以下问题:C++ QAudioDeviceInfo::deviceName方法的具体用法?C++ QAudioDeviceInfo::deviceName怎么用?C++ QAudioDeviceInfo::deviceName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAudioDeviceInfo
的用法示例。
在下文中一共展示了QAudioDeviceInfo::deviceName方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QObject
FrequencyAnalyzer::FrequencyAnalyzer(QObject *parent) :
QObject(parent),
d_ptr(new FrequencyAnalyzerPrivate(this))
{
Q_D(FrequencyAnalyzer);
QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice();
qDebug() << "device name: " << info.deviceName() << "\n"
<< "supported frequency:" << info.supportedFrequencies() << "\n"
<< "supported codecs" << info.supportedCodecs() << "\n"
<< "supported sample sizes" << info.supportedSampleSizes() << "\n"
<< "supported sample types" << info.supportedSampleTypes() << "\n";
QAudioFormat format = info.preferredFormat();
format.setCodec("audio/pcm");
format.setByteOrder(QAudioFormat::LittleEndian);
format.setSampleType(QAudioFormat::SignedInt);
format.setSampleSize(32);
//format.setFrequency(d->sampling = 11025);
//format.setFrequency(d->sampling = 22050);
format.setFrequency(d->sampling = info.supportedFrequencies().last());
format.setChannelCount(1);
if (!info.isFormatSupported(format)) {
qWarning("Format is unsupported");
return;
}
d->input = new QAudioInput(info, format, this);
connect(d->input, SIGNAL(stateChanged(QAudio::State)), SLOT(_q_onStateChanged()));
}
示例2: setAudioOutputDevice
void Engine::setAudioOutputDevice(const QAudioDeviceInfo &device)
{
if (device.deviceName() != m_audioOutputDevice.deviceName()) {
m_audioOutputDevice = device;
initialize();
}
}
示例3: startStreaming
void QSpotifyAudioThreadWorker::startStreaming(int channels, int sampleRate)
{
qDebug() << "QSpotifyAudioThreadWorker::startStreaming";
if (!m_audioOutput) {
QAudioFormat af;
af.setChannelCount(channels);
af.setCodec("audio/pcm");
af.setSampleRate(sampleRate);
af.setSampleSize(16);
af.setSampleType(QAudioFormat::SignedInt);
QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
if (!info.isFormatSupported(af)) {
QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
for (int i = 0; i < devices.size(); i++) {
QAudioDeviceInfo dev = devices[i];
qWarning() << dev.deviceName();
}
QCoreApplication::postEvent(QSpotifySession::instance(), new QEvent(QEvent::Type(StopEventType)));
return;
}
m_audioOutput = new QAudioOutput(af);
connect(m_audioOutput, SIGNAL(stateChanged(QAudio::State)), QSpotifySession::instance(), SLOT(audioStateChange(QAudio::State)));
m_audioOutput->setBufferSize(BUF_SIZE);
startAudioOutput();
}
}
示例4: setAudioInputDevice
void SoundEngine::setAudioInputDevice(const QAudioDeviceInfo &device)
{
if (device.deviceName() != m_audioInputDeviceInfo.deviceName())
{
m_audioInputDeviceInfo = device;
initializeAudio();
}
}
示例5: deviceName
/*!
Returns true if this QAudioDeviceInfo class represents the
same audio device as \a other.
*/
bool QAudioDeviceInfo::operator ==(const QAudioDeviceInfo &other) const
{
if (d == other.d)
return true;
if (d->realm == other.d->realm
&& d->mode == other.d->mode
&& d->handle == other.d->handle
&& deviceName() == other.deviceName())
return true;
return false;
}
示例6: audioDeviceByName
/**
* ATTENTION: The default devices give a null-device at second call
*/
QAudioDeviceInfo Client::audioDeviceByName( QString name, QAudio::Mode mode )
{
QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices( mode );
while(!devices.isEmpty())
{
QAudioDeviceInfo temp = devices.takeFirst();
if(temp.deviceName() == name)
{
return temp;
}
}
if( mode == QAudio::AudioInput)
{
return QAudioDeviceInfo::defaultInputDevice();
}
else if( mode == QAudio::AudioOutput )
{
return QAudioDeviceInfo::defaultOutputDevice();
}
return QAudioDeviceInfo();
}
示例7: foreach
foreach (QAudioDeviceInfo info, infos) {
ui->cbAudioOutput->addItem(info.deviceName());
}
示例8: QDialog
SettingsDialog::SettingsDialog(
const QList<QAudioDeviceInfo> &availableInputDevices,
const QList<QAudioDeviceInfo> &availableOutputDevices,
QWidget *parent)
: QDialog(parent)
, m_windowFunction(DefaultWindowFunction)
, m_inputDeviceComboBox(new QComboBox(this))
, m_outputDeviceComboBox(new QComboBox(this))
, m_windowFunctionComboBox(new QComboBox(this))
{
QVBoxLayout *dialogLayout = new QVBoxLayout(this);
// Populate combo boxes
QAudioDeviceInfo device;
foreach (device, availableInputDevices)
m_inputDeviceComboBox->addItem(device.deviceName(),
qVariantFromValue(device));
foreach (device, availableOutputDevices)
m_outputDeviceComboBox->addItem(device.deviceName(),
qVariantFromValue(device));
m_windowFunctionComboBox->addItem(tr("None"), qVariantFromValue(int(NoWindow)));
m_windowFunctionComboBox->addItem("Hann", qVariantFromValue(int(HannWindow)));
m_windowFunctionComboBox->setCurrentIndex(m_windowFunction);
// Initialize default devices
if (!availableInputDevices.empty())
m_inputDevice = availableInputDevices.front();
if (!availableOutputDevices.empty())
m_outputDevice = availableOutputDevices.front();
// Add widgets to layout
QScopedPointer<QHBoxLayout> inputDeviceLayout(new QHBoxLayout);
QLabel *inputDeviceLabel = new QLabel(tr("Input device"), this);
inputDeviceLayout->addWidget(inputDeviceLabel);
inputDeviceLayout->addWidget(m_inputDeviceComboBox);
dialogLayout->addLayout(inputDeviceLayout.data());
inputDeviceLayout.take(); // ownership transferred to dialogLayout
QScopedPointer<QHBoxLayout> outputDeviceLayout(new QHBoxLayout);
QLabel *outputDeviceLabel = new QLabel(tr("Output device"), this);
outputDeviceLayout->addWidget(outputDeviceLabel);
outputDeviceLayout->addWidget(m_outputDeviceComboBox);
dialogLayout->addLayout(outputDeviceLayout.data());
outputDeviceLayout.take(); // ownership transferred to dialogLayout
QScopedPointer<QHBoxLayout> windowFunctionLayout(new QHBoxLayout);
QLabel *windowFunctionLabel = new QLabel(tr("Window function"), this);
windowFunctionLayout->addWidget(windowFunctionLabel);
windowFunctionLayout->addWidget(m_windowFunctionComboBox);
dialogLayout->addLayout(windowFunctionLayout.data());
windowFunctionLayout.take(); // ownership transferred to dialogLayout
// Connect
CHECKED_CONNECT(m_inputDeviceComboBox, SIGNAL(activated(int)),
this, SLOT(inputDeviceChanged(int)));
CHECKED_CONNECT(m_outputDeviceComboBox, SIGNAL(activated(int)),
this, SLOT(outputDeviceChanged(int)));
CHECKED_CONNECT(m_windowFunctionComboBox, SIGNAL(activated(int)),
this, SLOT(windowFunctionChanged(int)));
// Add standard buttons to layout
QDialogButtonBox *buttonBox = new QDialogButtonBox(this);
buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
dialogLayout->addWidget(buttonBox);
// Connect standard buttons
CHECKED_CONNECT(buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()),
this, SLOT(accept()));
CHECKED_CONNECT(buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()),
this, SLOT(reject()));
setLayout(dialogLayout);
}
示例9: WARNING
AudioNotifier::AudioNotifier(QObject *parent)
{
QAudioDeviceInfo info = QAudioDeviceInfo::defaultOutputDevice();
// Set up the format, eg.
format = info.preferredFormat();
format.setCodec("audio/pcm");
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
format.setChannelCount(2);
#else
format.setChannels(2);
#endif
format.setSampleRate(44100);
format.setSampleSize(16);
format.setByteOrder(QAudioFormat::LittleEndian);
format.setSampleType(QAudioFormat::SignedInt);
if (!info.isFormatSupported(format)) {
WARNING(tr("Audio format not supported by backend. Trying nearest format."));
format = info.nearestFormat(format);
}
audioOutput = new QAudioOutput(format, this);
connect(audioOutput, SIGNAL(stateChanged(QAudio::State)), this, SLOT(audioStateChanged(QAudio::State)));
if(audioOutput->error() != QAudio::NoError)
{
WARNING(tr("Error while creating audio output. Code: ") + QString::number(audioOutput->error()) + tr(" Device: ") + info.deviceName());
}
}
示例10: Start
/////////////////////////////////////////////////////////////////////
// Starts up soundcard output thread using soundcard at list OutDevIndx
/////////////////////////////////////////////////////////////////////
bool CSoundOut::Start(int OutDevIndx, bool StereoOut, double UsrDataRate, bool BlockingMode)
{
QAudioDeviceInfo DeviceInfo;
long mvolume;
m_StereoOut = StereoOut;
m_BlockingMode = BlockingMode;
//Get required soundcard from list
m_OutDevices = DeviceInfo.availableDevices(QAudio::AudioOutput);
if (-1 == OutDevIndx) GetAlsaMasterVolume(&mvolume);
qDebug()<<"Soundcard volume" << mvolume;
if (-1 == OutDevIndx) m_OutDeviceInfo = QAudioDeviceInfo::defaultOutputDevice();
else m_OutDeviceInfo = m_OutDevices.at(OutDevIndx);
#if 1 //RRK get a list of audio devices and the default
foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::availableDevices(QAudio::AudioOutput)) {
qDebug() << "l:" << deviceInfo.deviceName();
}
QAudioDeviceInfo info = QAudioDeviceInfo::defaultOutputDevice();
qDebug() << "res:" << info.deviceName();
#endif
//Setup fixed format for sound ouput
m_OutAudioFormat.setCodec("audio/pcm");
//m_OutAudioFormat.setFrequency(SOUNDCARD_RATE);
m_OutAudioFormat.setSampleRate(SOUNDCARD_RATE);
m_OutAudioFormat.setSampleSize(16);
m_OutAudioFormat.setSampleType(QAudioFormat::SignedInt);
m_OutAudioFormat.setByteOrder(QAudioFormat::LittleEndian);
if(m_StereoOut)
//RRK m_OutAudioFormat.setChannels(2);
m_OutAudioFormat.setChannelCount(2);
else
m_OutAudioFormat.setChannelCount(1);
m_pAudioOutput = new QAudioOutput(m_OutDeviceInfo, m_OutAudioFormat, this);
if(!m_pAudioOutput)
{
qDebug()<<"Soundcard output error";
return false;
}
if(QAudio::NoError == m_pAudioOutput->error() )
{
//initialize the data queue variables
m_UserDataRate = 1; //force user data rate to be changed
ChangeUserDataRate(UsrDataRate);
m_pOutput = m_pAudioOutput->start(); //start QT AudioOutput
//RRK workaround for default, for some reason choosing default
//sets the master volume to max!
if (-1 == OutDevIndx) SetAlsaMasterVolume(50);
//determine how long to sleep between low level reads based on samplerate and period size
m_BlockTime = ( 250*m_pAudioOutput->periodSize() )/
( SOUNDCARD_RATE*m_OutAudioFormat.channelCount() );
//RRK ( SOUNDCARD_RATE*m_OutAudioFormat.channels() );
//qDebug()<<"periodSize "<<m_pAudioOutput->periodSize();
//qDebug()<<"BlockTime "<<m_BlockTime;
m_ThreadQuit = FALSE;
start(QThread::HighestPriority); //start worker thread and set its priority
// start(QThread::TimeCriticalPriority); //start worker thread and set its priority
return true;
}
else
{
qDebug()<<"Soundcard output error";
return false;
}
}
示例11: WARNING
AudioNotifier::AudioNotifier(QObject *parent)
{
QAudioDeviceInfo info = QAudioDeviceInfo::defaultOutputDevice();
// Set up the format, eg.
format = info.preferredFormat();
if (!info.isFormatSupported(format)) {
WARNING("Audio format not supported by backend. Trying nearest format.");
format = info.nearestFormat(format);
}
audioOutput = new QAudioOutput(format, this);
if(audioOutput->error() != QAudio::NoError)
{
WARNING("Error while creating audio output. Code: " + QString::number(audioOutput->error()) + " Device: " + info.deviceName());
}
}