diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2017-01-16 10:43:54 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2017-01-16 10:43:54 +0000 |
| commit | a1f1349e58a8f8d3ebc220f188b9d26c49585e4a (patch) | |
| tree | b90a7135c6664ef55b33c7284e5b5470ef1b667c /src | |
| parent | 49e42f5876622a312560a2d5a18fa18cd844cf51 (diff) | |
| download | qmmp-a1f1349e58a8f8d3ebc220f188b9d26c49585e4a.tar.gz qmmp-a1f1349e58a8f8d3ebc220f188b9d26c49585e4a.tar.bz2 qmmp-a1f1349e58a8f8d3ebc220f188b9d26c49585e4a.zip | |
fixed visual buffer
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@6984 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src')
| -rw-r--r-- | src/qmmp/visualbuffer.cpp | 30 | ||||
| -rw-r--r-- | src/qmmp/visualbuffer_p.h | 4 |
2 files changed, 18 insertions, 16 deletions
diff --git a/src/qmmp/visualbuffer.cpp b/src/qmmp/visualbuffer.cpp index 91403ff47..4904c92f6 100644 --- a/src/qmmp/visualbuffer.cpp +++ b/src/qmmp/visualbuffer.cpp @@ -45,22 +45,23 @@ static inline void stereo_from_multichannel(float *l, VisualBuffer::VisualBuffer() { - consumer_pos = 0; - insertion_pos = 0; + m_take_index = 0; + m_add_index = 0; m_elapsed = 0; } void VisualBuffer::add(float *pcm, int samples, int channels, qint64 ts, qint64 delay) { - insertion_pos++; - if (insertion_pos == VISUAL_BUFFER_SIZE ) + m_add_index++; + if (m_add_index == VISUAL_BUFFER_SIZE) { - insertion_pos = 0; + m_add_index = 0; } - VisualNode *b = &m_buffer[insertion_pos]; + 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 = qMax(delay, 50LL); //leave at least 50 ms for the visualization m_elapsed = qMax(0LL, ts - delay); m_time.restart(); } @@ -68,22 +69,23 @@ void VisualBuffer::add(float *pcm, int samples, int channels, qint64 ts, qint64 VisualNode *VisualBuffer::take() { int steps = 0; - int t = m_elapsed/* + m_time.elapsed()*/; - while((m_buffer[consumer_pos].ts < t) && (steps++ < VISUAL_BUFFER_SIZE)) + int t = m_elapsed + m_time.elapsed(); + while(m_buffer[m_take_index].used || + ((m_buffer[m_take_index].ts < t) && (steps++ < VISUAL_BUFFER_SIZE))) { - consumer_pos++; - if(consumer_pos == VISUAL_BUFFER_SIZE) + m_take_index++; + if(m_take_index == VISUAL_BUFFER_SIZE) { - consumer_pos = 0; + m_take_index = 0; } } - return &m_buffer[consumer_pos]; + return &m_buffer[m_take_index]; } void VisualBuffer::clear() { - consumer_pos = 0; - insertion_pos = 0; + m_take_index = 0; + m_add_index = 0; for(int i = 0; i < VISUAL_BUFFER_SIZE; ++i) { m_buffer[i].ts = 0; diff --git a/src/qmmp/visualbuffer_p.h b/src/qmmp/visualbuffer_p.h index 3f9a87269..248ab8cea 100644 --- a/src/qmmp/visualbuffer_p.h +++ b/src/qmmp/visualbuffer_p.h @@ -54,8 +54,8 @@ public: private: VisualNode m_buffer[VISUAL_BUFFER_SIZE]; qint64 m_elapsed; - int consumer_pos; - int insertion_pos; + int m_take_index; + int m_add_index; QTime m_time; QMutex m_mutex; |
