changeset 109:61a2ac1241b3

* Make a single base Thread class for RT and non-RT threads * Pull ResizeableBitmap out from the MatrixFile's ColumnBitmap * Reorder SpectrogramLayer::paint somewhat so as to improve cache hit ratio in the FFT file cache
author Chris Cannam
date Mon, 08 May 2006 16:44:47 +0000
parents 0c19e50bad7c
children c1188c5a991d
files base/NonRTThread.cpp base/NonRTThread.h base/ResizeableBitmap.h base/Thread.cpp base/Thread.h base/View.cpp plugin/DSSIPluginInstance.h transform/Transform.h
diffstat 8 files changed, 166 insertions(+), 79 deletions(-) [+]
line wrap: on
line diff
--- a/base/NonRTThread.cpp	Mon May 08 13:51:16 2006 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,42 +0,0 @@
-/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
-
-/*
-    Sonic Visualiser
-    An audio file viewer and annotation editor.
-    Centre for Digital Music, Queen Mary, University of London.
-    This file copyright 2006 Chris Cannam.
-    
-    This program is free software; you can redistribute it and/or
-    modify it under the terms of the GNU General Public License as
-    published by the Free Software Foundation; either version 2 of the
-    License, or (at your option) any later version.  See the file
-    COPYING included with this distribution for more information.
-*/
-
-#include "NonRTThread.h"
-
-#ifndef _WIN32
-#include <pthread.h>
-#endif
-
-NonRTThread::NonRTThread(QObject *parent) :
-    QThread(parent)
-{
-    setStackSize(512 * 1024);
-}
-
-void
-NonRTThread::start()
-{
-    QThread::start();
-
-#ifndef _WIN32
-    struct sched_param param;
-    ::memset(&param, 0, sizeof(param));
-
-    if (::pthread_setschedparam(pthread_self(), SCHED_OTHER, &param)) {
-        ::perror("pthread_setschedparam to SCHED_OTHER failed");
-    }
-#endif
-}
-
--- a/base/NonRTThread.h	Mon May 08 13:51:16 2006 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,32 +0,0 @@
-/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
-
-/*
-    Sonic Visualiser
-    An audio file viewer and annotation editor.
-    Centre for Digital Music, Queen Mary, University of London.
-    This file copyright 2006 Chris Cannam.
-    
-    This program is free software; you can redistribute it and/or
-    modify it under the terms of the GNU General Public License as
-    published by the Free Software Foundation; either version 2 of the
-    License, or (at your option) any later version.  See the file
-    COPYING included with this distribution for more information.
-*/
-
-#ifndef _NON_RT_THREAD_H_
-#define _NON_RT_THREAD_H_
-
-#include <QThread>
-
-class NonRTThread : public QThread
-{
-Q_OBJECT
-
-public:
-    NonRTThread(QObject *parent = 0);
-
-public slots:
-    void start();
-};
-
-#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/base/ResizeableBitmap.h	Mon May 08 16:44:47 2006 +0000
@@ -0,0 +1,69 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    Sonic Visualiser
+    An audio file viewer and annotation editor.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2006 Chris Cannam.
+    
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.  See the file
+    COPYING included with this distribution for more information.
+*/
+
+#ifndef _RESIZEABLE_BITMAP_H_
+#define _RESIZEABLE_BITMAP_H_
+
+#include <vector>
+#include <stdint.h>
+
+class ResizeableBitmap {
+
+public:
+    ResizeableBitmap() : m_bits(0) {
+    }
+    ResizeableBitmap(size_t size) : m_bits(new std::vector<uint8_t>) {
+        m_bits->assign(size / 8 + 1, 0);
+    }
+    ResizeableBitmap(const ResizeableBitmap &b) {
+        m_bits = new std::vector<uint8_t>(*b.m_bits);
+    }
+    ResizeableBitmap &operator=(const ResizeableBitmap &b) {
+        if (&b != this) return *this;
+        delete m_bits;
+        m_bits = new std::vector<uint8_t>(*b.m_bits);
+        return *this;
+    }
+    ~ResizeableBitmap() {
+        delete m_bits;
+    }
+    
+    void resize(size_t bits) { // losing all data
+        if (!m_bits || bits < m_bits->size()) {
+            delete m_bits;
+            m_bits = new std::vector<uint8_t>;
+        }
+        m_bits->assign(bits / 8, 0);
+    }
+    
+    bool get(size_t column) const {
+        return ((*m_bits)[column / 8]) & (1u << (column % 8));
+    }
+    
+    void set(size_t column, bool state) {
+        if (state) {
+            ((*m_bits)[column / 8]) |=  (uint8_t(1) << (column % 8));
+        } else {
+            ((*m_bits)[column / 8]) &= ~(uint8_t(1) << (column % 8));
+        }
+    }
+    
+private:
+    std::vector<uint8_t> *m_bits;
+};
+
+
+#endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/base/Thread.cpp	Mon May 08 16:44:47 2006 +0000
@@ -0,0 +1,55 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    Sonic Visualiser
+    An audio file viewer and annotation editor.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2006 Chris Cannam.
+    
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.  See the file
+    COPYING included with this distribution for more information.
+*/
+
+#include "Thread.h"
+
+#ifndef _WIN32
+#include <pthread.h>
+#endif
+
+Thread::Thread(Type type, QObject *parent) :
+    QThread(parent),
+    m_type(type)
+{
+    setStackSize(512 * 1024);
+}
+
+void
+Thread::start()
+{
+    QThread::start();
+
+#ifndef _WIN32
+    struct sched_param param;
+    ::memset(&param, 0, sizeof(param));
+
+    if (m_type == RTThread) {
+
+        param.sched_priority = 5;
+
+        if (::pthread_setschedparam(pthread_self(), SCHED_FIFO, &param)) {
+            ::perror("INFO: pthread_setschedparam to SCHED_FIFO failed");
+        }
+
+    } else {
+
+        if (::pthread_setschedparam(pthread_self(), SCHED_OTHER, &param)) {
+            ::perror("WARNING: pthread_setschedparam to SCHED_OTHER failed");
+        }
+    }        
+
+#endif
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/base/Thread.h	Mon May 08 16:44:47 2006 +0000
@@ -0,0 +1,37 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    Sonic Visualiser
+    An audio file viewer and annotation editor.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2006 Chris Cannam.
+    
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.  See the file
+    COPYING included with this distribution for more information.
+*/
+
+#ifndef _THREAD_H_
+#define _THREAD_H_
+
+#include <QThread>
+
+class Thread : public QThread
+{
+Q_OBJECT
+
+public:
+    enum Type { RTThread, NonRTThread };
+
+    Thread(Type type = NonRTThread, QObject *parent = 0);
+
+public slots:
+    void start();
+
+private:    
+    Type m_type;
+};
+
+#endif
--- a/base/View.cpp	Mon May 08 13:51:16 2006 +0000
+++ b/base/View.cpp	Mon May 08 16:44:47 2006 +0000
@@ -31,7 +31,7 @@
 #include <cassert>
 #include <math.h>
 
-#define DEBUG_VIEW_WIDGET_PAINT 1
+//#define DEBUG_VIEW_WIDGET_PAINT 1
 
 using std::cerr;
 using std::endl;
--- a/plugin/DSSIPluginInstance.h	Mon May 08 13:51:16 2006 +0000
+++ b/plugin/DSSIPluginInstance.h	Mon May 08 16:44:47 2006 +0000
@@ -32,7 +32,7 @@
 #include "api/dssi.h"
 
 #include "base/RingBuffer.h"
-#include "base/NonRTThread.h"
+#include "base/Thread.h"
 #include "RealTimePluginInstance.h"
 #include "base/Scavenger.h"
 
@@ -198,7 +198,7 @@
 
     static Scavenger<ScavengerArrayWrapper<snd_seq_event_t *> > m_bufferScavenger;
 
-    class NonRTPluginThread : public NonRTThread
+    class NonRTPluginThread : public Thread
     {
     public:
 	NonRTPluginThread(LADSPA_Handle handle,
--- a/transform/Transform.h	Mon May 08 13:51:16 2006 +0000
+++ b/transform/Transform.h	Mon May 08 16:44:47 2006 +0000
@@ -16,7 +16,7 @@
 #ifndef _TRANSFORM_H_
 #define _TRANSFORM_H_
 
-#include "NonRTThread.h"
+#include "Thread.h"
 
 #include "base/Model.h"
 
@@ -35,7 +35,7 @@
  * the background thread has populated it.
  */
 
-class Transform : public NonRTThread
+class Transform : public Thread
 {
 public:
     virtual ~Transform();