2014-11-29 20:07:01 +01:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2004, Melchior FRANZ <mfranz@kde.org>
|
|
|
|
Copyright 2010, 2014, John Maguire <john.maguire@gmail.com>
|
|
|
|
Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com>
|
|
|
|
|
|
|
|
Clementine 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 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Original Author: Melchior FRANZ <mfranz@kde.org> 2004
|
2020-09-18 16:15:19 +02:00
|
|
|
*/
|
2010-08-28 20:48:16 +02:00
|
|
|
|
|
|
|
#include "fht.h"
|
|
|
|
|
2020-09-18 16:15:19 +02:00
|
|
|
#include <cmath>
|
|
|
|
|
2017-03-11 18:13:55 +01:00
|
|
|
FHT::FHT(int n) : num_((n < 3) ? 0 : 1 << n), exp2_((n < 3) ? -1 : n) {
|
2014-02-07 16:34:20 +01:00
|
|
|
if (n > 3) {
|
2017-03-11 18:13:55 +01:00
|
|
|
buf_vector_.resize(num_);
|
|
|
|
tab_vector_.resize(num_ * 2);
|
2014-02-07 16:34:20 +01:00
|
|
|
makeCasTable();
|
|
|
|
}
|
2010-08-28 20:48:16 +02:00
|
|
|
}
|
|
|
|
|
2017-03-11 18:13:55 +01:00
|
|
|
FHT::~FHT() {}
|
|
|
|
|
|
|
|
int FHT::sizeExp() const { return exp2_; }
|
|
|
|
int FHT::size() const { return num_; }
|
|
|
|
|
|
|
|
float* FHT::buf_() { return buf_vector_.data(); }
|
|
|
|
float* FHT::tab_() { return tab_vector_.data(); }
|
|
|
|
int* FHT::log_() { return log_vector_.data(); }
|
2010-08-28 20:48:16 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void FHT::makeCasTable(void) {
|
2017-03-11 18:13:55 +01:00
|
|
|
float* costab = tab_();
|
|
|
|
float* sintab = tab_() + num_ / 2 + 1;
|
2010-08-28 20:48:16 +02:00
|
|
|
|
2017-03-11 18:13:55 +01:00
|
|
|
for (int ul = 0; ul < num_; ul++) {
|
|
|
|
float d = M_PI * ul / (num_ / 2);
|
2014-02-07 16:34:20 +01:00
|
|
|
*costab = *sintab = cos(d);
|
2010-08-28 20:48:16 +02:00
|
|
|
|
2017-03-11 18:13:55 +01:00
|
|
|
costab += 2;
|
|
|
|
sintab += 2;
|
|
|
|
if (sintab > tab_() + num_ * 2) sintab = tab_() + 1;
|
2014-02-07 16:34:20 +01:00
|
|
|
}
|
2010-08-28 20:48:16 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void FHT::scale(float* p, float d) {
|
Add "Psychedelic Colour" mode to all analyzers
(Well, except Nyanalyzer and Rainbow dash because they are already colourful enough.)
I have added functionality for any 2D analyzer to change any part of its colour palatte with the frequency content of the music, in the same way that Moodbars do.
I find this gives the analyzer a sort of "third dimention".
This is built into Analyzer::Base, so all analyzers can use it and override it as they please. I have thus added support for Block, Boom, Turbine, Sonogram, and Bar, however Boom and Block seem to look the best in my opinion.
This is of course all optional and is toggled by a checkbox in the context menu for the analyzer, disabled by default.
I have not been able to measure any increase in CPU activity with this enabled, even at 60fps.
2015-07-01 17:48:03 +02:00
|
|
|
for (int i = 0; i < (num_ / 2); i++) *p++ *= d;
|
2010-08-28 20:48:16 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void FHT::ewma(float* d, float* s, float w) {
|
Add "Psychedelic Colour" mode to all analyzers
(Well, except Nyanalyzer and Rainbow dash because they are already colourful enough.)
I have added functionality for any 2D analyzer to change any part of its colour palatte with the frequency content of the music, in the same way that Moodbars do.
I find this gives the analyzer a sort of "third dimention".
This is built into Analyzer::Base, so all analyzers can use it and override it as they please. I have thus added support for Block, Boom, Turbine, Sonogram, and Bar, however Boom and Block seem to look the best in my opinion.
This is of course all optional and is toggled by a checkbox in the context menu for the analyzer, disabled by default.
I have not been able to measure any increase in CPU activity with this enabled, even at 60fps.
2015-07-01 17:48:03 +02:00
|
|
|
for (int i = 0; i < (num_ / 2); i++, d++, s++) *d = *d * w + *s * (1 - w);
|
2010-08-28 20:48:16 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void FHT::logSpectrum(float* out, float* p) {
|
Add "Psychedelic Colour" mode to all analyzers
(Well, except Nyanalyzer and Rainbow dash because they are already colourful enough.)
I have added functionality for any 2D analyzer to change any part of its colour palatte with the frequency content of the music, in the same way that Moodbars do.
I find this gives the analyzer a sort of "third dimention".
This is built into Analyzer::Base, so all analyzers can use it and override it as they please. I have thus added support for Block, Boom, Turbine, Sonogram, and Bar, however Boom and Block seem to look the best in my opinion.
This is of course all optional and is toggled by a checkbox in the context menu for the analyzer, disabled by default.
I have not been able to measure any increase in CPU activity with this enabled, even at 60fps.
2015-07-01 17:48:03 +02:00
|
|
|
int n = num_ / 2, i, j, k, *r;
|
2017-03-11 18:13:55 +01:00
|
|
|
if (log_vector_.size() < n) {
|
|
|
|
log_vector_.resize(n);
|
2014-11-01 19:26:05 +01:00
|
|
|
float f = n / log10(static_cast<double>(n));
|
2017-03-11 18:13:55 +01:00
|
|
|
for (i = 0, r = log_(); i < n; i++, r++) {
|
2014-11-01 19:26:05 +01:00
|
|
|
j = static_cast<int>(rint(log10(i + 1.0) * f));
|
2014-02-07 16:34:20 +01:00
|
|
|
*r = j >= n ? n - 1 : j;
|
2010-08-28 20:48:16 +02:00
|
|
|
}
|
2014-02-07 16:34:20 +01:00
|
|
|
}
|
|
|
|
semiLogSpectrum(p);
|
|
|
|
*out++ = *p = *p / 100;
|
2017-03-11 18:13:55 +01:00
|
|
|
for (k = i = 1, r = log_(); i < n; i++) {
|
2014-02-07 16:34:20 +01:00
|
|
|
j = *r++;
|
2014-11-01 19:26:05 +01:00
|
|
|
if (i == j) {
|
2014-02-07 16:34:20 +01:00
|
|
|
*out++ = p[i];
|
2014-11-01 19:26:05 +01:00
|
|
|
} else {
|
2014-02-07 16:34:20 +01:00
|
|
|
float base = p[k - 1];
|
|
|
|
float step = (p[j] - base) / (j - (k - 1));
|
|
|
|
for (float corr = 0; k <= j; k++, corr += step) *out++ = base + corr;
|
2010-08-28 20:48:16 +02:00
|
|
|
}
|
2014-02-07 16:34:20 +01:00
|
|
|
}
|
2010-08-28 20:48:16 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void FHT::semiLogSpectrum(float* p) {
|
|
|
|
power2(p);
|
Add "Psychedelic Colour" mode to all analyzers
(Well, except Nyanalyzer and Rainbow dash because they are already colourful enough.)
I have added functionality for any 2D analyzer to change any part of its colour palatte with the frequency content of the music, in the same way that Moodbars do.
I find this gives the analyzer a sort of "third dimention".
This is built into Analyzer::Base, so all analyzers can use it and override it as they please. I have thus added support for Block, Boom, Turbine, Sonogram, and Bar, however Boom and Block seem to look the best in my opinion.
This is of course all optional and is toggled by a checkbox in the context menu for the analyzer, disabled by default.
I have not been able to measure any increase in CPU activity with this enabled, even at 60fps.
2015-07-01 17:48:03 +02:00
|
|
|
for (int i = 0; i < (num_ / 2); i++, p++) {
|
2017-03-11 18:13:55 +01:00
|
|
|
float e = 10.0 * log10(sqrt(*p / 2));
|
2014-02-07 16:34:20 +01:00
|
|
|
*p = e < 0 ? 0 : e;
|
|
|
|
}
|
2010-08-28 20:48:16 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void FHT::spectrum(float* p) {
|
|
|
|
power2(p);
|
Add "Psychedelic Colour" mode to all analyzers
(Well, except Nyanalyzer and Rainbow dash because they are already colourful enough.)
I have added functionality for any 2D analyzer to change any part of its colour palatte with the frequency content of the music, in the same way that Moodbars do.
I find this gives the analyzer a sort of "third dimention".
This is built into Analyzer::Base, so all analyzers can use it and override it as they please. I have thus added support for Block, Boom, Turbine, Sonogram, and Bar, however Boom and Block seem to look the best in my opinion.
This is of course all optional and is toggled by a checkbox in the context menu for the analyzer, disabled by default.
I have not been able to measure any increase in CPU activity with this enabled, even at 60fps.
2015-07-01 17:48:03 +02:00
|
|
|
for (int i = 0; i < (num_ / 2); i++, p++)
|
2017-03-11 18:13:55 +01:00
|
|
|
*p = static_cast<float>(sqrt(*p / 2));
|
2010-08-28 20:48:16 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void FHT::power(float* p) {
|
|
|
|
power2(p);
|
2017-03-11 18:13:55 +01:00
|
|
|
for (int i = 0; i < (num_ / 2); i++) *p++ /= 2;
|
2010-08-28 20:48:16 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void FHT::power2(float* p) {
|
Add "Psychedelic Colour" mode to all analyzers
(Well, except Nyanalyzer and Rainbow dash because they are already colourful enough.)
I have added functionality for any 2D analyzer to change any part of its colour palatte with the frequency content of the music, in the same way that Moodbars do.
I find this gives the analyzer a sort of "third dimention".
This is built into Analyzer::Base, so all analyzers can use it and override it as they please. I have thus added support for Block, Boom, Turbine, Sonogram, and Bar, however Boom and Block seem to look the best in my opinion.
This is of course all optional and is toggled by a checkbox in the context menu for the analyzer, disabled by default.
I have not been able to measure any increase in CPU activity with this enabled, even at 60fps.
2015-07-01 17:48:03 +02:00
|
|
|
_transform(p, num_, 0);
|
2010-08-28 20:48:16 +02:00
|
|
|
|
2017-03-11 18:13:55 +01:00
|
|
|
*p = static_cast<float>(2 * pow(*p, 2));
|
|
|
|
p++;
|
2010-08-28 20:48:16 +02:00
|
|
|
|
2017-03-11 18:13:55 +01:00
|
|
|
float* q = p + num_ - 2;
|
|
|
|
for (int i = 1; i < (num_ / 2); i++) {
|
|
|
|
*p = static_cast<float>(pow(*p, 2) + pow(*q, 2));
|
|
|
|
p++;
|
|
|
|
q--;
|
|
|
|
}
|
2010-08-28 20:48:16 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void FHT::transform(float* p) {
|
Add "Psychedelic Colour" mode to all analyzers
(Well, except Nyanalyzer and Rainbow dash because they are already colourful enough.)
I have added functionality for any 2D analyzer to change any part of its colour palatte with the frequency content of the music, in the same way that Moodbars do.
I find this gives the analyzer a sort of "third dimention".
This is built into Analyzer::Base, so all analyzers can use it and override it as they please. I have thus added support for Block, Boom, Turbine, Sonogram, and Bar, however Boom and Block seem to look the best in my opinion.
This is of course all optional and is toggled by a checkbox in the context menu for the analyzer, disabled by default.
I have not been able to measure any increase in CPU activity with this enabled, even at 60fps.
2015-07-01 17:48:03 +02:00
|
|
|
if (num_ == 8)
|
2014-02-07 16:34:20 +01:00
|
|
|
transform8(p);
|
|
|
|
else
|
Add "Psychedelic Colour" mode to all analyzers
(Well, except Nyanalyzer and Rainbow dash because they are already colourful enough.)
I have added functionality for any 2D analyzer to change any part of its colour palatte with the frequency content of the music, in the same way that Moodbars do.
I find this gives the analyzer a sort of "third dimention".
This is built into Analyzer::Base, so all analyzers can use it and override it as they please. I have thus added support for Block, Boom, Turbine, Sonogram, and Bar, however Boom and Block seem to look the best in my opinion.
This is of course all optional and is toggled by a checkbox in the context menu for the analyzer, disabled by default.
I have not been able to measure any increase in CPU activity with this enabled, even at 60fps.
2015-07-01 17:48:03 +02:00
|
|
|
_transform(p, num_, 0);
|
2010-08-28 20:48:16 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void FHT::transform8(float* p) {
|
|
|
|
float a, b, c, d, e, f, g, h, b_f2, d_h2;
|
|
|
|
float a_c_eg, a_ce_g, ac_e_g, aceg, b_df_h, bdfh;
|
|
|
|
|
|
|
|
a = *p++, b = *p++, c = *p++, d = *p++;
|
|
|
|
e = *p++, f = *p++, g = *p++, h = *p;
|
|
|
|
b_f2 = (b - f) * M_SQRT2;
|
|
|
|
d_h2 = (d - h) * M_SQRT2;
|
|
|
|
|
|
|
|
a_c_eg = a - c - e + g;
|
|
|
|
a_ce_g = a - c + e - g;
|
|
|
|
ac_e_g = a + c - e - g;
|
|
|
|
aceg = a + c + e + g;
|
|
|
|
|
|
|
|
b_df_h = b - d + f - h;
|
|
|
|
bdfh = b + d + f + h;
|
|
|
|
|
|
|
|
*p = a_c_eg - d_h2;
|
|
|
|
*--p = a_ce_g - b_df_h;
|
|
|
|
*--p = ac_e_g - b_f2;
|
|
|
|
*--p = aceg - bdfh;
|
|
|
|
*--p = a_c_eg + d_h2;
|
|
|
|
*--p = a_ce_g + b_df_h;
|
|
|
|
*--p = ac_e_g + b_f2;
|
|
|
|
*--p = aceg + bdfh;
|
2010-08-28 20:48:16 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void FHT::_transform(float* p, int n, int k) {
|
|
|
|
if (n == 8) {
|
|
|
|
transform8(p + k);
|
|
|
|
return;
|
|
|
|
}
|
2010-08-28 20:48:16 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
int i, j, ndiv2 = n / 2;
|
|
|
|
float a, *t1, *t2, *t3, *t4, *ptab, *pp;
|
|
|
|
|
2017-03-11 18:13:55 +01:00
|
|
|
for (i = 0, t1 = buf_(), t2 = buf_() + ndiv2, pp = &p[k]; i < ndiv2; i++)
|
2014-02-07 16:34:20 +01:00
|
|
|
*t1++ = *pp++, *t2++ = *pp++;
|
2010-08-28 20:48:16 +02:00
|
|
|
|
2017-03-11 18:13:55 +01:00
|
|
|
std::copy(buf_(), buf_() + n, p + k);
|
2010-08-28 20:48:16 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
_transform(p, ndiv2, k);
|
|
|
|
_transform(p, ndiv2, k + ndiv2);
|
2010-08-28 20:48:16 +02:00
|
|
|
|
Add "Psychedelic Colour" mode to all analyzers
(Well, except Nyanalyzer and Rainbow dash because they are already colourful enough.)
I have added functionality for any 2D analyzer to change any part of its colour palatte with the frequency content of the music, in the same way that Moodbars do.
I find this gives the analyzer a sort of "third dimention".
This is built into Analyzer::Base, so all analyzers can use it and override it as they please. I have thus added support for Block, Boom, Turbine, Sonogram, and Bar, however Boom and Block seem to look the best in my opinion.
This is of course all optional and is toggled by a checkbox in the context menu for the analyzer, disabled by default.
I have not been able to measure any increase in CPU activity with this enabled, even at 60fps.
2015-07-01 17:48:03 +02:00
|
|
|
j = num_ / ndiv2 - 1;
|
2017-03-11 18:13:55 +01:00
|
|
|
t1 = buf_();
|
2014-02-07 16:34:20 +01:00
|
|
|
t2 = t1 + ndiv2;
|
|
|
|
t3 = p + k + ndiv2;
|
2017-03-11 18:13:55 +01:00
|
|
|
ptab = tab_();
|
2014-02-07 16:34:20 +01:00
|
|
|
pp = p + k;
|
2010-08-28 20:48:16 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
a = *ptab++ * *t3++;
|
|
|
|
a += *ptab * *pp;
|
|
|
|
ptab += j;
|
2010-08-28 20:48:16 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
*t1++ = *pp + a;
|
|
|
|
*t2++ = *pp++ - a;
|
2010-08-28 20:48:16 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
for (i = 1, t4 = p + k + n; i < ndiv2; i++, ptab += j) {
|
2010-08-28 20:48:16 +02:00
|
|
|
a = *ptab++ * *t3++;
|
2014-02-07 16:34:20 +01:00
|
|
|
a += *ptab * *--t4;
|
2010-08-28 20:48:16 +02:00
|
|
|
|
|
|
|
*t1++ = *pp + a;
|
|
|
|
*t2++ = *pp++ - a;
|
2014-02-07 16:34:20 +01:00
|
|
|
}
|
2017-03-11 18:13:55 +01:00
|
|
|
|
|
|
|
std::copy(buf_(), buf_() + n, p + k);
|
2010-08-28 20:48:16 +02:00
|
|
|
}
|