void CAudioOutputTest::start(const QString &filePath, const QAudioDeviceInfo &audioDeviceInfo) { stop(); if(m_PCMIODevice) { m_PCMIODevice->deleteLater(); m_PCMIODevice = NULL; } m_PCMIODevice = new CPCMIODevice(filePath,this); connect(m_PCMIODevice,SIGNAL(readChannelFinished()),this,SLOT(onStateChanged())); QAudioFormat format; format.setSampleRate(44100); format.setChannelCount(2); format.setSampleSize(16); format.setCodec("audio/pcm"); format.setByteOrder(QAudioFormat::LittleEndian); format.setSampleType(QAudioFormat::SignedInt); QAudioDeviceInfo info(audioDeviceInfo); if (!info.isFormatSupported(format)) { // qWarning() << "Default format not supported - trying to use nearest"; format = info.nearestFormat(format); } if(m_audioOutput) { delete m_audioOutput; m_audioOutput = 0; } m_audioOutput = new QAudioOutput(audioDeviceInfo, format, this); connect(m_audioOutput,SIGNAL(stateChanged(QAudio::State)),this,SLOT(onStateChanged())); if(m_PCMIODevice) { m_PCMIODevice->start(); } m_audioOutput->start(m_PCMIODevice); }
static int QtSoundInit() { qDebug() << __func__; nQtAudioFps = nAppVirtualFps; nAudSegLen = (nAudSampleRate[0] * 100 + (nQtAudioFps / 2)) / nQtAudioFps; // seglen * 2 channels * 2 bytes per sample (16bits) nAudAllocSegLen = nAudSegLen * 4; // seg * nsegs * 2 channels if (qSoundBuffer != nullptr) delete qSoundBuffer; qSoundBuffer = new QAudioInterfaceBuffer(); qSoundBuffer->setBufferSize(nAudAllocSegLen * nAudSegCount); nAudNextSound = new short[nAudAllocSegLen / sizeof(short)]; QtSoundSetCallback(nullptr); QtSoundGetNextSoundFiller(0); //qSoundBuffer->writeData((const char *) nAudNextSound, nAudAllocSegLen); //qSoundBuffer->writeData((const char *) nAudNextSound, nAudAllocSegLen); pBurnSoundOut = nAudNextSound; nBurnSoundRate = nAudSampleRate[0]; nBurnSoundLen = nAudAllocSegLen; qAudio = QAudioInterface::get(); qAudio->setBuffer(qSoundBuffer); QAudioFormat format; format.setChannelCount(2); format.setSampleRate(nAudSampleRate[0]); format.setSampleType(QAudioFormat::SignedInt); format.setByteOrder(QAudioFormat::LittleEndian); format.setSampleSize(16); qAudio->setFormat(format); // we need to invoke this method on sound's thread, so we can't call this // method from our object QMetaObject::invokeMethod(qAudio, "init", Qt::QueuedConnection); bAudOkay = 1; return 0; }
void MainAudio::run() { QAudioFormat fmt; fmt.setSampleRate(AUDIO_FREQ); fmt.setCodec("audio/pcm"); fmt.setChannelCount(AUDIO_CHANNELS); fmt.setSampleSize(AUDIO_SAMPLESIZE); fmt.setByteOrder(QAudioFormat::LittleEndian); fmt.setSampleType(QAudioFormat::SignedInt); mixlen = sizeof(short)*AUDIO_BUFFERS*AUDIO_CHANNELS*AUDIO_SAMPLES; mixbuf = (char*)malloc(mixlen); output = new QAudioOutput(fmt); output->setBufferSize(mixlen); feed = output->start(); if (feed != NULL) { // buffering has already done in the internal mixed buffer // use a small interval to copy mixed audio stream from // internal buffer to audio output buffer as soon as possible // use 1 instead of 0 to prevent CPU exhausting timer = startTimer(1); } }
/*! Constructor. */ AudioOut::AudioOut(AudioSource *source, QObject *parent /* = 0 */) : QThread(parent), m_audioOutput(0), m_outTarget(0), m_source(source), m_sendBuffer(0), m_sendBufferSize(0), m_samplesMixed(0), m_threadState(NotRunning), m_usingThread(false) { QAudioFormat format; format.setFrequency(AUDIO_FREQUENCY); format.setChannels(GEDefaultChannelCount); format.setSampleSize(AUDIO_SAMPLE_BITS); format.setCodec(GEDefaultAudioCodec); format.setByteOrder(GEByteOrder); format.setSampleType(GESampleType); QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice()); if (!info.isFormatSupported(format)) format = info.nearestFormat(format); m_audioOutput = new QAudioOutput(info, format); m_audioOutput->setBufferSize(4096 * 8); m_sendBufferSize = 4096 * 8; m_outTarget = m_audioOutput->start(); DEBUG_INFO("Buffer size: " << m_audioOutput->bufferSize()); m_sendBuffer = new AUDIO_SAMPLE_TYPE[m_sendBufferSize]; #ifndef Q_OS_SYMBIAN m_usingThread = true; start(); #endif }
void AudioProcessorQt::start() { if (!m_device) { m_device = new AudioDevice(this); } if (!m_audioOutput) { QAudioFormat format; format.setSampleRate(44100); format.setChannelCount(2); format.setSampleSize(16); format.setCodec("audio/pcm"); format.setByteOrder(QAudioFormat::LittleEndian); format.setSampleType(QAudioFormat::SignedInt); m_audioOutput = new QAudioOutput(format, this); } m_device->setInput(input()); m_device->setFormat(m_audioOutput->format()); m_audioOutput->setBufferSize(input()->audioBuffers * 4); m_audioOutput->start(m_device); }
void AudioFileWav::addHeader(const QAudioFormat& audioFormat) { QDataStream stream(&_file); stream.setByteOrder(QDataStream::LittleEndian); // RIFF stream.writeRawData("RIFF", 4); stream << quint32(0); stream.writeRawData("WAVE", 4); // Format description PCM = 16 stream.writeRawData("fmt ", 4); stream << quint32(16); stream << quint16(1); stream << quint16(audioFormat.channelCount()); stream << quint32(audioFormat.sampleRate()); stream << quint32(audioFormat.sampleRate() * audioFormat.channelCount() * audioFormat.sampleSize() / 8); // bytes per second stream << quint16(audioFormat.channelCount() * audioFormat.sampleSize() / 8); // block align stream << quint16(audioFormat.sampleSize()); // bits Per Sample // Init data chunck stream.writeRawData("data", 4); stream << quint32(0); }
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); }
MainWindow::MainWindow(vector<TimeOption> timeOptions_, QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), timer(this), finishedSource(":/sounds/alarm.raw"), timeOptions(timeOptions_) { ui->setupUi(this); for (vector<TimeOption>::iterator it = timeOptions.begin(); it!= timeOptions.end(); ++ it) { TimeOption o = *it; ui->timeSelection->addItem(QString::fromStdString(o.name)); } finishedSource.open(QIODevice::ReadOnly); QAudioFormat format; format.setSampleRate(44100); format.setChannelCount(1); format.setSampleSize(16); format.setCodec("audio/pcm"); format.setByteOrder(QAudioFormat::LittleEndian); format.setSampleType(QAudioFormat::SignedInt); QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice()); if (!info.isFormatSupported(format)) { qWarning() << "Raw audio format not supported by backend, cannot play audio."; finishedSound = NULL; } else { finishedSound = new QAudioOutput(format, this); //finishedSound->start(&finishedSource); } connect(ui->startTimer, SIGNAL(clicked()), this, SLOT(startCountDown())); connect(&timer, SIGNAL(timeout()), this, SLOT(timerTick())); connect(ui->fullscreen, SIGNAL(clicked()), this, SLOT(fullScreenClicked())); }
void NotificationSound::playSound() { //QSound::play(":/sound/notification_sound.wav"); //return; qreal frequency = ((sFrequency <= 0)?2000:sFrequency); qreal mseconds = ((sDuration <= 0)?1000:sDuration); quint8 volume = ((sVolume <= 0)?1:sVolume); qreal sampleRate = 2.0 * M_PI / (192000./frequency); QByteArray bytebuf; bytebuf.resize(mseconds * 192); for (int i=0; i < bytebuf.size(); i++) { bytebuf[i] = (quint8)(qreal(255) * qSin(qreal(i) * sampleRate)); } QDataStream stream(&bytebuf, QIODevice::ReadWrite); QAudioFormat format; format.setSampleRate(192000); format.setChannelCount(1); format.setSampleSize(8); format.setCodec("audio/pcm"); format.setByteOrder(QAudioFormat::LittleEndian); format.setSampleType(QAudioFormat::UnSignedInt); QAudioOutput * audio = new QAudioOutput(format, this); audio->setVolume(1.0 * (qreal(volume + 1)/4)); audio->setBufferSize(bytebuf.size()); audio->start(stream.device()); QEventLoop loop; QTimer::singleShot(mseconds*2, &loop, SLOT(quit())); loop.exec(); }
int test_1(QObject* a) { QAudioFormat format; // Set up the format, eg. format.setSampleRate(44100); format.setChannelCount(2); format.setCodec("audio/pcm"); format.setSampleType(QAudioFormat::SignedInt); format.setSampleSize(16); format.setByteOrder(QAudioFormat::LittleEndian); QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice()); if (!info.isFormatSupported(format)) { qDebug() << "Raw audio format not supported by backend, cannot play audio."; return -1; } char filename[1024]; printf("input file name :"); scanf("%s",filename); fflush(stdin); fflush(stdout); printf("start audio \n"); QAudioOutput *audio; audio = new QAudioOutput(format, a); QIODevice *out = audio->start(); #if 0 qDebug()<< out->isSequential() << " swquential"; // 不是顺序设备,是随机设备 #endif decodeAndPlay(filename,out); }
DlgEditMusic::DlgEditMusic(cMusicObject *TheMusicObject,cApplicationConfig *ApplicationConfig,QWidget *parent): QCustomDialog(ApplicationConfig,parent), ui(new Ui::DlgEditMusic) { ui->setupUi(this); OkBt =ui->OKBT; CancelBt =ui->CancelBt; HelpBt =ui->HelpBt; HelpFile ="0124"; MusicObject =TheMusicObject; StopMaj =false; InSliderMoveEvent =false; IsInit =false; PlayerPlayMode =false; PlayerPauseMode =false; IsSliderProcess =false; ActualPosition =-1; ResetPositionWanted =false; AudioBuf =(u_int8_t *)malloc(AUDIOBUFSIZE); AudioBufSize =0; MixedMusic.SetFPS(double(1000)/ApplicationConfig->PreviewFPS,2,ApplicationConfig->PreviewSamplingRate,AV_SAMPLE_FMT_S16); Music.SetFPS(MixedMusic.WantedDuration,MixedMusic.Channels,MixedMusic.SamplingRate,MixedMusic.SampleFormat); // Set up the format QAudioFormat format; format.setCodec("audio/pcm"); format.setSampleRate(MixedMusic.SamplingRate); // Usually this is specified through an UI option format.setChannelCount(MixedMusic.Channels); format.setSampleSize(16); format.setByteOrder(QAudioFormat::LittleEndian); format.setSampleType(QAudioFormat::SignedInt); // Create audio output stream, set up signals audio_outputStream = new QAudioOutput(format,this); }
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; }
void RtpAudioStream::startPlaying() { if (audio_output_) return; QAudioFormat format; format.setSampleRate(audio_out_rate_); format.setSampleSize(sample_bytes_ * 8); // bits format.setSampleType(QAudioFormat::SignedInt); format.setChannelCount(1); format.setCodec("audio/pcm"); // RTP_STREAM_DEBUG("playing %s %d samples @ %u Hz", // tempfile_->fileName().toUtf8().constData(), // (int) tempfile_->size(), audio_out_rate_); audio_output_ = new QAudioOutput(format, this); audio_output_->setNotifyInterval(65); // ~15 fps connect(audio_output_, SIGNAL(stateChanged(QAudio::State)), this, SLOT(outputStateChanged())); connect(audio_output_, SIGNAL(notify()), this, SLOT(outputNotify())); tempfile_->seek(0); audio_output_->start(tempfile_); emit startedPlaying(); }
/*! Constructor. */ PushAudioOut::PushAudioOut(AudioSource *source, QObject *parent /* = 0 */) : QThread(parent), m_audioOutput(0), m_outTarget(0), m_sendBuffer(0), m_sendBufferSize(0), m_samplesMixed(0), m_threadState(NotRunning), m_source(source) { DEBUG_INFO(this); QAudioFormat format; format.setFrequency(AUDIO_FREQUENCY); format.setChannels(AUDIO_CHANNELS); format.setSampleSize(AUDIO_SAMPLE_BITS); format.setCodec(GEDefaultAudioCodec); switch (GEByteOrder) { case BigEndian: format.setByteOrder(QAudioFormat::BigEndian); break; case LittleEndian: format.setByteOrder(QAudioFormat::LittleEndian); break; default: DEBUG_INFO("INVALID BYTE ORDER"); } switch (GESampleType) { case Unknown: format.setSampleType(QAudioFormat::Unknown); break; case SignedInt: format.setSampleType(QAudioFormat::SignedInt); break; case UnSignedInt: format.setSampleType(QAudioFormat::UnSignedInt); break; case Float: format.setSampleType(QAudioFormat::Float); break; default: DEBUG_INFO("INVALID SAMPLE TYPE"); } QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice()); if (!info.isFormatSupported(format)) format = info.nearestFormat(format); m_audioOutput = new QAudioOutput(info, format); #if defined(Q_WS_MAEMO_5) || defined(MEEGO_EDITION_HARMATTAN) m_sendBufferSize = 4096 * 4; #else m_audioOutput->setBufferSize(4096 * 4); #endif #if defined(Q_WS_MAEMO_5) || defined(MEEGO_EDITION_HARMATTAN) m_audioOutput->setBufferSize(4096 * 16); m_sendBufferSize = 4096 * 8; #else m_audioOutput->setBufferSize(4096 * 4); m_sendBufferSize = 4096 * 2; #endif DEBUG_INFO("Buffer size: " << m_audioOutput->bufferSize()); m_sendBuffer = new AUDIO_SAMPLE_TYPE[m_sendBufferSize]; m_needsTick = false; #if defined(QTGAMEENABLER_USE_VOLUME_HACK) && defined(Q_OS_SYMBIAN) DEBUG_INFO("WARNING: Using the volume hack!"); // This really ugly hack is used as the last resort. This allows us to // adjust the application volume in Symbian. The CMMFDevSound object lies // deep inside the QAudioOutput in Symbian implementation and it has the // needed functions. So, we dig the required object accessing it directly // from memory. unsigned int *pointer_to_abstract_audio = (unsigned int*)((unsigned char*)m_audioOutput + 8); unsigned int *dev_sound_wrapper = (unsigned int*)(*pointer_to_abstract_audio) + 13; unsigned int *temp = ((unsigned int*)(*dev_sound_wrapper) + 6); CMMFDevSound *devSound = (CMMFDevSound*)(*temp); devSound->SetVolume(devSound->MaxVolume() * 6 / 10); #endif }
void Generator::generateData(const QAudioFormat &format, qint64 durationUs, int frequency) { const int channelBytes = format.sampleSize() / 8; const int sampleBytes = format.channels() * channelBytes; qint64 length = (format.frequency() * format.channels() * (format.sampleSize() / 8)) * durationUs / 100000; Q_ASSERT(length % sampleBytes == 0); Q_UNUSED(sampleBytes) // suppress warning in release builds m_buffer.resize(length); unsigned char *ptr = reinterpret_cast<unsigned char *>(m_buffer.data()); int sampleIndex = 0; while (length) { const qreal x = qSin(2 * M_PI * frequency * qreal(sampleIndex % format.frequency()) / format.frequency()); for (int i=0; i<format.channels(); ++i) { if (format.sampleSize() == 8 && format.sampleType() == QAudioFormat::UnSignedInt) { const quint8 value = static_cast<quint8>((1.0 + x) / 2 * 255); *reinterpret_cast<quint8*>(ptr) = value; } else if (format.sampleSize() == 8 && format.sampleType() == QAudioFormat::SignedInt) { const qint8 value = static_cast<qint8>(x * 127); *reinterpret_cast<quint8*>(ptr) = value; } else if (format.sampleSize() == 16 && format.sampleType() == QAudioFormat::UnSignedInt) { quint16 value = static_cast<quint16>((1.0 + x) / 2 * 65535); if (format.byteOrder() == QAudioFormat::LittleEndian) qToLittleEndian<quint16>(value, ptr); else qToBigEndian<quint16>(value, ptr); } else if (format.sampleSize() == 16 && format.sampleType() == QAudioFormat::SignedInt) { qint16 value = static_cast<qint16>(x * 32767); if (format.byteOrder() == QAudioFormat::LittleEndian) qToLittleEndian<qint16>(value, ptr); else qToBigEndian<qint16>(value, ptr); } ptr += channelBytes; length -= channelBytes; } ++sampleIndex; } }
qint64 audioDuration(const QAudioFormat &format, qint64 bytes) { return (bytes * 1000000) / (format.sampleRate() * format.channelCount() * (format.sampleSize() / 8)); }
void tst_QAudioDecoderBackend::fileTest() { QAudioDecoder d; QAudioBuffer buffer; quint64 duration = 0; int byteCount = 0; int sampleCount = 0; QVERIFY(d.state() == QAudioDecoder::StoppedState); QVERIFY(d.bufferAvailable() == false); QCOMPARE(d.sourceFilename(), QString("")); QVERIFY(d.audioFormat() == QAudioFormat()); // Test local file QFileInfo fileInfo(QFINDTESTDATA(TEST_FILE_NAME)); d.setSourceFilename(fileInfo.absoluteFilePath()); QVERIFY(d.state() == QAudioDecoder::StoppedState); QVERIFY(!d.bufferAvailable()); QCOMPARE(d.sourceFilename(), fileInfo.absoluteFilePath()); QSignalSpy readySpy(&d, SIGNAL(bufferReady())); QSignalSpy bufferChangedSpy(&d, SIGNAL(bufferAvailableChanged(bool))); QSignalSpy errorSpy(&d, SIGNAL(error(QAudioDecoder::Error))); QSignalSpy stateSpy(&d, SIGNAL(stateChanged(QAudioDecoder::State))); QSignalSpy durationSpy(&d, SIGNAL(durationChanged(qint64))); QSignalSpy finishedSpy(&d, SIGNAL(finished())); QSignalSpy positionSpy(&d, SIGNAL(positionChanged(qint64))); d.start(); QTRY_VERIFY(d.state() == QAudioDecoder::DecodingState); QTRY_VERIFY(!stateSpy.isEmpty()); QTRY_VERIFY(!readySpy.isEmpty()); QTRY_VERIFY(!bufferChangedSpy.isEmpty()); QVERIFY(d.bufferAvailable()); QTRY_VERIFY(!durationSpy.isEmpty()); QVERIFY(qAbs(d.duration() - 1000) < 20); buffer = d.read(); QVERIFY(buffer.isValid()); // Test file is 44.1K 16bit mono, 44094 samples QCOMPARE(buffer.format().channelCount(), 1); QCOMPARE(buffer.format().sampleRate(), 44100); QCOMPARE(buffer.format().sampleSize(), 16); QCOMPARE(buffer.format().sampleType(), QAudioFormat::SignedInt); QCOMPARE(buffer.format().codec(), QString("audio/pcm")); QCOMPARE(buffer.byteCount(), buffer.sampleCount() * 2); // 16bit mono // The decoder should still have no format set QVERIFY(d.audioFormat() == QAudioFormat()); QVERIFY(errorSpy.isEmpty()); duration += buffer.duration(); sampleCount += buffer.sampleCount(); byteCount += buffer.byteCount(); // Now drain the decoder if (sampleCount < 44094) { QTRY_COMPARE(d.bufferAvailable(), true); } while (d.bufferAvailable()) { buffer = d.read(); QVERIFY(buffer.isValid()); QTRY_VERIFY(!positionSpy.isEmpty()); QVERIFY(positionSpy.takeLast().at(0).toLongLong() == qint64(duration / 1000)); duration += buffer.duration(); sampleCount += buffer.sampleCount(); byteCount += buffer.byteCount(); if (sampleCount < 44094) { QTRY_COMPARE(d.bufferAvailable(), true); } } // Make sure the duration is roughly correct (+/- 20ms) QCOMPARE(sampleCount, 44094); QCOMPARE(byteCount, 44094 * 2); QVERIFY(qAbs(qint64(duration) - 1000000) < 20000); QVERIFY(qAbs((d.position() + (buffer.duration() / 1000)) - 1000) < 20); QTRY_COMPARE(finishedSpy.count(), 1); QVERIFY(!d.bufferAvailable()); QTRY_COMPARE(d.state(), QAudioDecoder::StoppedState); d.stop(); QTRY_COMPARE(d.state(), QAudioDecoder::StoppedState); QTRY_COMPARE(durationSpy.count(), 2); QCOMPARE(d.duration(), qint64(-1)); QVERIFY(!d.bufferAvailable()); readySpy.clear(); bufferChangedSpy.clear(); stateSpy.clear(); durationSpy.clear(); finishedSpy.clear(); positionSpy.clear(); // change output audio format QAudioFormat format; format.setChannelCount(2); format.setSampleSize(8); format.setSampleRate(11050); format.setCodec("audio/pcm"); format.setSampleType(QAudioFormat::SignedInt); d.setAudioFormat(format); // We expect 1 second still, at 11050 * 2 samples == 22k samples. // (at 1 byte/sample -> 22kb) // Make sure it stuck QVERIFY(d.audioFormat() == format); duration = 0; sampleCount = 0; byteCount = 0; d.start(); QTRY_VERIFY(d.state() == QAudioDecoder::DecodingState); QTRY_VERIFY(!stateSpy.isEmpty()); QTRY_VERIFY(!readySpy.isEmpty()); QTRY_VERIFY(!bufferChangedSpy.isEmpty()); QVERIFY(d.bufferAvailable()); QTRY_VERIFY(!durationSpy.isEmpty()); QVERIFY(qAbs(d.duration() - 1000) < 20); buffer = d.read(); QVERIFY(buffer.isValid()); // See if we got the right format QVERIFY(buffer.format() == format); // The decoder should still have the same format QVERIFY(d.audioFormat() == format); QVERIFY(errorSpy.isEmpty()); duration += buffer.duration(); sampleCount += buffer.sampleCount(); byteCount += buffer.byteCount(); // Now drain the decoder if (duration < 998000) { QTRY_COMPARE(d.bufferAvailable(), true); } while (d.bufferAvailable()) { buffer = d.read(); QVERIFY(buffer.isValid()); QTRY_VERIFY(!positionSpy.isEmpty()); QVERIFY(positionSpy.takeLast().at(0).toLongLong() == qint64(duration / 1000)); QVERIFY(d.position() - (duration / 1000) < 20); duration += buffer.duration(); sampleCount += buffer.sampleCount(); byteCount += buffer.byteCount(); if (duration < 998000) { QTRY_COMPARE(d.bufferAvailable(), true); } } // Resampling might end up with fewer or more samples // so be a bit sloppy QVERIFY(qAbs(sampleCount - 22047) < 100); QVERIFY(qAbs(byteCount - 22047) < 100); QVERIFY(qAbs(qint64(duration) - 1000000) < 20000); QVERIFY(qAbs((d.position() + (buffer.duration() / 1000)) - 1000) < 20); QTRY_COMPARE(finishedSpy.count(), 1); QVERIFY(!d.bufferAvailable()); QTRY_COMPARE(d.state(), QAudioDecoder::StoppedState); d.stop(); QTRY_COMPARE(d.state(), QAudioDecoder::StoppedState); QTRY_COMPARE(durationSpy.count(), 2); QCOMPARE(d.duration(), qint64(-1)); QVERIFY(!d.bufferAvailable()); }
wgt_QVideoPlayer::wgt_QVideoPlayer(QWidget *parent) : QWidget(parent),ui(new Ui::wgt_QVideoPlayer) { ui->setupUi(this); AudioBuf = (u_int8_t *)malloc(AUDIOBUFSIZE); AudioBufSize = 0; FLAGSTOPITEMSELECTION = NULL; InPlayerUpdate = false; Diaporama = NULL; IsValide = false; IsInit = false; DisplayMSec = true; // add msec to display IconPause = QIcon(ICON_PLAYERPLAY); // QApplication::style()->standardIcon(QStyle::SP_MediaPlay) IconPlay = QIcon(ICON_PLAYERPAUSE); // QApplication::style()->standardIcon(QStyle::SP_MediaPause) PlayerPlayMode = false; // Is player currently play mode PlayerPauseMode = false; // Is player currently plause mode IsSliderProcess = false; ActualPosition = -1; tDuration = QTime(0,0,0,0); ResetPositionWanted = false; Deinterlace = false; AudioPlayed = 0; ui->CustomRuler->ActiveSlider(0); ui->CustomRuler->setSingleStep(25); ui->MovieFrame->setText(""); ui->MovieFrame->setAttribute(Qt::WA_OpaquePaintEvent); #if QT_VERSION >= 0x050000 ui->VideoPlayerVolumeBT->setIcon(style()->standardIcon(QStyle::SP_MediaVolume)); ui->VideoPlayerVolumeBT->setPopupMode(QToolButton::InstantPopup); connect(ui->VideoPlayerVolumeBT,SIGNAL(pressed()),this,SLOT(s_VideoPlayerVolume())); #else ui->VideoPlayerVolumeBT->setVisible(false); #endif connect(&Timer,SIGNAL(timeout()),this,SLOT(s_TimerEvent())); connect(ui->VideoPlayerPlayPauseBT,SIGNAL(clicked()),this,SLOT(s_VideoPlayerPlayPauseBT())); connect(ui->MovieFrame,SIGNAL(DoubleClick()),this,SLOT(s_DoubleClick())); connect(ui->MovieFrame,SIGNAL(RightClickEvent(QMouseEvent *)),this,SLOT(s_RightClickEvent(QMouseEvent *))); // Slider control connect(ui->CustomRuler,SIGNAL(sliderPressed()),this,SLOT(s_SliderPressed())); connect(ui->CustomRuler,SIGNAL(sliderReleased()),this,SLOT(s_SliderReleased())); connect(ui->CustomRuler,SIGNAL(valueChanged(int)),this,SLOT(s_SliderMoved(int))); connect(ui->CustomRuler,SIGNAL(PositionChangeByUser()),this,SLOT(s_PositionChangeByUser())); connect(ui->CustomRuler,SIGNAL(StartEndChangeByUser()),this,SLOT(s_StartEndChangeByUser())); connect(ui->VideoPlayerSaveImageBT,SIGNAL(pressed()),this,SLOT(s_SaveImage())); MixedMusic.SetFPS(double(1000)/12.5,2,48000,AV_SAMPLE_FMT_S16); Music.SetFPS(MixedMusic.WantedDuration,MixedMusic.Channels,MixedMusic.SamplingRate,MixedMusic.SampleFormat); // Set up the format QAudioFormat format; format.setCodec("audio/pcm"); format.setSampleRate(MixedMusic.SamplingRate); // Usually this is specified through an UI option format.setChannelCount(MixedMusic.Channels); format.setSampleSize(16); format.setByteOrder(QAudioFormat::LittleEndian); format.setSampleType(QAudioFormat::SignedInt); // Create audio output stream, set up signals audio_outputStream=new QAudioOutput(format,this); audio_outputStream->setBufferSize(MixedMusic.NbrPacketForFPS*MixedMusic.SoundPacketSize*BUFFERING_NBR_AUDIO_FRAME); audio_outputDevice=audio_outputStream->start(); AudioPlayed=0; audio_outputStream->suspend(); }
void Generator::generateData(const QAudioFormat& format, unsigned char* ptr, qint64 length) { const int channelBytes = format.sampleSize() / 8; if (length <= 0) return; QMutexLocker lock(m_mutex); QVector<qreal> channels; channels.resize(2); // LOG_INFO() << "generating Sounds" << QDateTime::currentDateTime() << length; initializeSounds(); while (length) { generateTone(channels[0], channels[1], m_sampleIndex); //const qreal x = soundFunc(2 * M_PI * frequency * qreal(sampleIndex ) / format.sampleRate()); for (int i=0; i<format.channelCount(); ++i) { if (format.sampleSize() == 8 && format.sampleType() == QAudioFormat::UnSignedInt) { const quint8 value = static_cast<quint8>((1.0 + channels[i]) / 2 * 255); *reinterpret_cast<quint8*>(ptr) = value; } else if (format.sampleSize() == 8 && format.sampleType() == QAudioFormat::SignedInt) { const qint8 value = static_cast<qint8>(channels[i] * 127); *reinterpret_cast<quint8*>(ptr) = value; } else if (format.sampleSize() == 16 && format.sampleType() == QAudioFormat::UnSignedInt) { quint16 value = static_cast<quint16>((1.0 + channels[i]) / 2 * 65535); if (format.byteOrder() == QAudioFormat::LittleEndian) qToLittleEndian<quint16>(value, ptr); else qToBigEndian<quint16>(value, ptr); } else if (format.sampleSize() == 16 && format.sampleType() == QAudioFormat::SignedInt) { qint16 value = static_cast<qint16>(channels[i] * 32767); if (format.byteOrder() == QAudioFormat::LittleEndian) qToLittleEndian<qint16>(value, ptr); else qToBigEndian<qint16>(value, ptr); } ptr += channelBytes; length -= channelBytes; } ++m_sampleIndex; } }
bool QAudioDeviceInfoInternal::testSettings(const QAudioFormat& format) const { // Set nearest to closest settings that do work. // See if what is in settings will work (return value). bool failed = false; bool match = false; // check codec for( int i = 0; i < codecz.count(); i++) { if (format.codec() == codecz.at(i)) match = true; } if (!match) failed = true; // check channel match = false; if (!failed) { for( int i = 0; i < channelz.count(); i++) { if (format.channels() == channelz.at(i)) { match = true; break; } } if (!match) failed = true; } // check frequency match = false; if (!failed) { for( int i = 0; i < freqz.count(); i++) { if (format.frequency() == freqz.at(i)) { match = true; break; } } if (!match) failed = true; } // check sample size match = false; if (!failed) { for( int i = 0; i < sizez.count(); i++) { if (format.sampleSize() == sizez.at(i)) { match = true; break; } } if (!match) failed = true; } // check byte order match = false; if (!failed) { for( int i = 0; i < byteOrderz.count(); i++) { if (format.byteOrder() == byteOrderz.at(i)) { match = true; break; } } if (!match) failed = true; } // check sample type match = false; if (!failed) { for( int i = 0; i < typez.count(); i++) { if (format.sampleType() == typez.at(i)) { match = true; break; } } if (!match) failed = true; } if(!failed) { // settings work return true; } return false; }
void tst_QAudioDecoderBackend::deviceTest() { QAudioDecoder d; QAudioBuffer buffer; quint64 duration = 0; int sampleCount = 0; QSignalSpy readySpy(&d, SIGNAL(bufferReady())); QSignalSpy bufferChangedSpy(&d, SIGNAL(bufferAvailableChanged(bool))); QSignalSpy errorSpy(&d, SIGNAL(error(QAudioDecoder::Error))); QSignalSpy stateSpy(&d, SIGNAL(stateChanged(QAudioDecoder::State))); QSignalSpy durationSpy(&d, SIGNAL(durationChanged(qint64))); QSignalSpy finishedSpy(&d, SIGNAL(finished())); QSignalSpy positionSpy(&d, SIGNAL(positionChanged(qint64))); QVERIFY(d.state() == QAudioDecoder::StoppedState); QVERIFY(d.bufferAvailable() == false); QCOMPARE(d.sourceFilename(), QString("")); QVERIFY(d.audioFormat() == QAudioFormat()); QFileInfo fileInfo(QFINDTESTDATA(TEST_FILE_NAME)); QFile file(fileInfo.absoluteFilePath()); QVERIFY(file.open(QIODevice::ReadOnly)); d.setSourceDevice(&file); QVERIFY(d.sourceDevice() == &file); QVERIFY(d.sourceFilename().isEmpty()); // We haven't set the format yet QVERIFY(d.audioFormat() == QAudioFormat()); d.start(); QTRY_VERIFY(d.state() == QAudioDecoder::DecodingState); QTRY_VERIFY(!stateSpy.isEmpty()); QTRY_VERIFY(!readySpy.isEmpty()); QTRY_VERIFY(!bufferChangedSpy.isEmpty()); QVERIFY(d.bufferAvailable()); QTRY_VERIFY(!durationSpy.isEmpty()); QVERIFY(qAbs(d.duration() - 1000) < 20); buffer = d.read(); QVERIFY(buffer.isValid()); // Test file is 44.1K 16bit mono QCOMPARE(buffer.format().channelCount(), 1); QCOMPARE(buffer.format().sampleRate(), 44100); QCOMPARE(buffer.format().sampleSize(), 16); QCOMPARE(buffer.format().sampleType(), QAudioFormat::SignedInt); QCOMPARE(buffer.format().codec(), QString("audio/pcm")); QVERIFY(errorSpy.isEmpty()); duration += buffer.duration(); sampleCount += buffer.sampleCount(); // Now drain the decoder if (sampleCount < 44094) { QTRY_COMPARE(d.bufferAvailable(), true); } while (d.bufferAvailable()) { buffer = d.read(); QVERIFY(buffer.isValid()); QTRY_VERIFY(!positionSpy.isEmpty()); QVERIFY(positionSpy.takeLast().at(0).toLongLong() == qint64(duration / 1000)); QVERIFY(d.position() - (duration / 1000) < 20); duration += buffer.duration(); sampleCount += buffer.sampleCount(); if (sampleCount < 44094) { QTRY_COMPARE(d.bufferAvailable(), true); } } // Make sure the duration is roughly correct (+/- 20ms) QCOMPARE(sampleCount, 44094); QVERIFY(qAbs(qint64(duration) - 1000000) < 20000); QVERIFY(qAbs((d.position() + (buffer.duration() / 1000)) - 1000) < 20); QTRY_COMPARE(finishedSpy.count(), 1); QVERIFY(!d.bufferAvailable()); QTRY_COMPARE(d.state(), QAudioDecoder::StoppedState); d.stop(); QTRY_COMPARE(d.state(), QAudioDecoder::StoppedState); QVERIFY(!d.bufferAvailable()); QTRY_COMPARE(durationSpy.count(), 2); QCOMPARE(d.duration(), qint64(-1)); readySpy.clear(); bufferChangedSpy.clear(); stateSpy.clear(); durationSpy.clear(); finishedSpy.clear(); positionSpy.clear(); // Now try changing formats QAudioFormat format; format.setChannelCount(2); format.setSampleSize(8); format.setSampleRate(8000); format.setCodec("audio/pcm"); format.setSampleType(QAudioFormat::SignedInt); d.setAudioFormat(format); // Make sure it stuck QVERIFY(d.audioFormat() == format); d.start(); QTRY_VERIFY(d.state() == QAudioDecoder::DecodingState); QTRY_VERIFY(!stateSpy.isEmpty()); QTRY_VERIFY(!readySpy.isEmpty()); QTRY_VERIFY(!bufferChangedSpy.isEmpty()); QVERIFY(d.bufferAvailable()); QTRY_VERIFY(!durationSpy.isEmpty()); QVERIFY(qAbs(d.duration() - 1000) < 20); buffer = d.read(); QVERIFY(buffer.isValid()); // See if we got the right format QVERIFY(buffer.format() == format); // The decoder should still have the same format QVERIFY(d.audioFormat() == format); QVERIFY(errorSpy.isEmpty()); d.stop(); QTRY_COMPARE(d.state(), QAudioDecoder::StoppedState); QVERIFY(!d.bufferAvailable()); QTRY_COMPARE(durationSpy.count(), 2); QCOMPARE(d.duration(), qint64(-1)); }
bool QAudioDeviceInfoInternal::testSettings(const QAudioFormat& format) const { // Set nearest to closest settings that do work. // See if what is in settings will work (return value). int err = 0; snd_pcm_t* handle; snd_pcm_hw_params_t *params; QString dev = device; QList<QByteArray> devices = QAudioDeviceInfoInternal::availableDevices(QAudio::AudioOutput); if(dev.compare(QLatin1String("default")) == 0) { #if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14) dev = QLatin1String(devices.first().constData()); #else dev = QLatin1String("hw:0,0"); #endif } else { #if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14) dev = device; #else int idx = 0; char *name; QString shortName = device.mid(device.indexOf(QLatin1String("="),0)+1); while(snd_card_get_name(idx,&name) == 0) { if(shortName.compare(QLatin1String(name)) == 0) break; idx++; } dev = QString(QLatin1String("hw:%1,0")).arg(idx); #endif } if(mode == QAudio::AudioOutput) { err=snd_pcm_open( &handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_PLAYBACK,0); } else { err=snd_pcm_open( &handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_CAPTURE,0); } if(err < 0) { handle = 0; return false; } bool testChannel = false; bool testCodec = false; bool testFreq = false; bool testType = false; bool testSize = false; int dir = 0; snd_pcm_nonblock( handle, 0 ); snd_pcm_hw_params_alloca( ¶ms ); snd_pcm_hw_params_any( handle, params ); // set the values! snd_pcm_hw_params_set_channels(handle,params,format.channels()); snd_pcm_hw_params_set_rate(handle,params,format.frequency(),dir); err = -1; switch(format.sampleSize()) { case 8: if(format.sampleType() == QAudioFormat::SignedInt) err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S8); else if(format.sampleType() == QAudioFormat::UnSignedInt) err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U8); break; case 16: if(format.sampleType() == QAudioFormat::SignedInt) { if(format.byteOrder() == QAudioFormat::LittleEndian) err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_LE); else if(format.byteOrder() == QAudioFormat::BigEndian) err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_BE); } else if(format.sampleType() == QAudioFormat::UnSignedInt) { if(format.byteOrder() == QAudioFormat::LittleEndian) err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_LE); else if(format.byteOrder() == QAudioFormat::BigEndian) err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_BE); } break; case 32: if(format.sampleType() == QAudioFormat::SignedInt) { if(format.byteOrder() == QAudioFormat::LittleEndian) err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_LE); else if(format.byteOrder() == QAudioFormat::BigEndian) err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_BE); } else if(format.sampleType() == QAudioFormat::UnSignedInt) { if(format.byteOrder() == QAudioFormat::LittleEndian) err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_LE); else if(format.byteOrder() == QAudioFormat::BigEndian) err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_BE); } } // For now, just accept only audio/pcm codec if(!format.codec().startsWith(QLatin1String("audio/pcm"))) { err=-1; } else testCodec = true; if(err>=0 && format.channels() != -1) { err = snd_pcm_hw_params_test_channels(handle,params,format.channels()); if(err>=0) err = snd_pcm_hw_params_set_channels(handle,params,format.channels()); if(err>=0) testChannel = true; } if(err>=0 && format.frequency() != -1) { err = snd_pcm_hw_params_test_rate(handle,params,format.frequency(),0); if(err>=0) err = snd_pcm_hw_params_set_rate(handle,params,format.frequency(),dir); if(err>=0) testFreq = true; } if((err>=0 && format.sampleSize() != -1) && (format.sampleType() != QAudioFormat::Unknown)) { switch(format.sampleSize()) { case 8: if(format.sampleType() == QAudioFormat::SignedInt) err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S8); else if(format.sampleType() == QAudioFormat::UnSignedInt) err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U8); break; case 16: if(format.sampleType() == QAudioFormat::SignedInt) { if(format.byteOrder() == QAudioFormat::LittleEndian) err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_LE); else if(format.byteOrder() == QAudioFormat::BigEndian) err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_BE); } else if(format.sampleType() == QAudioFormat::UnSignedInt) { if(format.byteOrder() == QAudioFormat::LittleEndian) err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_LE); else if(format.byteOrder() == QAudioFormat::BigEndian) err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_BE); } break; case 32: if(format.sampleType() == QAudioFormat::SignedInt) { if(format.byteOrder() == QAudioFormat::LittleEndian) err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_LE); else if(format.byteOrder() == QAudioFormat::BigEndian) err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_BE); } else if(format.sampleType() == QAudioFormat::UnSignedInt) { if(format.byteOrder() == QAudioFormat::LittleEndian) err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_LE); else if(format.byteOrder() == QAudioFormat::BigEndian) err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_BE); } } if(err>=0) { testSize = true; testType = true; } } if(err>=0) err = snd_pcm_hw_params(handle, params); if(err == 0) { // settings work // close() if(handle) snd_pcm_close(handle); return true; } if(handle) snd_pcm_close(handle); return false; }
bool isPCM(const QAudioFormat &format) { return (format.codec() == "audio/pcm"); }
QAudioFormat QAudioDeviceInfoInternal::preferredFormat() const { QAudioFormat nearest; if(mode == QAudio::AudioOutput) { nearest.setFrequency(44100); nearest.setChannels(2); nearest.setByteOrder(QAudioFormat::LittleEndian); nearest.setSampleType(QAudioFormat::SignedInt); nearest.setSampleSize(16); nearest.setCodec(QLatin1String("audio/pcm")); } else { nearest.setFrequency(8000); nearest.setChannels(1); nearest.setSampleType(QAudioFormat::UnSignedInt); nearest.setSampleSize(8); nearest.setCodec(QLatin1String("audio/pcm")); if(!testSettings(nearest)) { nearest.setChannels(2); nearest.setSampleSize(16); nearest.setSampleType(QAudioFormat::SignedInt); } } return nearest; }
qreal nyquistFrequency(const QAudioFormat &format) { return format.sampleRate() / 2; }
void AudioEncoderControl::setAudioSettings(const QAudioEncoderSettings &settings) { QAudioFormat fmt = m_session->format(); if (settings.encodingMode() == QMultimedia::ConstantQualityEncoding) { if (settings.quality() == QMultimedia::LowQuality) { fmt.setSampleSize(8); fmt.setChannelCount(1); fmt.setSampleRate(8000); fmt.setSampleType(QAudioFormat::UnSignedInt); } else if (settings.quality() == QMultimedia::NormalQuality) { fmt.setSampleSize(16); fmt.setChannelCount(1); fmt.setSampleRate(22050); fmt.setSampleType(QAudioFormat::SignedInt); } else { fmt.setSampleSize(16); fmt.setChannelCount(1); fmt.setSampleRate(44100); fmt.setSampleType(QAudioFormat::SignedInt); } } else { fmt.setChannelCount(settings.channelCount()); fmt.setSampleRate(settings.sampleRate()); if (settings.sampleRate() == 8000 && settings.bitRate() == 8000) { fmt.setSampleType(QAudioFormat::UnSignedInt); fmt.setSampleSize(8); } else { fmt.setSampleSize(16); fmt.setSampleType(QAudioFormat::SignedInt); } } fmt.setCodec("audio/pcm"); m_session->setFormat(fmt); m_settings = settings; }
bool Engine::selectFormat() { bool foundSupportedFormat = false; if (m_file || QAudioFormat() != m_format) { QAudioFormat format = m_format; if (m_file) // Header is read from the WAV file; just need to check whether // it is supported by the audio output device format = m_file->fileFormat(); if (m_audioOutputDevice.isFormatSupported(format)) { setFormat(format); foundSupportedFormat = true; } } else { QList<int> sampleRatesList; #ifdef Q_OS_WIN // The Windows audio backend does not correctly report format support // (see QTBUG-9100). Furthermore, although the audio subsystem captures // at 11025Hz, the resulting audio is corrupted. sampleRatesList += 8000; #endif if (!m_generateTone) sampleRatesList += m_audioInputDevice.supportedSampleRates(); sampleRatesList += m_audioOutputDevice.supportedSampleRates(); sampleRatesList = sampleRatesList.toSet().toList(); // remove duplicates qSort(sampleRatesList); ENGINE_DEBUG << "Engine::initialize frequenciesList" << sampleRatesList; QList<int> channelsList; channelsList += m_audioInputDevice.supportedChannelCounts(); channelsList += m_audioOutputDevice.supportedChannelCounts(); channelsList = channelsList.toSet().toList(); qSort(channelsList); ENGINE_DEBUG << "Engine::initialize channelsList" << channelsList; QAudioFormat format; format.setByteOrder(QAudioFormat::LittleEndian); format.setCodec("audio/pcm"); format.setSampleSize(16); format.setSampleType(QAudioFormat::SignedInt); int sampleRate, channels; foreach (sampleRate, sampleRatesList) { if (foundSupportedFormat) break; format.setSampleRate(sampleRate); foreach (channels, channelsList) { format.setChannelCount(channels); const bool inputSupport = m_generateTone || m_audioInputDevice.isFormatSupported(format); const bool outputSupport = m_audioOutputDevice.isFormatSupported(format); ENGINE_DEBUG << "Engine::initialize checking " << format << "input" << inputSupport << "output" << outputSupport; if (inputSupport && outputSupport) { foundSupportedFormat = true; break; } } } if (!foundSupportedFormat) format = QAudioFormat(); setFormat(format); }
Client::Client(QWidget *parent) : QMainWindow(parent), protocolClient(nullptr), settings(nullptr), audioOutput(nullptr), connectionState(ConnectionState::STATE_DISCONNECTED), serverConfiguration(nullptr), clientConfiguration(nullptr), contactRegistry(ContactRegistry::getInstance()) { ui.setupUi(this); ui.listContacts->setContextMenuPolicy(Qt::CustomContextMenu); connectionTimer.start(500); OPENMITTSU_CONNECT(&connectionTimer, timeout(), this, connectionTimerOnTimer()); QCoreApplication::setOrganizationName("BliZZarD"); QCoreApplication::setOrganizationDomain("philippberger.de"); QCoreApplication::setApplicationName("OpenMittsu"); this->settings = new QSettings(this); // Initialize in the right thread MessageCenter* mc = MessageCenter::getInstance(); mc->setTabContainer(ui.tabWidget); OPENMITTSU_CONNECT(mc, newUnreadMessageAvailable(ChatTab*), this, messageCenterOnHasUnreadMessages(ChatTab*)); QString const apiServerRootCertificate = QStringLiteral("LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUVZVENDQTBtZ0F3SUJBZ0lKQU0xRFIvREJSRnBRTUEwR0NTcUdTSWIzRFFFQkJRVUFNSDB4Q3pBSkJnTlYKQkFZVEFrTklNUXN3Q1FZRFZRUUlFd0phU0RFUE1BMEdBMVVFQnhNR1duVnlhV05vTVJBd0RnWURWUVFLRXdkVQphSEpsWlcxaE1Rc3dDUVlEVlFRTEV3SkRRVEVUTUJFR0ExVUVBeE1LVkdoeVpXVnRZU0JEUVRFY01Cb0dDU3FHClNJYjNEUUVKQVJZTlkyRkFkR2h5WldWdFlTNWphREFlRncweE1qRXhNVE14TVRVNE5UaGFGdzB6TWpFeE1EZ3gKTVRVNE5UaGFNSDB4Q3pBSkJnTlZCQVlUQWtOSU1Rc3dDUVlEVlFRSUV3SmFTREVQTUEwR0ExVUVCeE1HV25WeQphV05vTVJBd0RnWURWUVFLRXdkVWFISmxaVzFoTVFzd0NRWURWUVFMRXdKRFFURVRNQkVHQTFVRUF4TUtWR2h5ClpXVnRZU0JEUVRFY01Cb0dDU3FHU0liM0RRRUpBUllOWTJGQWRHaHlaV1Z0WVM1amFEQ0NBU0l3RFFZSktvWkkKaHZjTkFRRUJCUUFEZ2dFUEFEQ0NBUW9DZ2dFQkFLOEdkb1Q3SXBOQzNEejdJVUdZVzlwT0J3eCs5RW5EWnJrTgpWRDhsM0tmQkhqR1RkaTlnUTZOaCttUTkveVE4MjU0VDJiaWc5cDBoY244a2pnRVFnSldIcE5oWW5PaHkzaTBqCmNtbHpiMU1GL2RlRmpKVnR1TVAzdHFUd2lNYXZwd2VvYTIwbEdEbi9DTFpvZHUwUmE4b0w3OGI2RlZ6dE5rV2cKUGRpV0NsTWswSlBQTWxmTEVpSzhoZkhFKzZtUlZYbWkxMml0SzFzZW1td3lIS2RqOWZHNFg5K3JRMnNLdUxmZQpqeDd1RnhuQUYrR2l2Q3VDbzh4Zk9lc0x3NzJ2eCtXN21tZFlzaGcvbFhPY3F2c3pRUS9MbUZFVlFZeE5hZWVWCm5QU0FzK2h0OHZVUFc0c1g5SWtYS1ZnQkpkMVIxaXNVcG9GNmRLbFVleG12THhFeWY1Y0NBd0VBQWFPQjR6Q0IKNERBZEJnTlZIUTRFRmdRVXc2TGFDNytKNjJyS2RhVEEzN2tBWVlVYnJrZ3dnYkFHQTFVZEl3U0JxRENCcFlBVQp3NkxhQzcrSjYycktkYVRBMzdrQVlZVWJya2loZ1lHa2Z6QjlNUXN3Q1FZRFZRUUdFd0pEU0RFTE1Ba0dBMVVFCkNCTUNXa2d4RHpBTkJnTlZCQWNUQmxwMWNtbGphREVRTUE0R0ExVUVDaE1IVkdoeVpXVnRZVEVMTUFrR0ExVUUKQ3hNQ1EwRXhFekFSQmdOVkJBTVRDbFJvY21WbGJXRWdRMEV4SERBYUJna3Foa2lHOXcwQkNRRVdEV05oUUhSbwpjbVZsYldFdVkyaUNDUUROUTBmd3dVUmFVREFNQmdOVkhSTUVCVEFEQVFIL01BMEdDU3FHU0liM0RRRUJCUVVBCkE0SUJBUUFSSE15SUhCREZ1bCtodmpBQ3Q2cjBFQUhZd1I5R1FTZ2hJUXNmSHQ4Y3lWY3ptRW5KSDlocnZoOVEKVml2bTdtcmZ2ZWlobU5YQW40V2xHd1ErQUN1VnRUTHh3OEVyYlNUN0lNQU94OW5wSGYva25nblo0blN3VVJGOQpyQ0V5SHExNzlwTlhwT3paMjU3RTVyMGF2TU5OWFhEd3VsdzAzaUJFMjFlYmQwMHBHMTFHVnEvSTI2cys4QmpuCkRLUlBxdUtyU080L2x1RUR2TDRuZ2lRalpwMzJTOVoxSzlzVk96cXRRN0k5enplVUFEbTNhVmEvQnBhdzRpTVIKMVNJN285YUpZaVJpMWd4WVAyQlVBMUlGcXI4Tnp5ZkdEN3RSSGRxN2JaT3hYQWx1djgxZGNiejBTQlg4U2dWMQo0SEVLYzZ4TUFObllzL2FZS2p2bVAwVnBPdlJVCi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0="); PublicKey const longTermServerPublicKey = PublicKey::fromHexString(QStringLiteral("b851ae1bf275ebe6851ca7f5206b495080927159787e9aaabbeb4e55af09d805")); serverConfiguration = new ServerConfiguration(QStringLiteral("g-xx.0.threema.ch"), 5222, longTermServerPublicKey, QStringLiteral("https://api.threema.ch/identity/%1"), QStringLiteral("Threema/2.2A"), apiServerRootCertificate, QStringLiteral("https://%1.blob.threema.ch/%2"), QStringLiteral("https://%1.blob.threema.ch/%2/done"), QStringLiteral("https://upload.blob.threema.ch/upload"), QStringLiteral("Threema/2.2A"), apiServerRootCertificate); // Load stored settings if (settings->contains("clientConfigurationFile")) { if (validateClientConfigurationFile(settings->value("clientConfigurationFile").toString(), true)) { this->clientConfiguration = new ClientConfiguration(ClientConfiguration::fromFile(settings->value("clientConfigurationFile").toString())); updateClientSettingsInfo(settings->value("clientConfigurationFile").toString()); } else { LOGGER_DEBUG("Removing key \"clientConfigurationFile\" from stored settings as the file is not valid."); settings->remove("clientConfigurationFile"); } } // Load Contacts if (settings->contains("contactsFile")) { if (validateKnownIdentitiesFile(settings->value("contactsFile").toString(), true)) { contactRegistry->fromFile(settings->value("contactsFile").toString()); updateKnownContactsInfo(settings->value("contactsFile").toString()); } else { LOGGER_DEBUG("Removing key \"contactsFile\" from stored settings as the file is not valid."); settings->remove("contactsFile"); } } OPENMITTSU_CONNECT(contactRegistry, identitiesChanged(), this, contactRegistryOnIdentitiesChanged()); OPENMITTSU_CONNECT(ui.btnConnect, clicked(), this, btnConnectOnClick()); OPENMITTSU_CONNECT(ui.btnOpenClientIni, clicked(), this, btnOpenClientIniOnClick()); OPENMITTSU_CONNECT(ui.btnOpenContacts, clicked(), this, btnOpenContactsOnClick()); OPENMITTSU_CONNECT(ui.listContacts, itemDoubleClicked(QListWidgetItem*), this, listContactsOnDoubleClick(QListWidgetItem*)); OPENMITTSU_CONNECT(ui.listContacts, customContextMenuRequested(const QPoint&), this, listContactsOnContextMenu(const QPoint&)); OPENMITTSU_CONNECT(ui.tabWidget, currentChanged(int), this, chatTabWidgetOnCurrentTabChanged(int)); // Menus OPENMITTSU_CONNECT(ui.actionLicense, triggered(), this, menuAboutLicenseOnClick()); OPENMITTSU_CONNECT(ui.actionAbout, triggered(), this, menuAboutAboutOnClick()); OPENMITTSU_CONNECT(ui.actionAbout_Qt, triggered(), this, menuAboutAboutQtOnClick()); OPENMITTSU_CONNECT(ui.actionAdd_a_Contact, triggered(), this, menuContactAddOnClick()); OPENMITTSU_CONNECT(ui.actionDelete_a_Contact, triggered(), this, menuContactDeleteOnClick()); OPENMITTSU_CONNECT(ui.actionEdit_a_Contact, triggered(), this, menuContactEditOnClick()); OPENMITTSU_CONNECT(ui.actionSave_to_file, triggered(), this, menuContactSaveToFileOnClick()); OPENMITTSU_CONNECT(ui.actionAdd_Group, triggered(), this, menuGroupAddOnClick()); OPENMITTSU_CONNECT(ui.actionEdit_Group, triggered(), this, menuGroupEditOnClick()); OPENMITTSU_CONNECT(ui.actionLeave_Group, triggered(), this, menuGroupLeaveOnClick()); OPENMITTSU_CONNECT(ui.actionCreate_Backup, triggered(), this, menuIdentityCreateBackupOnClick()); OPENMITTSU_CONNECT(ui.actionLoad_Backup, triggered(), this, menuIdentityLoadBackupOnClick()); OPENMITTSU_CONNECT(ui.actionShow_Fingerprint, triggered(), this, menuIdentityShowFingerprintOnClick()); OPENMITTSU_CONNECT(ui.actionShow_Public_Key, triggered(), this, menuIdentityShowPublicKeyOnClick()); OPENMITTSU_CONNECT(ui.actionStatistics, triggered(), this, menuAboutStatisticsOnClick()); OPENMITTSU_CONNECT(ui.actionExit, triggered(), this, menuFileExitOnClick()); protocolClientThread.start(); protocolClient = nullptr; OPENMITTSU_CONNECT(&protocolClientThread, finished(), this, threadFinished()); // Load audio resources QAudioFormat format; format.setSampleRate(44100); format.setChannelCount(2); format.setSampleSize(16); format.setCodec("audio/pcm"); format.setByteOrder(QAudioFormat::LittleEndian); format.setSampleType(QAudioFormat::UnSignedInt); audioOutput = new QAudioOutput(format, this); OPENMITTSU_CONNECT(audioOutput, stateChanged(QAudio::State), this, audioOutputOnStateChanged(QAudio::State)); receivedMessageAudioFile.setFileName(":/audio/ReceivedMessage.wav"); if (!receivedMessageAudioFile.open(QFile::ReadOnly)) { throw InternalErrorException() << "Could not load audio file ReceivedMessage.wav in the Client."; } // Call Updater OPENMITTSU_CONNECT_QUEUED(&updater, foundNewVersion(int, int, int, int, QString, QString, QString), this, updaterFoundNewVersion(int, int, int, int, QString, QString, QString)); QTimer::singleShot(0, &updater, SLOT(start())); // Call the setup() function in the thread QTimer::singleShot(0, protocolClient, SLOT(setup())); contactRegistryOnIdentitiesChanged(); // Restore Window location and size restoreGeometry(settings->value("clientMainWindowGeometry").toByteArray()); restoreState(settings->value("clientMainWindowState").toByteArray()); }
bool OutputQtMultimedia::initialize(quint32 freq, ChannelMap map, Qmmp::AudioFormat format) { QAudioFormat qformat; qformat.setCodec("audio/pcm"); qformat.setFrequency(freq); qformat.setByteOrder(QAudioFormat::LittleEndian); qformat.setChannels(map.size()); qformat.setSampleType(QAudioFormat::SignedInt); //Size of sample representation in input data. For 24-bit is 4, high byte is ignored. qint64 bytes_per_sample = 0; switch (format) { case Qmmp::PCM_S8: qformat.setSampleSize(8); bytes_per_sample = 1; break; case Qmmp::PCM_S16LE: qformat.setSampleSize(16); bytes_per_sample = 2; break; case Qmmp::PCM_S24LE: qformat.setSampleSize(24); bytes_per_sample = 4; break; case Qmmp::PCM_S32LE: qformat.setSampleSize(32); bytes_per_sample = 4; break; default: break; } if (!qformat.isValid()) return false; m_bytes_per_second = bytes_per_sample * freq * qformat.channels(); const QSettings settings(Qmmp::configFile(), QSettings::IniFormat); const QString saved_device_name = settings.value("QTMULTIMEDIA/device").toString(); QAudioDeviceInfo device_info; if (!saved_device_name.isEmpty()) { const QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput); foreach (const QAudioDeviceInfo &info, devices) { if (info.deviceName()==saved_device_name) { if (info.isFormatSupported(qformat)) { device_info = info; break; } else qDebug() << "OutputQtMultimedia: Output device: " << saved_device_name << " is not supported"; } } } if (device_info.isNull()) { device_info = QAudioDeviceInfo::defaultOutputDevice(); if (!device_info.isFormatSupported(qformat)) return false; } qDebug() << "OutputQtMultimedia: Using output device: " << device_info.deviceName(); m_output.reset(new QAudioOutput(device_info, qformat)); m_buffer = m_output->start(); configure(freq, map, format); return true; }
QAudioFormat QAudioDeviceInfo::nearestFormat(const QAudioFormat &settings) const { if (isFormatSupported(settings)) return settings; QAudioFormat nearest = settings; nearest.setCodec(QLatin1String("audio/pcm")); if (nearest.sampleType() == QAudioFormat::Unknown) { QAudioFormat preferred = preferredFormat(); nearest.setSampleType(preferred.sampleType()); } QMap<int,int> testFrequencies; QList<int> frequenciesAvailable = supportedFrequencies(); QMap<int,int> testSampleSizes; QList<int> sampleSizesAvailable = supportedSampleSizes(); // Get sorted sampleSizes (equal to and ascending values only) if (sampleSizesAvailable.contains(settings.sampleSize())) testSampleSizes.insert(0,settings.sampleSize()); sampleSizesAvailable.removeAll(settings.sampleSize()); foreach (int size, sampleSizesAvailable) { int larger = (size > settings.sampleSize()) ? size : settings.sampleSize(); int smaller = (size > settings.sampleSize()) ? settings.sampleSize() : size; if (size >= settings.sampleSize()) { int diff = larger - smaller; testSampleSizes.insert(diff, size); } }