aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/plugins/Visual/CMakeLists.txt2
-rw-r--r--src/plugins/Visual/Visual.pro2
-rw-r--r--src/plugins/Visual/analyzer/analyzer.cpp34
-rw-r--r--src/plugins/Visual/analyzer/analyzer.h10
-rw-r--r--src/plugins/Visual/analyzer/fft.c15
-rw-r--r--src/plugins/Visual/analyzer/fft.h9
-rw-r--r--src/plugins/Visual/analyzer/inlines.h31
7 files changed, 61 insertions, 42 deletions
diff --git a/src/plugins/Visual/CMakeLists.txt b/src/plugins/Visual/CMakeLists.txt
index 369a1605a..656000b8d 100644
--- a/src/plugins/Visual/CMakeLists.txt
+++ b/src/plugins/Visual/CMakeLists.txt
@@ -2,7 +2,7 @@ SET(USE_ANALYZER TRUE CACHE BOOL "enable/disable analyzer plugin")
SET(USE_PROJECTM TRUE CACHE BOOL "enable/disable projectm plugin")
IF(USE_ANALYZER)
-#add_subdirectory(analyzer)
+add_subdirectory(analyzer)
ENDIF(USE_ANALYZER)
IF(USE_PROJECTM)
diff --git a/src/plugins/Visual/Visual.pro b/src/plugins/Visual/Visual.pro
index 6ee5a7d59..fad9d2b8d 100644
--- a/src/plugins/Visual/Visual.pro
+++ b/src/plugins/Visual/Visual.pro
@@ -1,7 +1,7 @@
include(../../../qmmp.pri)
TEMPLATE = subdirs
-#SUBDIRS += analyzer
+SUBDIRS += analyzer
contains(CONFIG, PROJECTM_PLUGIN){
# SUBDIRS += projectm
}
diff --git a/src/plugins/Visual/analyzer/analyzer.cpp b/src/plugins/Visual/analyzer/analyzer.cpp
index d7cb683d0..62d6a5593 100644
--- a/src/plugins/Visual/analyzer/analyzer.cpp
+++ b/src/plugins/Visual/analyzer/analyzer.cpp
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2007-2013 by Ilya Kotov *
+ * Copyright (C) 2007-2015 by Ilya Kotov *
* forkotov02@hotmail.ru *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -48,8 +48,8 @@ Analyzer::Analyzer (QWidget *parent) : Visual (parent)
setMinimumSize(2*300-30,105);
m_timer = new QTimer (this);
connect(m_timer, SIGNAL (timeout()), this, SLOT (timeout()));
- m_left_buffer = new short[VISUAL_BUFFER_SIZE];
- m_right_buffer = new short[VISUAL_BUFFER_SIZE];
+ m_left_buffer = new float[VISUAL_BUFFER_SIZE];
+ m_right_buffer = new float[VISUAL_BUFFER_SIZE];
clear();
createMenu();
@@ -69,7 +69,7 @@ Analyzer::~Analyzer()
delete [] m_x_scale;
}
-void Analyzer::add (unsigned char *data, qint64 size, int chan)
+void Analyzer::add (float *data, size_t samples, int chan)
{
if (!m_timer->isActive ())
return;
@@ -77,23 +77,15 @@ void Analyzer::add (unsigned char *data, qint64 size, int chan)
if(VISUAL_BUFFER_SIZE == m_buffer_at)
{
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);
+ memmove(m_left_buffer, m_left_buffer + VISUAL_NODE_SIZE, m_buffer_at * sizeof(float));
+ memmove(m_right_buffer, m_right_buffer + VISUAL_NODE_SIZE, m_buffer_at * sizeof(float));
return;
}
- int frames = qMin((int)size/chan >> 1, VISUAL_BUFFER_SIZE - m_buffer_at);
+ int frames = qMin(int(samples/chan), VISUAL_BUFFER_SIZE - m_buffer_at);
- if (chan >= 2)
- {
- stereo16_from_multichannel(m_left_buffer + m_buffer_at,
- m_right_buffer + m_buffer_at,(short *) data, frames, chan);
- }
- else
- {
- memcpy(m_left_buffer + m_buffer_at, (short *) data, frames << 1);
- memcpy(m_right_buffer + m_buffer_at, (short *) data, frames << 1);
- }
+ stereo_from_multichannel(m_left_buffer + m_buffer_at,
+ m_right_buffer + m_buffer_at, data, frames, chan);
m_buffer_at += frames;
}
@@ -109,7 +101,7 @@ void Analyzer::clear()
void Analyzer::timeout()
{
- mutex()->lock ();
+ mutex()->lock();
if(m_buffer_at < VISUAL_NODE_SIZE)
{
mutex()->unlock ();
@@ -118,8 +110,8 @@ void Analyzer::timeout()
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);
+ memmove(m_left_buffer, m_left_buffer + VISUAL_NODE_SIZE, m_buffer_at * sizeof(float));
+ memmove(m_right_buffer, m_right_buffer + VISUAL_NODE_SIZE, m_buffer_at * sizeof(float));
mutex()->unlock ();
update();
}
@@ -232,7 +224,7 @@ void Analyzer::mousePressEvent(QMouseEvent *e)
m_menu->exec(e->globalPos());
}
-void Analyzer::process (short *left, short *right)
+void Analyzer::process (float *left, float *right)
{
static fft_state *state = 0;
if (!state)
diff --git a/src/plugins/Visual/analyzer/analyzer.h b/src/plugins/Visual/analyzer/analyzer.h
index 7de645ef5..d2c2d6cd1 100644
--- a/src/plugins/Visual/analyzer/analyzer.h
+++ b/src/plugins/Visual/analyzer/analyzer.h
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2007-2013 by Ilya Kotov *
+ * Copyright (C) 2007-2015 by Ilya Kotov *
* forkotov02@hotmail.ru *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -41,7 +41,7 @@ public:
Analyzer( QWidget *parent = 0);
virtual ~Analyzer();
- void add(unsigned char *data, qint64 size, int chan);
+ void add(float *data, size_t samples, int chan);
void clear();
@@ -58,7 +58,7 @@ private:
virtual void closeEvent (QCloseEvent *);
void paintEvent(QPaintEvent *);
void mousePressEvent(QMouseEvent *e);
- void process(short *l, short *r);
+ void process(float *l, float *r);
void draw(QPainter *p);
void createMenu();
QTimer *m_timer;
@@ -68,8 +68,8 @@ private:
double m_peaks_falloff;
double m_analyzer_falloff;
bool m_show_peaks;
- short *m_left_buffer;
- short *m_right_buffer;
+ float *m_left_buffer;
+ float *m_right_buffer;
int m_buffer_at;
int m_cols, m_rows;
bool m_update;
diff --git a/src/plugins/Visual/analyzer/fft.c b/src/plugins/Visual/analyzer/fft.c
index 0ea89eae6..2865e878e 100644
--- a/src/plugins/Visual/analyzer/fft.c
+++ b/src/plugins/Visual/analyzer/fft.c
@@ -25,6 +25,11 @@
* More optimisations.
*/
+/*
+ modifications compared to original code:
+ using float format for input data
+*/
+
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
@@ -56,7 +61,7 @@ struct _struct_fft_state {
/* # Local function prototypes # */
/* ############################# */
-static void fft_prepare(const sound_sample * input, float *re, float *im);
+static void fft_prepare(const float *input, float *re, float *im);
static void fft_calculate(float *re, float *im);
static void fft_output(const float *re, const float *im, float *output);
static int reverseBits(unsigned int initial);
@@ -126,7 +131,7 @@ fft_init(void)
* state is a (non-NULL) pointer returned by fft_init.
*/
void
-fft_perform(const sound_sample * input, float *output, fft_state * state)
+fft_perform(const float *input, float *output, fft_state * state)
{
/* Convert data from sound format to be ready for FFT */
fft_prepare(input, state->real, state->imag);
@@ -156,7 +161,7 @@ fft_close(fft_state * state)
* Prepare data to perform an FFT on
*/
static void
-fft_prepare(const sound_sample * input, float *re, float *im)
+fft_prepare(const float *input, float *re, float *im)
{
unsigned int i;
float *realptr = re;
@@ -164,7 +169,7 @@ fft_prepare(const sound_sample * input, float *re, float *im)
/* Get input, in reverse bit order */
for (i = 0; i < FFT_BUFFER_SIZE; i++) {
- *realptr++ = input[bitReverse[i]];
+ *realptr++ = input[bitReverse[i]] * 32767.0;
*imagptr++ = 0;
}
}
@@ -174,7 +179,7 @@ fft_prepare(const sound_sample * input, float *re, float *im)
* Note: only produces half as many data points as the input had.
* This is roughly a consequence of the Nyquist sampling theorm thingy.
* (FIXME - make this comment better, and helpful.)
- *
+ *
* The two divisions by 4 are also a consequence of this: the contributions
* returned for each frequency are split into two parts, one at i in the
* table, and the other at FFT_BUFFER_SIZE - i, except for i = 0 and
diff --git a/src/plugins/Visual/analyzer/fft.h b/src/plugins/Visual/analyzer/fft.h
index 915bccaf6..c24e2e584 100644
--- a/src/plugins/Visual/analyzer/fft.h
+++ b/src/plugins/Visual/analyzer/fft.h
@@ -23,8 +23,11 @@
#define FFT_BUFFER_SIZE (1 << FFT_BUFFER_SIZE_LOG)
-/* sound sample - should be an signed 16 bit value */
-typedef short int sound_sample;
+/*
+ modifications compared to original code:
+ using float format for input data
+*/
+
#ifdef __cplusplus
extern "C" {
@@ -33,7 +36,7 @@ extern "C" {
/* FFT library */
typedef struct _struct_fft_state fft_state;
fft_state *fft_init(void);
- void fft_perform(const sound_sample * input, float *output,
+ void fft_perform(const float *input, float *output,
fft_state * state);
void fft_close(fft_state * state);
diff --git a/src/plugins/Visual/analyzer/inlines.h b/src/plugins/Visual/analyzer/inlines.h
index 39b81bd57..8203de336 100644
--- a/src/plugins/Visual/analyzer/inlines.h
+++ b/src/plugins/Visual/analyzer/inlines.h
@@ -4,13 +4,20 @@
// warranty, or liability of any kind.
//
+/*
+ modifications compared to original code:
+ using float format
+*/
+
#ifndef INLINES_H
#define INLINES_H
#include "fft.h"
+#include <math.h>
+#include <string.h>
// *fast* convenience functions
-static inline void calc_freq(short* dest, short *src)
+static inline void calc_freq(short* dest, float *src)
{
static fft_state *state = NULL;
float tmp_out[257];
@@ -25,11 +32,17 @@ static inline void calc_freq(short* dest, short *src)
dest[i] = ((int) sqrt(tmp_out[i + 1])) >> 8;
}
-static inline void stereo16_from_multichannel(register short *l,
- register short *r,
- register short *s,
+static inline void stereo_from_multichannel(float *l,
+ float *r,
+ float *s,
long cnt, int chan)
{
+ if(chan == 1)
+ {
+ memcpy(l, s, cnt * sizeof(float));
+ memcpy(r, s, cnt * sizeof(float));
+ return;
+ }
while (cnt > 0)
{
l[0] = s[0];
@@ -41,10 +54,16 @@ static inline void stereo16_from_multichannel(register short *l,
}
}
-static inline void mono16_from_multichannel(register short *l,
- register short *s,
+static inline void mono_from_multichannel(float *l,
+ float *s,
long cnt, int chan)
{
+ if(chan == 1)
+ {
+ memcpy(l, s, cnt * sizeof(float));
+ return;
+ }
+
while (cnt > 0)
{
l[0] = s[0];