From 6ddd7c32322b9688ad3323238afb201af89d4ac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santi=20Nore=C3=B1a?= Date: Sun, 13 Jul 2014 21:39:30 +0200 Subject: [PATCH] The bug stills remains, it seems a bug in the reset() function in QAudioOutput not relly resetting the audio buffer... --- src/audiolayerwidget.cpp | 21 ++++++++++----------- src/defines.h | 2 +- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/audiolayerwidget.cpp b/src/audiolayerwidget.cpp index 9213355..be9dfdb 100644 --- a/src/audiolayerwidget.cpp +++ b/src/audiolayerwidget.cpp @@ -42,7 +42,6 @@ AudioLayerWidget::AudioLayerWidget(QWidget *parent, QString name): m_statusLabel->setText(STATUS_LABEL); m_statusValue = new QLabel; m_receiveDMX = new QCheckBox("Receiving DMX", this); -// m_receiveDMX->setCheckable(false); m_receiveDMX->setChecked(false); status->addWidget(m_receiveDMX); status->addWidget(m_statusLabel); @@ -90,8 +89,6 @@ AudioLayerWidget::AudioLayerWidget(QWidget *parent, QString name): progressTime->addWidget(m_progressTimeLabel); progressTime->addWidget(m_progressTime); - -// QHBoxLayout *totalTime = new QHBoxLayout; m_totalTimeLabel = new QLabel; m_totalTimeLabel->setText(TOTAL_TIME_LABEL); m_totalTimeValue = new QTimeEdit; @@ -101,7 +98,6 @@ AudioLayerWidget::AudioLayerWidget(QWidget *parent, QString name): m_totalTimeValue->setMaximumWidth(90); progressTime->addWidget(m_totalTimeLabel); progressTime->addWidget(m_totalTimeValue); -// layout->addLayout(totalTime); layout->addLayout(progressTime); QHBoxLayout *progressSlider = new QHBoxLayout; @@ -141,7 +137,9 @@ AudioLayerWidget::AudioLayerWidget(QWidget *parent, QString name): connect(m_watchDMX, SIGNAL(timeout()), this, SLOT(watchDMXExpired())); m_watchDMX->start(1000); + createAudioOutput(); + pause(); } AudioLayerWidget::~AudioLayerWidget() @@ -189,8 +187,8 @@ void AudioLayerWidget::loadMedia(QString file) if (m_currentMedia == file) return; if (QFile::exists(file)){ - reset(); m_decoder->loadMedia(file); + setInitPosition(); m_currentMedia = file; fileLoaded(file); } @@ -220,7 +218,7 @@ void AudioLayerWidget::notified() void AudioLayerWidget::pullTimerExpired() { if (m_audioOutput && m_audioOutput->state() != QAudio::StoppedState) { - int chunks = m_audioOutput->bytesFree()/m_audioOutput->periodSize(); + int chunks = m_audioOutput->bytesFree() / m_audioOutput->periodSize(); while (chunks) { const qint64 len = m_decoder->read(m_buffer.data(), m_audioOutput->periodSize()); if ( len == -1) { @@ -255,11 +253,11 @@ void AudioLayerWidget::toggleSuspendResume() void AudioLayerWidget::handleStateChanged(QAudio::State state) { if (state == QAudio::SuspendedState) { - m_statusValue->setText(PAUSE_LABEL); + m_statusValue->setText(PAUSE_LABEL); } else if (state == QAudio::ActiveState) { - m_statusValue->setText(PLAY_LABEL); + m_statusValue->setText(PLAY_LABEL); } else if (m_audioOutput->state() == QAudio::StoppedState) { - m_statusValue->setText(STOP_LABEL); + m_statusValue->setText(STOP_LABEL); } else if (state == QAudio::IdleState) { m_statusValue->setText(IDDLE_LABEL); } @@ -275,6 +273,7 @@ void AudioLayerWidget::durationChanged(qint64 dur) void AudioLayerWidget::play() { +// reset(); setInitPosition(); m_pullTimer->start(PULL_TIMER_INTERVAL); m_audioOutput->resume(); @@ -311,12 +310,12 @@ void AudioLayerWidget::reset() m_audioOutput->reset(); m_output = m_audioOutput->start(); Q_CHECK_PTR(m_output); - pause(); +// pause(); } void AudioLayerWidget::setInitPosition() { -// m_buffer.clear(); + reset(); m_decoder->setPos(0); m_progressMs = 0; m_progressTime->setTime(QTime::fromMSecsSinceStartOfDay(m_progressMs)); diff --git a/src/defines.h b/src/defines.h index 681dad2..f48f7dd 100644 --- a/src/defines.h +++ b/src/defines.h @@ -5,7 +5,7 @@ #define COPYRIGHT "(C) 2014 Santi Norena libremediaserver@gmail.com" #define LICENSE "GPL 3 License. See LICENSE.txt and credits.txt for details" -#define LAYERS_NUMBER 4 +#define LAYERS_NUMBER 3 #define DEFAULT_FILE "lms-audio.xlm"