Skip to content

Commit

Permalink
Revert "Spectrum analyzer update (LMMS#5160)"
Browse files Browse the repository at this point in the history
This reverts commit da73ddd.
  • Loading branch information
seokwon committed Dec 12, 2019
1 parent ee54af6 commit b043803
Show file tree
Hide file tree
Showing 26 changed files with 362 additions and 1,865 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,3 @@
[submodule "doc/wiki"]
path = doc/wiki
url = https://github.com/lmms/lmms.wiki.git
[submodule "src/3rdparty/ringbuffer"]
path = src/3rdparty/ringbuffer
url = https://github.com/JohannesLorenz/ringbuffer.git
132 changes: 0 additions & 132 deletions include/LocklessRingBuffer.h

This file was deleted.

2 changes: 0 additions & 2 deletions include/RingBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
#include "lmms_math.h"
#include "MemoryManager.h"

/** \brief A basic LMMS ring buffer for single-thread use. For thread and realtime safe alternative see LocklessRingBuffer.
*/
class LMMS_EXPORT RingBuffer : public QObject
{
Q_OBJECT
Expand Down
43 changes: 0 additions & 43 deletions include/lmms_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,47 +49,4 @@ const float F_PI_SQR = (float) LD_PI_SQR;
const float F_E = (float) LD_E;
const float F_E_R = (float) LD_E_R;

// Frequency ranges (in Hz).
// Arbitrary low limit for logarithmic frequency scale; >1 Hz.
const int LOWEST_LOG_FREQ = 10;

// Full range is defined by LOWEST_LOG_FREQ and current sample rate.
enum FREQUENCY_RANGES
{
FRANGE_FULL = 0,
FRANGE_AUDIBLE,
FRANGE_BASS,
FRANGE_MIDS,
FRANGE_HIGH
};

const int FRANGE_AUDIBLE_START = 20;
const int FRANGE_AUDIBLE_END = 20000;
const int FRANGE_BASS_START = 20;
const int FRANGE_BASS_END = 300;
const int FRANGE_MIDS_START = 200;
const int FRANGE_MIDS_END = 5000;
const int FRANGE_HIGH_START = 4000;
const int FRANGE_HIGH_END = 20000;

// Amplitude ranges (in dBFS).
// Reference: full scale sine wave (-1.0 to 1.0) is 0 dB.
// Doubling or halving the amplitude produces 3 dB difference.
enum AMPLITUDE_RANGES
{
ARANGE_EXTENDED = 0,
ARANGE_AUDIBLE,
ARANGE_LOUD,
ARANGE_SILENT
};

const int ARANGE_EXTENDED_START = -80;
const int ARANGE_EXTENDED_END = 20;
const int ARANGE_AUDIBLE_START = -50;
const int ARANGE_AUDIBLE_END = 0;
const int ARANGE_LOUD_START = -30;
const int ARANGE_LOUD_END = 0;
const int ARANGE_SILENT_START = -60;
const int ARANGE_SILENT_END = -10;

#endif
51 changes: 4 additions & 47 deletions plugins/SpectrumAnalyzer/Analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@

#include "Analyzer.h"

#ifdef SA_DEBUG
#include <chrono>
#include <iostream>
#endif

#include "embed.h"
#include "lmms_basics.h"
#include "plugin_export.h"


Expand All @@ -44,7 +38,7 @@ extern "C" {
"Spectrum Analyzer",
QT_TRANSLATE_NOOP("pluginBrowser", "A graphical spectrum analyzer."),
"Martin Pavelek <he29/dot/HS/at/gmail/dot/com>",
0x0112,
0x0100,
Plugin::Effect,
new PluginPixmapLoader("logo"),
NULL,
Expand All @@ -56,54 +50,17 @@ extern "C" {
Analyzer::Analyzer(Model *parent, const Plugin::Descriptor::SubPluginFeatures::Key *key) :
Effect(&analyzer_plugin_descriptor, parent, key),
m_processor(&m_controls),
m_controls(this),
m_processorThread(m_processor, m_inputBuffer),
// Buffer is sized to cover 4* the current maximum LMMS audio buffer size,
// so that it has some reserve space in case data processor is busy.
m_inputBuffer(4 * m_maxBufferSize)
m_controls(this)
{
m_processorThread.start();
}


Analyzer::~Analyzer()
{
m_processor.terminate();
m_inputBuffer.wakeAll();
m_processorThread.wait();
}

// Take audio data and pass them to the spectrum processor.
// Skip processing if the controls dialog isn't visible, it would only waste CPU cycles.
bool Analyzer::processAudioBuffer(sampleFrame *buffer, const fpp_t frame_count)
{
// Measure time spent in audio thread; both average and peak should be well under 1 ms.
#ifdef SA_DEBUG
unsigned int audio_time = std::chrono::high_resolution_clock::now().time_since_epoch().count();
if (audio_time - m_last_dump_time > 5000000000) // print every 5 seconds
{
std::cout << "Analyzer audio thread: " << m_sum_execution / m_dump_count << " ms avg / "
<< m_max_execution << " ms peak." << std::endl;
m_last_dump_time = audio_time;
m_sum_execution = m_max_execution = m_dump_count = 0;
}
#endif

if (!isEnabled() || !isRunning ()) {return false;}

// Skip processing if the controls dialog isn't visible, it would only waste CPU cycles.
if (m_controls.isViewVisible())
{
// To avoid processing spikes on audio thread, data are stored in
// a lockless ringbuffer and processed in a separate thread.
m_inputBuffer.write(buffer, frame_count, true);
}
#ifdef SA_DEBUG
audio_time = std::chrono::high_resolution_clock::now().time_since_epoch().count() - audio_time;
m_dump_count++;
m_sum_execution += audio_time / 1000000.0;
if (audio_time / 1000000.0 > m_max_execution) {m_max_execution = audio_time / 1000000.0;}
#endif

if (m_controls.isViewVisible()) {m_processor.analyse(buffer, frame_count);}
return isRunning();
}

Expand Down
24 changes: 1 addition & 23 deletions plugins/SpectrumAnalyzer/Analyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@
#ifndef ANALYZER_H
#define ANALYZER_H

#include <QWaitCondition>

#include "DataprocLauncher.h"
#include "Effect.h"
#include "LocklessRingBuffer.h"
#include "SaControls.h"
#include "SaProcessor.h"

Expand All @@ -41,7 +37,7 @@ class Analyzer : public Effect
{
public:
Analyzer(Model *parent, const Descriptor::SubPluginFeatures::Key *key);
virtual ~Analyzer();
virtual ~Analyzer() {};

bool processAudioBuffer(sampleFrame *buffer, const fpp_t frame_count) override;
EffectControls *controls() override {return &m_controls;}
Expand All @@ -51,24 +47,6 @@ class Analyzer : public Effect
private:
SaProcessor m_processor;
SaControls m_controls;

// Maximum LMMS buffer size (hard coded, the actual constant is hard to get)
const unsigned int m_maxBufferSize = 4096;

// QThread::create() workaround
// Replace DataprocLauncher by QThread and replace initializer in constructor
// with the following commented line when LMMS CI starts using Qt > 5.9
//m_processorThread = QThread::create([=]{m_processor.analyze(m_inputBuffer);});
DataprocLauncher m_processorThread;

LocklessRingBuffer<sampleFrame> m_inputBuffer;

#ifdef SA_DEBUG
int m_last_dump_time;
int m_dump_count;
float m_sum_execution;
float m_max_execution;
#endif
};

#endif // ANALYZER_H
Expand Down
4 changes: 1 addition & 3 deletions plugins/SpectrumAnalyzer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
INCLUDE(BuildPlugin)
INCLUDE_DIRECTORIES(${FFTW3F_INCLUDE_DIRS})

LINK_LIBRARIES(${FFTW3F_LIBRARIES})

BUILD_PLUGIN(analyzer Analyzer.cpp SaProcessor.cpp SaControls.cpp SaControlsDialog.cpp SaSpectrumView.cpp SaWaterfallView.cpp
MOCFILES SaProcessor.h SaControls.h SaControlsDialog.h SaSpectrumView.h SaWaterfallView.h DataprocLauncher.h EMBEDDED_RESOURCES *.svg logo.png)
MOCFILES SaProcessor.h SaControls.h SaControlsDialog.h SaSpectrumView.h SaWaterfallView.h EMBEDDED_RESOURCES *.svg logo.png)
52 changes: 0 additions & 52 deletions plugins/SpectrumAnalyzer/DataprocLauncher.h

This file was deleted.

Loading

0 comments on commit b043803

Please sign in to comment.