diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2010-10-08 18:06:38 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2010-10-08 18:06:38 +0000 |
| commit | c4749f20a5ad31ed8c68c11547120a0d1da45a8f (patch) | |
| tree | 805248511deeea91f7da2d2881f9afefe9f21b1a /src/ui | |
| parent | 767150cfe9403eb432ea82377664abda214d6e04 (diff) | |
| download | qmmp-c4749f20a5ad31ed8c68c11547120a0d1da45a8f.tar.gz qmmp-c4749f20a5ad31ed8c68c11547120a0d1da45a8f.tar.bz2 qmmp-c4749f20a5ad31ed8c68c11547120a0d1da45a8f.zip | |
dynamic buffer size
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@1928 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/ui')
| -rw-r--r-- | src/ui/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/ui/inlines.h | 93 | ||||
| -rw-r--r-- | src/ui/logscale.cpp | 74 | ||||
| -rw-r--r-- | src/ui/logscale.h | 31 | ||||
| -rw-r--r-- | src/ui/mainvisual.cpp | 91 | ||||
| -rw-r--r-- | src/ui/mainvisual.h | 33 | ||||
| -rw-r--r-- | src/ui/mp3player.cpp | 5 | ||||
| -rw-r--r-- | src/ui/shadedvisual.cpp | 89 | ||||
| -rw-r--r-- | src/ui/shadedvisual.h | 8 | ||||
| -rw-r--r-- | src/ui/ui.pro | 2 |
10 files changed, 104 insertions, 324 deletions
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 5275ad98f..9f9a31774 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -50,7 +50,6 @@ SET(ui_SRCS jumptotrackdialog.cpp keyboardmanager.cpp listwidget.cpp - logscale.cpp mainvisual.cpp mainwindow.cpp monostereo.cpp @@ -107,7 +106,6 @@ SET(ui_MOC_HDRS jumptotrackdialog.h keyboardmanager.h listwidget.h - logscale.h mainvisual.h mainwindow.h monostereo.h diff --git a/src/ui/inlines.h b/src/ui/inlines.h index e2c48d019..39b81bd57 100644 --- a/src/ui/inlines.h +++ b/src/ui/inlines.h @@ -10,8 +10,7 @@ #include "fft.h" // *fast* convenience functions -static inline void -calc_freq(short* dest, short *src) +static inline void calc_freq(short* dest, short *src) { static fft_state *state = NULL; float tmp_out[257]; @@ -26,27 +25,6 @@ calc_freq(short* dest, short *src) dest[i] = ((int) sqrt(tmp_out[i + 1])) >> 8; } -static inline void -calc_mono_freq(short dest[2][256], short src[2][512], int nch) -{ - int i; - short *d, *sl, *sr, tmp[512]; - - if (nch == 1) - calc_freq(dest[0], src[0]); - else - { - d = tmp; - sl = src[0]; - sr = src[1]; - for (i = 0; i < 512; i++) - { - *(d++) = (*(sl++) + *(sr++)) >> 1; - } - calc_freq(dest[0], tmp); - } -} - static inline void stereo16_from_multichannel(register short *l, register short *r, register short *s, @@ -63,71 +41,16 @@ static inline void stereo16_from_multichannel(register short *l, } } - -static inline void stereo16_from_stereopcm16(register short *l, - register short *r, - register short *s, - long cnt) -{ - while (cnt >= 4l) - { - l[0] = s[0]; - r[0] = s[1]; - l[1] = s[2]; - r[1] = s[3]; - l[2] = s[4]; - r[2] = s[5]; - l[3] = s[6]; - r[3] = s[7]; - l += 4; - r += 4; - s += 8; - cnt -= 4l; - } - - if (cnt > 0l) - { - l[0] = s[0]; - r[0] = s[1]; - if (cnt > 1l) - { - l[1] = s[2]; - r[1] = s[3]; - if (cnt > 2l) - { - l[2] = s[4]; - r[2] = s[5]; - } - } - } -} - -static inline void mono16_from_monopcm16(register short *l, - register short *s, - long cnt) +static inline void mono16_from_multichannel(register short *l, + register short *s, + long cnt, int chan) { - while (cnt >= 4l) - { - l[0] = s[0]; - l[1] = s[1]; - l[2] = s[2]; - l[3] = s[3]; - l += 4; - s += 4; - cnt -= 4l; - } - - if (cnt > 0l) + while (cnt > 0) { l[0] = s[0]; - if (cnt > 1l) - { - l[1] = s[1]; - if (cnt > 2l) - { - l[2] = s[2]; - } - } + s += chan; + l++; + cnt--; } } diff --git a/src/ui/logscale.cpp b/src/ui/logscale.cpp deleted file mode 100644 index 921004fd9..000000000 --- a/src/ui/logscale.cpp +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (c) 2000-2001 Brad Hughes <bhughes@trolltech.com> -// -// Use, modification and distribution is allowed without limitation, -// warranty, or liability of any kind. -// - -#include "logscale.h" - -#include <math.h> -#include <stdio.h> - - -LogScale::LogScale(int maxscale, int maxrange) - : indices(0), s(0), r(0) -{ - setMax(maxscale, maxrange); -} - - -LogScale::~LogScale() -{ - if (indices) - delete [] indices; -} - - -void LogScale::setMax(int maxscale, int maxrange) -{ - if (maxscale == 0 || maxrange == 0) - return; - - s = maxscale; - r = maxrange; - - if (indices) - delete [] indices; - - double alpha; - int i, scaled; - double domain = double(maxscale), - range = double(maxrange), - x = 1.0, - dx = 1.0, - y = 0.0, - yy = 0.0, - t = 0.0, - e4 = double(1.0E-8); - - indices = new int[maxrange]; - for (i = 0; i < maxrange; i++) - indices[i] = 0; - - // initialize log scale - while (fabs(dx) > e4) { - t = log((domain + x) / x); - y = (x * t) - range; - yy = t - (domain / (x + domain)); - dx = y / yy; - x -= dx; - } - - alpha = x; - for (i = 1; i < (int) domain; i++) { - scaled = (int) floor(0.5 + (alpha * log((double(i) + alpha) / alpha))); - if (indices[scaled - 1] < i) - indices[scaled - 1] = i; - } -} - - -int LogScale::operator[](int index) -{ - return indices[index]; -} diff --git a/src/ui/logscale.h b/src/ui/logscale.h deleted file mode 100644 index d74d25207..000000000 --- a/src/ui/logscale.h +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2000-2001 Brad Hughes <bhughes@trolltech.com> -// -// Use, modification and distribution is allowed without limitation, -// warranty, or liability of any kind. -// - -#ifndef __logscale_h -#define __logscale_h - - -class LogScale -{ -public: - LogScale(int = 0, int = 0); - ~LogScale(); - - int scale() const { return s; } - int range() const { return r; } - - void setMax(int, int); - - int operator[](int); - - -private: - int *indices; - int s, r; -}; - - -#endif // __logscale_h diff --git a/src/ui/mainvisual.cpp b/src/ui/mainvisual.cpp index fdf7076e7..222878e36 100644 --- a/src/ui/mainvisual.cpp +++ b/src/ui/mainvisual.cpp @@ -31,6 +31,9 @@ #include "inlines.h" #include "mainvisual.h" +#define VISUAL_NODE_SIZE 512 //samples +#define VISUAL_BUFFER_SIZE (5*VISUAL_NODE_SIZE) + MainVisual *MainVisual::m_instance = 0; @@ -49,9 +52,10 @@ MainVisual::MainVisual (QWidget *parent) connect(m_skin, SIGNAL(skinChanged()), this, SLOT(updateSettings())); m_timer = new QTimer (this); connect(m_timer, SIGNAL (timeout()), this, SLOT (timeout())); - m_nodes.clear(); createMenu(); readSettings(); + m_left_buffer = new short[VISUAL_BUFFER_SIZE]; + m_buffer_at = 0; m_instance = this; } @@ -67,8 +71,7 @@ MainVisual::~MainVisual() else settings.setValue("Visualization/type", "None"); settings.setValue("Visualization/rate", 1000/m_timer->interval()); - while (!m_nodes.isEmpty()) - delete m_nodes.takeFirst(); + delete [] m_left_buffer; m_instance = 0; } @@ -89,8 +92,7 @@ void MainVisual::setVisual (VisualBase *newvis) void MainVisual::clear() { - while (!m_nodes.isEmpty()) - delete m_nodes.takeFirst(); + m_buffer_at = 0; if (m_vis) m_vis->clear(); m_pixmap = m_bg; @@ -102,52 +104,47 @@ void MainVisual::add (unsigned char *data, qint64 size, int chan) if (!m_timer->isActive () || !m_vis) return; - short *l = 0, *r = 0; - qint64 samples = size/chan >> 1; - int frames = samples/512; - for (int i = 0; i < frames; ++i) + if(VISUAL_BUFFER_SIZE == m_buffer_at) { - l = new short[512]; - r = 0; - if (chan == 2) - { - r = new short[512]; - stereo16_from_stereopcm16 (l, r, (short *) (data + i*4*512), 512); - } - else if (chan == 1) - mono16_from_monopcm16 (l, (short *) (data + i*2*512), 512); - else - { - r = new short[512]; - stereo16_from_multichannel(l, r, (short *) (data + i*2*chan*512), 512, chan); - } - m_nodes.append (new VisualNode (l, r, 512)); + m_buffer_at -= VISUAL_NODE_SIZE; + memmove(m_left_buffer, m_left_buffer + VISUAL_NODE_SIZE, m_buffer_at << 1); + return; + } + + int frames = qMin((int)size/chan >> 1, VISUAL_BUFFER_SIZE - m_buffer_at); + + if (chan >= 2) + { + mono16_from_multichannel(m_left_buffer + m_buffer_at, (short *) data, frames, chan); + } + else + { + memcpy(m_left_buffer + m_buffer_at, (short *) data, frames << 1); } + + m_buffer_at += frames; } void MainVisual::timeout() { - VisualNode *node = 0; mutex()->lock (); - while(m_nodes.size() > 5) + if(m_buffer_at < VISUAL_NODE_SIZE) { - delete m_nodes.takeFirst(); + mutex()->unlock (); + return; } - if(!m_nodes.isEmpty()) - node = m_nodes.takeFirst(); - - mutex()->unlock(); - - if (m_vis && node) + if (m_vis) { - m_vis->process (node); + m_vis->process (m_left_buffer); + m_buffer_at -= VISUAL_NODE_SIZE; + memmove(m_left_buffer, m_left_buffer + VISUAL_NODE_SIZE, m_buffer_at << 1); m_pixmap = m_bg; QPainter p(&m_pixmap); m_vis->draw (&p); - delete node; } + mutex()->unlock (); update(); } @@ -447,14 +444,14 @@ void Analyzer::clear() } } -bool Analyzer::process (VisualNode *node) +bool Analyzer::process (short *l) { static fft_state *state = 0; if (!state) state = fft_init(); short dest[256]; - const int xscale_long[] = + static const int xscale_long[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, @@ -463,19 +460,14 @@ bool Analyzer::process (VisualNode *node) 114, 122, 131, 140, 150, 161, 172, 184, 255 }; - const int xscale_short[] = + static const int xscale_short[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 15, 20, 27, 36, 47, 62, 82, 107, 141, 184, 255 }; - if (node) - { - //i = node->length; - calc_freq (dest, node->left); - } - else - return false; + calc_freq (dest, l); + const double y_scale = 3.60673760222; /* 20.0 / log(256) */ int max = m_lines ? 75 : 19, y, j; @@ -587,18 +579,15 @@ void Scope::clear() Scope::~Scope() {} -bool Scope::process(VisualNode *node) +bool Scope::process(short *l) { - if (!node) - return false; - - int step = (node->length << 8)/76; + int step = (VISUAL_NODE_SIZE << 8)/76; int pos = 0; for (int i = 0; i < 76; ++i) { pos += step; - m_intern_vis_data[i] = (node->left[pos >> 8] >> 12); + m_intern_vis_data[i] = (l[pos >> 8] >> 12); if (m_intern_vis_data[i] > 4) m_intern_vis_data[i] = 4; diff --git a/src/ui/mainvisual.h b/src/ui/mainvisual.h index dbd3cd9c0..9807483d7 100644 --- a/src/ui/mainvisual.h +++ b/src/ui/mainvisual.h @@ -23,40 +23,17 @@ #include <QWidget> #include <QResizeEvent> #include <qmmp/visual.h> -#include "logscale.h" -class QSettings; class QTimer; class QMenu; class QActionGroup; -class Buffer; - -class VisualNode -{ -public: - VisualNode(short *l, short *r, unsigned long n) - : left(l), right(r), length(n) - { - // left and right are allocated and then passed to this class - // the code that allocated left and right should give up all ownership - } - - ~VisualNode() - { - delete [] left; - delete [] right; - } - - short *left, *right; - long length; -}; class VisualBase { public: virtual ~VisualBase(){} virtual void clear() = 0; - virtual bool process(VisualNode *node) = 0; + virtual bool process(short *l) = 0; virtual void draw(QPainter *) = 0; virtual const QString name() = 0; }; @@ -96,7 +73,6 @@ private: VisualBase *m_vis; QPixmap m_pixmap; QPixmap m_bg; - QList <VisualNode*> m_nodes; QTimer *m_timer; bool m_playing; Skin *m_skin; @@ -112,6 +88,9 @@ private: QAction *m_peaksAction; QAction *m_transparentAction; int m_ratio; + short *m_left_buffer; + short *m_right_buffer; + int m_buffer_at; }; namespace mainvisual @@ -123,7 +102,7 @@ public: virtual ~Analyzer(); void clear(); - bool process(VisualNode *node); + bool process(short *l); void draw(QPainter *p); const QString name() { @@ -149,7 +128,7 @@ public: Scope(); virtual ~Scope(); void clear(); - bool process(VisualNode *node); + bool process(short *l); void draw(QPainter *p); const QString name() { diff --git a/src/ui/mp3player.cpp b/src/ui/mp3player.cpp index 1d20377e7..b42b52632 100644 --- a/src/ui/mp3player.cpp +++ b/src/ui/mp3player.cpp @@ -38,13 +38,14 @@ int main(int argc, char *argv[]) { QApplication a (argc, argv ); a.setApplicationName("qmmp"); + + LXDESupport::load(); //load lxde icons + QTranslator translator; QString locale = Qmmp::systemLanguageID(); translator.load(QString(":/qmmp_") + locale); a.installTranslator(&translator); - LXDESupport::load(); //lxde icons - QTranslator qt_translator; qt_translator.load(QLibraryInfo::location (QLibraryInfo::TranslationsPath) + "/qt_" + locale); a.installTranslator(&qt_translator); diff --git a/src/ui/shadedvisual.cpp b/src/ui/shadedvisual.cpp index fdc487c7c..e249752ca 100644 --- a/src/ui/shadedvisual.cpp +++ b/src/ui/shadedvisual.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2007-2009 by Ilya Kotov * + * Copyright (C) 2007-2010 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -25,6 +25,9 @@ #include "inlines.h" #include "shadedvisual.h" +#define VISUAL_NODE_SIZE 512 //samples +#define VISUAL_BUFFER_SIZE (5*VISUAL_NODE_SIZE) + ShadedVisual::ShadedVisual(QWidget *parent) : Visual(parent) { m_skin = Skin::instance(); @@ -34,49 +37,52 @@ ShadedVisual::ShadedVisual(QWidget *parent) : Visual(parent) m_timer = new QTimer(this); connect(m_timer, SIGNAL (timeout()), this, SLOT (timeout())); connect(m_skin, SIGNAL(skinChanged()), this, SLOT(updateSkin())); + m_left_buffer = new short[VISUAL_BUFFER_SIZE]; + m_right_buffer = new short[VISUAL_BUFFER_SIZE]; + m_buffer_at = 0; m_timer->setInterval(50); m_timer->start(); clear(); } ShadedVisual::~ShadedVisual() -{} +{ + delete [] m_left_buffer; + delete [] m_right_buffer; +} void ShadedVisual::add(unsigned char *data, qint64 size, int chan) { if (!m_timer->isActive ()) return; - long len = size, cnt; - short *l = 0, *r = 0; - - len /= chan; - len /= 2; - if ( len > 512 ) - len = 512; - cnt = len; - if (chan == 2) + if(VISUAL_BUFFER_SIZE == m_buffer_at) { - l = new short[len]; - r = new short[len]; - stereo16_from_stereopcm16 ( l, r, (short *) data, cnt); + m_buffer_at -= VISUAL_NODE_SIZE; + memmove(m_left_buffer, m_left_buffer + VISUAL_NODE_SIZE, m_buffer_at << 1); + memmove(m_right_buffer, m_right_buffer + VISUAL_NODE_SIZE, m_buffer_at << 1); + return; } - else if (chan == 1) + + int frames = qMin((int)size/chan >> 1, VISUAL_BUFFER_SIZE - m_buffer_at); + + if (chan >= 2) { - l = new short[len]; - mono16_from_monopcm16 (l, (short *) data, cnt); + stereo16_from_multichannel(m_left_buffer + m_buffer_at, + m_right_buffer + m_buffer_at,(short *) data, frames, chan); } else - len = 0; + { + memcpy(m_left_buffer + m_buffer_at, (short *) data, frames << 1); + memcpy(m_right_buffer + m_buffer_at, (short *) data, frames << 1); + } - if (len) - m_nodes.append (new VisualNode (l, r, len)); + m_buffer_at += frames; } void ShadedVisual::clear() { - while (!m_nodes.isEmpty()) - m_nodes.removeFirst(); + m_buffer_at = 0; m_l = 0; m_r = 0; m_pixmap.fill(m_skin->getVisColor(0)); @@ -85,39 +91,28 @@ void ShadedVisual::clear() void ShadedVisual::timeout() { - VisualNode *node = 0; m_pixmap.fill(m_skin->getVisColor(0)); mutex()->lock (); - VisualNode *prev = 0; - while ((!m_nodes.isEmpty())) + if(m_buffer_at < VISUAL_NODE_SIZE) { - node = m_nodes.takeFirst(); - /*if ( node->offset > synctime ) - break;*/ - - if (prev) - delete prev; - prev = node; + mutex()->unlock (); + return; } - mutex()->unlock(); - node = prev; - if (!node) - return; - process (node); - delete node; + process (m_left_buffer, m_right_buffer); + m_buffer_at -= VISUAL_NODE_SIZE; + memmove(m_left_buffer, m_left_buffer + VISUAL_NODE_SIZE, m_buffer_at << 1); + memmove(m_right_buffer, m_right_buffer + VISUAL_NODE_SIZE, m_buffer_at << 1); QPainter p(&m_pixmap); draw (&p); + mutex()->unlock (); update(); } -void ShadedVisual::process (VisualNode *node) +void ShadedVisual::process (short *left, short *right) { - if (!node) - return; - - int step = (node->length << 8)/74; + int step = (VISUAL_NODE_SIZE << 8)/74; int pos = 0; int l = 0; int r = 0; @@ -127,17 +122,17 @@ void ShadedVisual::process (VisualNode *node) { pos += step; - if (node->left) + if (left) { - j_l = abs((node->left[pos >> 8] >> 12)); + j_l = abs((left[pos >> 8] >> 12)); if (j_l > 15) j_l = 15; l = qMax(l, j_l); } - if (node->right) + if (right) { - j_r = abs((node->right[pos >> 8] >> 12)); + j_r = abs((right[pos >> 8] >> 12)); if (j_r > 15) j_r = 15; r = qMax(r, j_r); diff --git a/src/ui/shadedvisual.h b/src/ui/shadedvisual.h index e276b8b24..0592ec78f 100644 --- a/src/ui/shadedvisual.h +++ b/src/ui/shadedvisual.h @@ -27,7 +27,7 @@ class QTimer; class QPixmap; class Skin; -class VisualNode; +//class VisualNode; /** @author Ilya Kotov <forkotov02@hotmail.ru> @@ -54,12 +54,14 @@ private slots: void updateSkin(); private: - void process (VisualNode *node); + void process (short *l, short *r); void draw (QPainter *); Skin *m_skin; QTimer *m_timer; QPixmap m_pixmap; - QList <VisualNode*> m_nodes; + short *m_left_buffer; + short *m_right_buffer; + int m_buffer_at; double m_l, m_r; int m_ratio; diff --git a/src/ui/ui.pro b/src/ui/ui.pro index c4c0ee861..3cabae11e 100644 --- a/src/ui/ui.pro +++ b/src/ui/ui.pro @@ -28,7 +28,6 @@ HEADERS += mainwindow.h \ mainvisual.h \ inlines.h \ fft.h \ - logscale.h \ textscroller.h \ monostereo.h \ playstatus.h \ @@ -81,7 +80,6 @@ SOURCES += mainwindow.cpp \ eqgraph.cpp \ mainvisual.cpp \ fft.c \ - logscale.cpp \ textscroller.cpp \ monostereo.cpp \ playstatus.cpp \ |
