void Engine::startPlayback() { if (m_audioOutput) { if (QAudio::AudioOutput == m_mode && QAudio::SuspendedState == m_state) { m_audioOutput->resume(); } else { m_spectrumAnalyser.cancelCalculation(); spectrumChanged(0, 0, FrequencySpectrum()); setPlayPosition(0, true); m_mode = QAudio::AudioOutput; CHECKED_CONNECT(m_audioOutput, SIGNAL(stateChanged(QAudio::State)), this, SLOT(audioStateChanged(QAudio::State))); CHECKED_CONNECT(m_audioOutput, SIGNAL(notify()), this, SLOT(audioNotify())); m_count = 0; if (m_file) { m_file->seek(0); m_bufferPosition = 0; m_dataLength = 0; m_audioOutput->start(m_file); } else { m_audioOutputIODevice.close(); m_audioOutputIODevice.setBuffer(&m_buffer); m_audioOutputIODevice.open(QIODevice::ReadOnly); m_audioOutput->start(&m_audioOutputIODevice); } } } }
void Engine::startRecording() { if (m_audioInput) { if (QAudio::AudioInput == m_mode && QAudio::SuspendedState == m_state) { m_audioInput->resume(); } else { m_spectrumAnalyser.cancelCalculation(); spectrumChanged(0, 0, FrequencySpectrum()); m_buffer.fill(0); setRecordPosition(0, true); stopPlayback(); m_mode = QAudio::AudioInput; CHECKED_CONNECT(m_audioInput, SIGNAL(stateChanged(QAudio::State)), this, SLOT(audioStateChanged(QAudio::State))); CHECKED_CONNECT(m_audioInput, SIGNAL(notify()), this, SLOT(audioNotify())); m_count = 0; m_dataLength = 0; emit dataLengthChanged(0); m_audioInputIODevice = m_audioInput->start(); CHECKED_CONNECT(m_audioInputIODevice, SIGNAL(readyRead()), this, SLOT(audioDataReady())); } } }
void Engine::startPlayback() { if (m_audioOutput) { if (QAudio::AudioOutput == m_mode && QAudio::SuspendedState == m_state) { #ifdef Q_OS_WIN // The Windows backend seems to internally go back into ActiveState // while still returning SuspendedState, so to ensure that it doesn't // ignore the resume() call, we first re-suspend m_audioOutput->suspend(); #endif m_audioOutput->resume(); } else { m_spectrumAnalyser.cancelCalculation(); spectrumChanged(0, 0, FrequencySpectrum()); setPlayPosition(0, true); stopRecording(); m_mode = QAudio::AudioOutput; CHECKED_CONNECT(m_audioOutput, SIGNAL(stateChanged(QAudio::State)), this, SLOT(audioStateChanged(QAudio::State))); CHECKED_CONNECT(m_audioOutput, SIGNAL(notify()), this, SLOT(audioNotify())); m_count = 0; if (m_file) { m_file->seek(0); m_bufferPosition = 0; m_dataLength = 0; m_audioOutput->start(m_file); } else { m_audioOutputIODevice.close(); m_audioOutputIODevice.setBuffer(&m_buffer); m_audioOutputIODevice.open(QIODevice::ReadOnly); m_audioOutput->start(&m_audioOutputIODevice); } } } }
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))); }