Skip to content

Commit

Permalink
Add Audio Peak Meter Scope.
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatherly committed Mar 1, 2015
1 parent 7310c52 commit edc2cd6
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/controllers/scopecontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "scopecontroller.h"
#include "widgets/scopes/audiopeakmeterscopewidget.h"
#include "widgets/scopes/audiowaveformscopewidget.h"
#include "widgets/scopes/videowaveformscopewidget.h"
#include "docks/scopedock.h"
Expand All @@ -29,6 +30,7 @@ ScopeController::ScopeController(QMainWindow* mainWindow, QMenu* menu)
{
qDebug() << "begin";
QMenu* scopeMenu = menu->addMenu(tr("Scopes"));
createScopeDock<AudioPeakMeterScopeWidget>(mainWindow, scopeMenu);
createScopeDock<AudioWaveformScopeWidget>(mainWindow, scopeMenu);
// if (!Settings.playerGPU()) {
// createScopeDock<VideoWaveformScopeWidget>(mainWindow, scopeMenu);
Expand Down
2 changes: 2 additions & 0 deletions src/src.pro
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ SOURCES += main.cpp\
docks/scopedock.cpp \
controllers/scopecontroller.cpp \
widgets/scopes/scopewidget.cpp \
widgets/scopes/audiopeakmeterscopewidget.cpp \
widgets/scopes/audiowaveformscopewidget.cpp \
widgets/scopes/videowaveformscopewidget.cpp \
sharedframe.cpp \
Expand Down Expand Up @@ -181,6 +182,7 @@ HEADERS += mainwindow.h \
docks/scopedock.h \
controllers/scopecontroller.h \
widgets/scopes/scopewidget.h \
widgets/scopes/audiopeakmeterscopewidget.h \
widgets/scopes/audiowaveformscopewidget.h \
widgets/scopes/videowaveformscopewidget.h \
dataqueue.h \
Expand Down
81 changes: 81 additions & 0 deletions src/widgets/scopes/audiopeakmeterscopewidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (c) 2015 Meltytech, LLC
* Author: Brian Matherly <code@brianmatherly.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "audiopeakmeterscopewidget.h"
#include <QDebug>
#include <QVBoxLayout>
#include <MltProfile.h>
#include "widgets/audiosignal.h"

AudioPeakMeterScopeWidget::AudioPeakMeterScopeWidget()
: ScopeWidget("AudioPeakMeter")
, m_filter(0)
, m_audioSignal(0)
, m_orientation(Qt::Horizontal)
{
qDebug() << "begin";
Mlt::Profile profile;
m_filter = new Mlt::Filter(profile, "audiolevel");
qRegisterMetaType< QVector<double> >("QVector<double>");
setAutoFillBackground(true);
setBackgroundRole(QPalette::Base);

QVBoxLayout *vlayout = new QVBoxLayout(this);
vlayout->setContentsMargins(4, 4, 4, 4);
m_audioSignal = new AudioSignal(this);
vlayout->addWidget(m_audioSignal);

m_audioSignal->setMinimumSize(41, 300);
m_audioSignal->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
setMinimumSize(49, 308);
setMaximumSize(49, 508);
qDebug() << "end";
}

AudioPeakMeterScopeWidget::~AudioPeakMeterScopeWidget()
{
delete m_filter;
}

void AudioPeakMeterScopeWidget::refreshScope(const QSize& /*size*/, bool /*full*/)
{
SharedFrame sFrame;
while (m_queue.count() > 0) {
sFrame = m_queue.pop();
if (sFrame.is_valid() && sFrame.get_audio_samples() > 0) {
mlt_audio_format format = mlt_audio_s16;
int channels = sFrame.get_audio_channels();
int frequency = sFrame.get_audio_frequency();
int samples = sFrame.get_audio_samples();
Mlt::Frame mFrame = sFrame.clone(true, false, false);
m_filter->process(mFrame);
mFrame.get_audio( format, frequency, channels, samples );
QVector<double> levels;
while (channels--) {
QString s = QString("meta.media.audio_level.%1").arg(channels);
levels << mFrame.get_double(s.toLatin1().constData());
}
QMetaObject::invokeMethod(m_audioSignal, "slotAudioLevels", Qt::QueuedConnection, Q_ARG(const QVector<double>&, levels));
}
}
}

QString AudioPeakMeterScopeWidget::getTitle()
{
return tr("Audio Peak Meter");
}
51 changes: 51 additions & 0 deletions src/widgets/scopes/audiopeakmeterscopewidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2015 Meltytech, LLC
* Author: Brian Matherly <code@brianmatherly.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef AUDIOPEAKMETERSCOPEWIDGET_H
#define AUDIOPEAKMETERSCOPEWIDGET_H

#include "scopewidget.h"
#include <QMutex>
#include <QImage>
#include <QVector>
#include <MltFilter.h>

class AudioSignal;

class AudioPeakMeterScopeWidget Q_DECL_FINAL : public ScopeWidget
{
Q_OBJECT

public:
explicit AudioPeakMeterScopeWidget();
~AudioPeakMeterScopeWidget();
QString getTitle();

private:
// Functions run in scope thread.
void refreshScope(const QSize& size, bool full) Q_DECL_OVERRIDE;

// Members accessed by scope thread.
Mlt::Filter* m_filter;

// Members accessed by GUI thread.
AudioSignal* m_audioSignal;
Qt::Orientation m_orientation;
};

#endif // AUDIOPEAKMETERSCOPEWIDGET_H

0 comments on commit edc2cd6

Please sign in to comment.