当前位置: 首页>>代码示例>>C++>>正文


C++ QAudioDeviceInfo类代码示例

本文整理汇总了C++中QAudioDeviceInfo的典型用法代码示例。如果您正苦于以下问题:C++ QAudioDeviceInfo类的具体用法?C++ QAudioDeviceInfo怎么用?C++ QAudioDeviceInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了QAudioDeviceInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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());
    }
}
开发者ID:barry-ran,项目名称:screencloud,代码行数:28,代码来源:audionotifier.cpp

示例2: qDebug

void MyEngine::recordVoice() {
    qDebug() << "Called recordVoice" ;
    QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice();
    foreach (const QString &str, info.supportedCodecs ())
        qDebug() << "Supported codecs: "<< str;

    foreach (const QAudioDeviceInfo &audioDeviceInfo, QAudioDeviceInfo::availableDevices ( QAudio::AudioInput ))
        qDebug() << "Devices: " << audioDeviceInfo.deviceName();

    outputFile.setFileName("test.raw");
    outputFile.open( QIODevice::WriteOnly | QIODevice::Truncate )?qDebug() << "file created":qDebug() << "file creation error";

    //qDebug() << "Sample rate: " << format.sampleRate();

    //QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice();
    if (!info.isFormatSupported(format)) {
        qWarning()<<"default format not supported try to use nearest";
        format = info.nearestFormat(format);
    }

    audio = new QAudioInput(format, this);
    connect(audio, SIGNAL(stateChanged(QAudio::State)),
            this, SLOT(stateChanged(QAudio::State)));

    QTimer::singleShot(2000, this, SLOT(stopRecording())); // Records audio for 2 sec
    audio->start(&outputFile);

}
开发者ID:biedro,项目名称:s2c,代码行数:28,代码来源:myengine.cpp

示例3: on_pushButton_clicked

void MainWindow::on_pushButton_clicked()
{
      QIODevice *QID;
      //QID->open( QIODevice::WriteOnly);
      QBuffer myQB;

     //QID(myQB);
    //cb(128000,64000);
     //dFile.setFileName("../RecordTest.raw");
     microphoneBuffer->open( QIODevice::ReadWrite);
     QAudioFormat format;
     // Set up the desired format, for example:
     format.setSampleRate(16000);
     format.setChannelCount(1);
     format.setSampleSize(16);
     format.setCodec("audio/pcm");
     format.setByteOrder(QAudioFormat::LittleEndian);
     format.setSampleType(QAudioFormat::UnSignedInt);

     QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice();
     if (!info.isFormatSupported(format))
     {
         qWarning() << "Default format not supported, trying to use the nearest.";
         format = info.nearestFormat(format);
     }

     audio = new QAudioInput(format, this);
     connect(audio, SIGNAL(stateChanged(QAudio::State)), this, SLOT(handleStateChanged(QAudio::State)));

     //QTimer::singleShot(5000, this, SLOT(on_pushButton_2_clicked()));
     isRecording = true;
     audio->start(microphoneBuffer);
}
开发者ID:SpenserL,项目名称:WirelessAudio,代码行数:33,代码来源:mainwindow.cpp

示例4: qDebug

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();
    }
}
开发者ID:abranson,项目名称:libQtSpotify,代码行数:29,代码来源:qspotifyaudiothreadworker.cpp

示例5: 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()));
}
开发者ID:alekseysidorov,项目名称:MeeTuner,代码行数:32,代码来源:frequencyanalyzer.cpp

示例6: stop

void SoundInput::start(qint32 device)
{
	stop();

//---------------------------------------------------- Soundcard Setup
	m_callbackData.kin=0;                              //Buffer pointer
	m_callbackData.ncall=0;                            //Number of callbacks
	m_callbackData.bzero=false;                        //Flag to request reset of kin
	m_callbackData.monitoring=m_monitoring;

	//### Temporary: hardwired device selection
	QAudioDeviceInfo  DeviceInfo;
	QList<QAudioDeviceInfo> m_InDevices;
	QAudioDeviceInfo  m_InDeviceInfo;
	m_InDevices = DeviceInfo.availableDevices(QAudio::AudioInput);
	inputDevice = m_InDevices.at(0);
	//###
//  qDebug() << "B" << m_InDevices.length() << inputDevice.deviceName();

	const char* pcmCodec = "audio/pcm";
	QAudioFormat audioFormat = inputDevice.preferredFormat();
	audioFormat.setChannelCount(1);
	audioFormat.setCodec(pcmCodec);
	audioFormat.setSampleRate(12000);
	audioFormat.setSampleType(QAudioFormat::SignedInt);
	audioFormat.setSampleSize(16);

//  qDebug() << "C" << audioFormat << audioFormat.isValid();

	if (!audioFormat.isValid()) {
		emit error(tr("Requested audio format is not available."));
		return;
	}

	audioInput = new QAudioInput(inputDevice, audioFormat);
//  qDebug() << "D" << audioInput->error() << QAudio::NoError;
  if (audioInput->error() != QAudio::NoError) {
		emit error(reportAudioError(audioInput->error()));
		return;
	}

	stream = audioInput->start();
//  qDebug() << "E" << stream->errorString();

	m_ntr0 = 99;		     // initial value higher than any expected
	m_nBusy = 0;
	m_intervalTimer.start(100);
	m_ms0 = QDateTime::currentMSecsSinceEpoch();
	m_nsps0 = 0;
}
开发者ID:tgimmel,项目名称:wsjtx-r3520-src-Debian,代码行数:50,代码来源:soundin.cpp

