[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [amarok] src/context/applets/analyzer: Clean up analyzer code, increase precision.
From:       Mark Kretschmann <kretschmann () kde ! org>
Date:       2013-05-31 9:46:06
Message-ID: 20130531094606.68447A6067 () git ! kde ! org
[Download RAW message or body]

Git commit 0c87f221354f357a400cd393c058668d807a04ab by Mark Kretschmann.
Committed on 31/05/2013 at 11:45.
Pushed by markey into branch 'master'.

Clean up analyzer code, increase precision.

M  +10   -60   src/context/applets/analyzer/AnalyzerBase.cpp
M  +3    -5    src/context/applets/analyzer/AnalyzerBase.h
M  +1    -1    src/context/applets/analyzer/BlockAnalyzer.cpp

http://commits.kde.org/amarok/0c87f221354f357a400cd393c058668d807a04ab

diff --git a/src/context/applets/analyzer/AnalyzerBase.cpp \
b/src/context/applets/analyzer/AnalyzerBase.cpp index 7ee4992..a0ae157 100644
--- a/src/context/applets/analyzer/AnalyzerBase.cpp
+++ b/src/context/applets/analyzer/AnalyzerBase.cpp
@@ -26,21 +26,15 @@
 
 
 // INSTRUCTIONS Base2D
-// 1. do anything that depends on height() in init(), Base2D will call it before you \
                are shown
-// 2. otherwise you can use the constructor to initialise things
-// 3. reimplement analyze(), and paint to canvas(), Base2D will update the widget \
                when you return control to it
-// 4. if you want to manipulate the scope, reimplement transform()
-// 5. for convenience <vector> <qpixmap.h> <qwdiget.h> are pre-included
-// TODO make an INSTRUCTIONS file
-//can't mod scope in analyze you have to use transform
+// 1. reimplement analyze(), and paint to canvas(), Base2D will update the widget \
when you return control to it +// 2. if you want to manipulate the scope, reimplement \
transform()  
 
 template<class W>
-Analyzer::Base<W>::Base( QWidget *parent, uint scopeSize )
+Analyzer::Base<W>::Base( QWidget *parent )
     : W( parent )
-    , m_fht( new FHT( scopeSize ) )
-{
-}
+    , m_fht( new FHT( 9 ) ) // 2^9 = 512. It's the number of values AudioDataOutput \
sends +{}
 
 template<class W> void
 Analyzer::Base<W>::transform( QVector<float> &scope ) //virtual
@@ -48,9 +42,6 @@ Analyzer::Base<W>::transform( QVector<float> &scope ) //virtual
     //this is a standard transformation that should give
     //an FFT scope that has bands for pretty analyzers
 
-    //NOTE resizing here is redundant as FHT routines only calculate FHT::size() \
                values
-    //scope.resize( m_fht->size() );
-
     float *front = static_cast<float*>( &scope.front() );
 
     float* f = new float[ m_fht->size() ];
@@ -68,8 +59,7 @@ Analyzer::Base<W>::drawFrame( const \
QMap<Phonon::AudioDataOutput::Channel, QVect  if( thescope.isEmpty() )
         return;
 
-    static QVector<float> scope( 512 );
-    int i = 0;
+    QVector<float> scope( m_fht->size() );
 
     for( uint x = 0; ( int )x < m_fht->size(); ++x )
     {
@@ -83,50 +73,10 @@ Analyzer::Base<W>::drawFrame( const \
                QMap<Phonon::AudioDataOutput::Channel, QVect
                                + thescope[Phonon::AudioDataOutput::RightChannel][x] \
                )
                        / ( 2 * ( 1 << 15 ) ); // Average between the channels
         }
-        i += 2;
     }
 
     transform( scope );
     analyze( scope );
-
-    scope.resize( m_fht->size() );
-}
-
-template<class W> int
-Analyzer::Base<W>::resizeExponent( int exp )
-{
-    if( exp < 3 )
-        exp = 3;
-    else if( exp > 9 )
-        exp = 9;
-
-    if( exp != m_fht->sizeExp() )
-    {
-        delete m_fht;
-        m_fht = new FHT( exp );
-    }
-    return exp;
-}
-
-template<class W> int
-Analyzer::Base<W>::resizeForBands( int bands )
-{
-    int exp;
-    if( bands <= 8 )
-        exp = 4;
-    else if( bands <= 16 )
-        exp = 5;
-    else if( bands <= 32 )
-        exp = 6;
-    else if( bands <= 64 )
-        exp = 7;
-    else if( bands <= 128 )
-        exp = 8;
-    else
-        exp = 9;
-
-    resizeExponent( exp );
-    return m_fht->size() / 2;
 }
 
 template<class W> void
