From ba6d5b13e4cd306a1c4517780fba496d669dd596 Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Sun, 21 Mar 2021 11:30:29 +0000 Subject: improved visualization synchronization git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@9766 90c681e8-e032-0410-971d-27865f9a5e38 --- src/qmmp/visualbuffer.cpp | 14 ++++++++------ src/qmmp/visualbuffer_p.h | 1 + 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/qmmp/visualbuffer.cpp b/src/qmmp/visualbuffer.cpp index 5127f7639..3475ab81e 100644 --- a/src/qmmp/visualbuffer.cpp +++ b/src/qmmp/visualbuffer.cpp @@ -53,25 +53,25 @@ void VisualBuffer::add(float *pcm, int samples, int channels, qint64 ts, qint64 VisualNode *b = &m_buffer[m_add_index]; stereo_from_multichannel(b->data[0], b->data[1], pcm, qMin(512, samples / channels), channels); b->ts = ts; - delay = qBound(50LL, delay, 1000LL); //limit visualization delay - m_elapsed = qMax(0LL, ts - delay); + b->delay = qBound(50LL, delay, 1000LL); //limit visualization delay + m_elapsed = ts; m_time.restart(); } VisualNode *VisualBuffer::take() { int steps = 0; - int t = m_elapsed + m_time.elapsed(); + qint64 t = m_elapsed + m_time.elapsed(); while(m_buffer[m_take_index].used || - ((m_buffer[m_take_index].ts < t) && (steps++ < VISUAL_BUFFER_SIZE))) + ((m_buffer[m_take_index].ts + m_buffer[m_take_index].delay < t) && (steps++ < VISUAL_BUFFER_SIZE))) { m_take_index++; m_take_index %= VISUAL_BUFFER_SIZE; } - if(m_buffer[m_take_index].ts < t) //unable to find node + if(m_buffer[m_take_index].ts + m_buffer[m_take_index].delay < t) //unable to find node return nullptr; - if(m_buffer[m_take_index].ts > t + 100) //node is more than 100 ms in the future. So, ignore it. + if(m_buffer[m_take_index].ts + m_buffer[m_take_index].delay > t + 100) //node is more than 100 ms in the future. So, ignore it. return nullptr; return &m_buffer[m_take_index]; @@ -81,9 +81,11 @@ void VisualBuffer::clear() { m_take_index = 0; m_add_index = 0; + m_elapsed = 0; for(int i = 0; i < VISUAL_BUFFER_SIZE; ++i) { m_buffer[i].ts = 0; + m_buffer[i].delay = 0; m_buffer[i].used = false; memset(m_buffer[i].data[0], 0, 512 * sizeof(float)); memset(m_buffer[i].data[1], 0, 512 * sizeof(float)); diff --git a/src/qmmp/visualbuffer_p.h b/src/qmmp/visualbuffer_p.h index 8d65b1836..818cc4d63 100644 --- a/src/qmmp/visualbuffer_p.h +++ b/src/qmmp/visualbuffer_p.h @@ -33,6 +33,7 @@ public: float data[2][512] = { 0 }; bool used = false; qint64 ts = 0; + qint64 delay = 0; }; class VisualBuffer -- cgit v1.2.3-13-gbd6f