improved audio monitor

This commit is contained in:
itsmattkc
2019-01-22 13:17:38 +11:00
parent e7f05ff64b
commit 8133d4dd9d
6 changed files with 23 additions and 20 deletions
-6
View File
@@ -68,7 +68,6 @@ Timeline::Timeline(QWidget *parent) :
transition_tool_post_clip(-1),
hand_moving(false),
block_repaints(false),
last_frame(0),
scroll(0)
{
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
@@ -443,11 +442,6 @@ void Timeline::repaint_timeline() {
if (sequence != nullptr) {
set_sb_max();
if (last_frame != sequence->playhead) {
audio_monitor->update();
last_frame = sequence->playhead;
}
}
}
}
+1 -2
View File
@@ -231,7 +231,6 @@ private:
QVector<QPushButton*> tool_buttons;
void decheck_tool_buttons(QObject* sender);
void set_tool(int tool);
long last_frame;
int scroll;
void set_sb_max();
@@ -249,7 +248,7 @@ private:
QPushButton* zoomOutButton;
QPushButton* recordButton;
QPushButton* addButton;
QWidget* tool_button_widget;
QWidget* tool_button_widget;
};
#endif // TIMELINE_H
+1 -1
View File
@@ -560,7 +560,7 @@ void Viewer::setup_ui() {
QHBoxLayout* current_timecode_container_layout = new QHBoxLayout(current_timecode_container);
current_timecode_container_layout->setSpacing(0);
current_timecode_container_layout->setMargin(0);
current_timecode_slider = new LabelSlider(current_timecode_container);
current_timecode_slider = new LabelSlider(current_timecode_container);
lower_control_layout->addWidget(current_timecode_container);
QWidget* playback_controls = new QWidget(lower_controls);
+3 -7
View File
@@ -178,19 +178,15 @@ int AudioSenderThread::send_audio_to_output(unsigned long offset, int max) {
averages.resize(channels);
averages.fill(0);
for (int i=0;i<channels;i++) {
averages[i] = 0;
}
int counter = 0;
qint16 sample;
for (unsigned long i=offset;i<lim;i+=2) {
sample = qint16(((audio_ibuffer[i+1] & 0xFF) << 8) | (audio_ibuffer[i] & 0xFF));
averages[counter%channels] += qAbs(double(sample)/32768.0);
counter++;
averages[counter] = qMax((double(sample)/32768.0), averages[counter]);
counter = (counter+1)%channels;
}
double divider = counter / channels;
for (int i=0;i<channels;i++) {
averages[i] = log_volume(1.0-(averages[i]/divider));
averages[i] = log_volume(1.0-(averages[i]));
}
panel_timeline->audio_monitor->set_value(averages);
+13 -4
View File
@@ -21,13 +21,22 @@ extern "C" {
AudioMonitor::AudioMonitor(QWidget *parent) :
QWidget(parent)
{
values.resize(2);
values.fill(1.0);
clear_timer.setInterval(500);
connect(&clear_timer, SIGNAL(timeout()), this, SLOT(clear()));
}
void AudioMonitor::set_value(const QVector<double> &ivalues) {
values = ivalues;
update();
QMetaObject::invokeMethod(&clear_timer, "start");
}
void AudioMonitor::clear() {
clear_timer.stop();
values.fill(1);
update();
}
void AudioMonitor::resizeEvent(QResizeEvent *e) {
@@ -39,10 +48,9 @@ void AudioMonitor::resizeEvent(QResizeEvent *e) {
}
void AudioMonitor::paintEvent(QPaintEvent *) {
if (sequence != nullptr) {
if (sequence != nullptr && values.size() > 0) {
QPainter p(this);
int channel_x = AUDIO_MONITOR_GAP;
// int channel_count = av_get_channel_layout_nb_channels(sequence->audio_layout);
int channel_count = values.size();
int channel_width = (width()/channel_count) - AUDIO_MONITOR_GAP;
int i;
@@ -53,6 +61,7 @@ void AudioMonitor::paintEvent(QPaintEvent *) {
bool peak = false;
r.setHeight(qRound(r.height()*(values.at(i))));
peak = (r.height() == 0);
QRect peak_rect(channel_x, 0, channel_width, AUDIO_MONITOR_PEAK_HEIGHT);
if (peak) {
+5
View File
@@ -2,6 +2,7 @@
#define AUDIOMONITOR_H
#include <QWidget>
#include <QTimer>
class AudioMonitor : public QWidget
{
@@ -21,6 +22,10 @@ public slots:
private:
QLinearGradient gradient;
QVector<double> values;
QTimer clear_timer;
private slots:
void clear();
};
#endif // AUDIOMONITOR_H