@@ -157,8 +107,8 @@ Analyzer::Base<W>::demo() //virtual
 
 
 
-Analyzer::Base2D::Base2D( QWidget *parent, uint scopeSize )
-    : Base<QWidget>( parent, scopeSize )
+Analyzer::Base2D::Base2D( QWidget *parent )
+    : Base<QWidget>( parent )
 {
     connect( EngineController::instance(), SIGNAL( playbackStateChanged() ), this, \
SLOT( playbackStateChanged() ) );  
@@ -200,8 +150,8 @@ void Analyzer::Base2D::playbackStateChanged()
 
 
 
-Analyzer::Base3D::Base3D( QWidget *parent, uint scopeSize )
-    : Base<QGLWidget>( parent, scopeSize )
+Analyzer::Base3D::Base3D( QWidget *parent )
+    : Base<QGLWidget>( parent )
 {
     connect( EngineController::instance(), SIGNAL( playbackStateChanged() ), this, \
SLOT( playbackStateChanged() ) );  
diff --git a/src/context/applets/analyzer/AnalyzerBase.h \
b/src/context/applets/analyzer/AnalyzerBase.h index 568cd2f..7bb2cec 100644
--- a/src/context/applets/analyzer/AnalyzerBase.h
+++ b/src/context/applets/analyzer/AnalyzerBase.h
@@ -50,7 +50,7 @@ public:
     virtual void drawFrame( const QMap<Phonon::AudioDataOutput::Channel, \
QVector<qint16> > &thescope );  
 protected:
-    Base( QWidget*, uint = 7 );
+    Base( QWidget* );
     ~Base()
     {
         delete m_fht;
@@ -58,8 +58,6 @@ protected:
 
     void demo();
 
-    int  resizeExponent( int );
-    int  resizeForBands( int );
     virtual void transform( QVector<float>& );
     virtual void analyze( const QVector<float>& ) = 0;
     virtual void paused();
@@ -93,7 +91,7 @@ private slots:
     }
 
 protected:
-    Base2D( QWidget*, uint scopeSize = 7 );
+    Base2D( QWidget* );
 
     QPixmap *canvas()
     {
@@ -126,7 +124,7 @@ private slots:
     }
 
 protected:
-    Base3D( QWidget*, uint scopeSize = 7 );
+    Base3D( QWidget* );
 
 private:
     QTimer m_timer;
diff --git a/src/context/applets/analyzer/BlockAnalyzer.cpp \
b/src/context/applets/analyzer/BlockAnalyzer.cpp index 3316c28..53efd8e 100644
--- a/src/context/applets/analyzer/BlockAnalyzer.cpp
+++ b/src/context/applets/analyzer/BlockAnalyzer.cpp
@@ -31,7 +31,7 @@ static inline uint myMax( uint v1, uint v2 )
 }
 
 BlockAnalyzer::BlockAnalyzer( QWidget *parent )
-    : Analyzer::Base2D( parent, 9 )
+    : Analyzer::Base2D( parent )
     , m_columns( 0 )         //uint
     , m_rows( 0 )            //uint
     , m_y( 0 )               //uint


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic