本文整理汇总了C++中QAudioDeviceInfo::preferredFormat方法的典型用法代码示例。如果您正苦于以下问题:C++ QAudioDeviceInfo::preferredFormat方法的具体用法?C++ QAudioDeviceInfo::preferredFormat怎么用?C++ QAudioDeviceInfo::preferredFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAudioDeviceInfo
的用法示例。
在下文中一共展示了QAudioDeviceInfo::preferredFormat方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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());
}
}
示例3: SetAudioDevice
/*! Set a new audio device */
void Engine::SetAudioDevice( const QAudioDeviceInfo& deviceInfo ) {
m_pAudioOutput->stop();
m_pAudioOutput->disconnect(this);
m_pDevice = deviceInfo;
m_format= deviceInfo.preferredFormat();
// Set the use of float data
m_format.setSampleType( QAudioFormat::Float );
m_format.setSampleSize( SAMPLE_SIZE );
// Setup our audio device information
while ( !m_pDevice.isFormatSupported( m_format ) ) {
m_format = m_pDevice.nearestFormat( deviceInfo.preferredFormat() );
}
createAudioOutput();
} // end Engine::setAudioDevice()
示例4: start
void SoundInput::start(QAudioDeviceInfo const& device, int framesPerBuffer, AudioDevice * sink, unsigned downSampleFactor, AudioDevice::Channel channel)
{
Q_ASSERT (sink);
stop ();
m_sink = sink;
QAudioFormat format (device.preferredFormat());
format.setChannelCount (AudioDevice::Mono == channel ? 1 : 2);
format.setCodec ("audio/pcm");
format.setSampleRate (12000 * downSampleFactor);
format.setSampleType (QAudioFormat::SignedInt);
format.setSampleSize (16);
if (!format.isValid ())
{
Q_EMIT error (tr ("Requested input audio format is not valid."));
return;
}
// this function lies!
// if (!device.isFormatSupported (format))
// {
// Q_EMIT error (tr ("Requested input audio format is not supported on device."));
// return;
// }
m_stream.reset (new QAudioInput {device, format});
if (audioError ())
{
return;
}
connect (m_stream.data(), &QAudioInput::stateChanged, this, &SoundInput::handleStateChanged);
m_stream->setBufferSize (m_stream->format ().bytesForFrames (framesPerBuffer));
if (sink->initialize (QIODevice::WriteOnly, channel))
{
m_stream->start (sink);
audioError ();
}
else
{
Q_EMIT error (tr ("Failed to initialize audio sink device"));
}
}
示例5: 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());
}
}