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())); }
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()); } }
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); }
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); }
bool Lockin2::start(const QAudioDeviceInfo &audioDevice, const QAudioFormat &format) { if (_audioInput != 0) { qDebug() << __FUNCTION__ << ": lockin is already running, please stop is before start"; return false; } if (!format.isValid()) { qDebug() << __FUNCTION__ << ": format not valid"; return false; } if (!isFormatSupported(format)) { qDebug() << __FUNCTION__ << ": format not supported for lockin2"; return false; } if (audioDevice.isFormatSupported(format)) { _audioInput = new QAudioInput(audioDevice, format, this); _audioInput->setNotifyInterval(_outputPeriod * 1000.0); connect(_audioInput, SIGNAL(notify()), this, SLOT(interpretInput())); connect(_audioInput, SIGNAL(stateChanged(QAudio::State)), this, SLOT(audioStateChanged(QAudio::State))); // pour être au millieu avec le temps _timeValue = -(_integrationTime / 2.0); // nombre d'échantillons pour le temps d'integration _sampleIntegration = format.sampleRate() * _integrationTime; // nombre d'échantillons pour un affichage de vumeter _sampleVumeter = _vumeterTime * format.sampleRate(); // nettoyage des variables _fifo->readAll(); // vide le fifo _dataXY.clear(); // vide <x,y> _format = format; _audioInput->start(_fifo); } else { qDebug() << __FUNCTION__ << ": format not supported, can't start"; return false; } return true; }
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; }
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()); } }
SWipe::SWipe(QWidget *parent) : QMainWindow(parent) { captureAudio = false; audioFormat.setFrequency( 48000 ); audioFormat.setChannels( 1 ); audioFormat.setSampleSize( 16 ); audioFormat.setCodec( "audio/pcm" ); audioFormat.setByteOrder( QAudioFormat::LittleEndian ); audioFormat.setSampleType( QAudioFormat::SignedInt ); QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice(); if( !info.isFormatSupported( audioFormat ) ) { qWarning() << "default format not supported try to use nearest"; audioFormat = info.nearestFormat( audioFormat ); } magDec = NULL; mkWindow(); }
QAudioFormat AudioTransmitter::GetStreamAudioFormat(void) { QAudioFormat format; QAudioDeviceInfo info1 = QAudioDeviceInfo::defaultInputDevice(); 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); QStringList list=info1.supportedCodecs(); foreach (const QString &str, list) { qDebug()<<"codec: "<<str; } return format; }
TaudioIN::TaudioIN(QObject *parent) : QObject(parent), m_inDevice(0), m_buffer(0), m_pitchFinder(0) { QList<QAudioDeviceInfo> devList = QAudioDeviceInfo::availableDevices(QAudio::AudioInput); for (int i = 0; i < devList.count(); ++i) qDebug() << i << devList[i].deviceName(); QAudioDeviceInfo defaultIn = QAudioDeviceInfo::defaultInputDevice(); QAudioFormat format; format.setChannelCount(1); format.setSampleRate(48000); format.setSampleType(QAudioFormat::SignedInt); format.setSampleSize(16); format.setCodec("audio/pcm"); format.setByteOrder(QAudioFormat::LittleEndian); if (!defaultIn.isFormatSupported(format)) { qDebug() << "Format 48000/16 mono is not suported"; format = defaultIn.nearestFormat(format); qDebug() << "Format is" << format.sampleRate() << format.channelCount() << format.sampleSize(); } m_lastNote = new Tnote(); m_audioIN = new QAudioInput(defaultIn, format, this); m_audioIN->setBufferSize(2048); m_pitchFinder = new TpitchFinder(); m_pitchFinder->setMinimalDuration(0.1f); m_pitchFinder->setSplitByVolChange(false); m_pitchFinder->setSplitVolume(0.0); m_pitchFinder->setSkipStillerVal(0.0); m_pitchFinder->aGl()->equalLoudness = true; m_pitchFinder->setSampleRate(m_audioIN->format().sampleRate()); // framesPerChunk is determined here connect(m_pitchFinder, &TpitchFinder::pitchInChunk, this, &TaudioIN::pitchDetected); connect(m_pitchFinder, &TpitchFinder::noteStarted, this, &TaudioIN::noteStartedSlot); connect(m_pitchFinder, &TpitchFinder::noteFinished, this, &TaudioIN::noteFinishedSlot); }
void PCMPlayer::handleThreadOnStarted() { PCMPlayerDebug("current thread:%x",QThread::currentThreadId()); thread->setObjectName(QString("PCMPlayerThread-")+ QString::number((int)QThread::currentThreadId())); PCMPlayerDebug("prepare pcmPlayer!"); pcmFormat = new QAudioFormat(); pcmFormat->setSampleRate(samplesPerSec); pcmFormat->setChannels(channels); pcmFormat->setSampleSize(bitNumPerSample); if (bitNumPerSample == 8) { pcmFormat->setSampleType(QAudioFormat::SignedInt); } else if (bitNumPerSample == 16) { pcmFormat->setSampleType(QAudioFormat::UnSignedInt); } pcmFormat->setCodec("audio/pcm"); QAudioDeviceInfo devInfo = QAudioDeviceInfo::defaultOutputDevice(); if (!devInfo.isFormatSupported(*pcmFormat)) { *pcmFormat = devInfo.nearestFormat(*pcmFormat); PCMPlayerDebug("pcmPlayer prepare failed!"); return; } audioOutput = new QAudioOutput(*pcmFormat); audioOutput->reset(); audioOutput->setBufferSize(dataQueue->getBufferSize() * 2); PCMPlayerDebug("AudioOutput BufferSize = %d", audioOutput->bufferSize()); QObject::connect(QThread::currentThread(), SIGNAL(finished()), audioOutput, SLOT(deleteLater())); connect(QThread::currentThread() , SIGNAL(finished()) , this , SLOT(handleThreadOnFinished())); audioOutputIODevice = audioOutput->start(); timerID = startTimer(20); PCMPlayerDebug("pcmPlayer prepare successed!"); }
void Engine::startListening() { QAudioFormat format; // Set up the desired format, for example: format.setSampleRate(8000); format.setChannelCount(1); format.setSampleSize(8); 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); } QAudioInput *audio = new QAudioInput(format, this); QBuffer buffer; audio->start(&buffer); }
Logger::Logger(QObject *parent) : QObject(parent) { mPort = new SerialPort(this); mPacketInterface = new PacketInterface(this); mValueFile = new QFile("Data/BLDC_Values"); mPrintFile = new QFile("Data/BLDC_Print"); mValueFile->open(QIODevice::WriteOnly | QIODevice::Text); mPrintFile->open(QIODevice::WriteOnly | QIODevice::Text); mValueStream = new QTextStream(mValueFile); mPrintStream = new QTextStream(mPrintFile); mPort->openPort("/dev/ttyACM0"); // Video mVidW = 1280; mVidH = 720; mVidFps = 25.0; mFAudioSamp = 44100; mFrameGrabber = new FrameGrabber(mVidW, mVidH, mVidFps, 0, this); mFrameGrabber->start(QThread::InheritPriority); mPlotter = new FramePlotter(this); mPlotter->start(QThread::InheritPriority); mCoder = new VideoCoder(mVidW, mVidH, mVidFps, "Data/v_video.avi", this); mCoder->start(QThread::InheritPriority); // Audio recording mTimer = 0; mAudio = 0; if (QAudioDeviceInfo::availableDevices(QAudio::AudioInput).size() > 0) { mAudioFile.setFileName("Data/v_audio.raw"); mAudioFile.open(QIODevice::WriteOnly | QIODevice::Truncate); QAudioFormat format; // Set up the desired format, for example: format.setSampleRate(mFAudioSamp); format.setChannelCount(1); format.setSampleSize(8); 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); } mAudio = new QAudioInput(format, this); mAudio->setNotifyInterval(1000 / mVidFps); mAudio->start(&mAudioFile); } else { mTimer = new QTimer(this); mTimer->setInterval(1000 / mVidFps); mTimer->start(); } mConsoleReader = new ConsoleReader(this); connect(mConsoleReader, SIGNAL(textReceived(QString)), this, SLOT(consoleLineReceived(QString))); connect(mPort, SIGNAL(serial_data_available()), this, SLOT(serialDataAvailable())); if (mTimer != 0) { connect(mTimer, SIGNAL(timeout()), this, SLOT(timerSlot())); } if (mAudio != 0) { connect(mAudio, SIGNAL(notify()), this, SLOT(audioNotify())); // Lower the volume to avoid clipping. This seems to be passed to // pulseaudio. mAudio->setVolume(0.1); } connect(mPacketInterface, SIGNAL(dataToSend(QByteArray&)), this, SLOT(packetDataToSend(QByteArray&))); connect(mPacketInterface, SIGNAL(valuesReceived(PacketInterface::MC_VALUES)), this, SLOT(mcValuesReceived(PacketInterface::MC_VALUES))); connect(mPacketInterface, SIGNAL(printReceived(QString)), this, SLOT(printReceived(QString))); connect(mPacketInterface, SIGNAL(samplesReceived(QByteArray)), this, SLOT(samplesReceived(QByteArray))); connect(mPacketInterface, SIGNAL(rotorPosReceived(double)), this, SLOT(rotorPosReceived(double))); connect(mPacketInterface, SIGNAL(experimentSamplesReceived(QVector<double>)), this, SLOT(experimentSamplesReceived(QVector<double>))); connect(mPlotter, SIGNAL(frameReady(QImage)), mCoder, SLOT(setNextFrame(QImage))); }