示例7: GetStreamAudioFormat

QAudioFormat AudioReciever::GetStreamAudioFormat(void)
{
   QAudioFormat format;
   format.setSampleRate(44100);
   //format.setChannels(1);
   format.setSampleSize(24);
   format.setCodec("audio/pcm");
   format.setByteOrder(QAudioFormat::LittleEndian);
   format.setSampleType(QAudioFormat::UnSignedInt);

   QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice();
   if (!info.isFormatSupported(format))
       format = info.nearestFormat(format);

   return format;
}
开发者ID:lvip,项目名称:TwaddleMSG-desctop-,代码行数:16,代码来源:voip.cpp

示例8: main

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    const QAudioDeviceInfo inputDevice = QAudioDeviceInfo::defaultInputDevice();
    if (inputDevice.isNull()) {
        QMessageBox::warning(nullptr, "audio",
                             "There is no audio input device available.");
        return -1;
    }

    Widget w(inputDevice);
    w.show();
    
    return a.exec();
}
开发者ID:cvilas,项目名称:scratch,代码行数:16,代码来源:main.cpp

示例9: setAudioOutputDevice

void Engine::setAudioOutputDevice(const QAudioDeviceInfo &device)
{
    if (device.deviceName() != m_audioOutputDevice.deviceName()) {
        m_audioOutputDevice = device;
        initialize();
    }
}
开发者ID:jimtendo,项目名称:darcoi,代码行数:7,代码来源:engine.cpp

示例10: main

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    SaveSoundMainWindow w;
    w.show();
    RingIODevice *r = new RingIODevice(1000);
    QByteArray c(1000, 0xff);
    //r->writeAtPosition(QByteArray("!ello!"), 0);
    //r->writeAtPosition(" world!h", 6);

    //qDebug() << r->read(30);
    r->writeAtPosition(c, 0);
    r->addOrRemoveBytesFromCurrentPosition(100);
    QAudioDeviceInfo info = QAudioDeviceInfo::defaultOutputDevice();
    qDebug() << info.supportedSampleRates();
    return a.exec();
}
开发者ID:KurlesHS,项目名称:SaveSound,代码行数:17,代码来源:main.cpp

示例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());
    }
}
开发者ID:Nothing4You,项目名称:screencloud,代码行数:17,代码来源:audionotifier.cpp

示例12: setAudioInputDevice

void SoundEngine::setAudioInputDevice(const QAudioDeviceInfo &device)
{
    if (device.deviceName() != m_audioInputDeviceInfo.deviceName())
    {
        m_audioInputDeviceInfo = device;
        initializeAudio();
    }
}
开发者ID:yanik-porto,项目名称:SoundRecorder,代码行数:8,代码来源:soundengine.cpp

示例13: 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()
开发者ID:ZECTBynmo,项目名称:SparkPlug,代码行数:19,代码来源:Engine.cpp

示例14: isSampleRateSupported

bool CSoundCommonQT::isSampleRateSupported(const QAudioDeviceInfo &di, int samplerate) const
{
    samplerate = abs(samplerate);
#ifdef QTAUDIO_SAMPLERATE_HACK
    (void)di;
    return samplerate >= 1 && samplerate <= 192000;
#else
    return di.supportedSampleRates().contains(samplerate);
#endif
}
开发者ID:castrouk,项目名称:LinDrm,代码行数:10,代码来源:qtaudio.cpp

示例15: 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;
}
开发者ID:venkatarajasekhar,项目名称:Qt,代码行数:15,代码来源:qaudiodeviceinfo.cpp


注:本文中的QAudioDeviceInfo类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。