2014-11-29 20:07:01 +01:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2003, Max Howell <max.howell@methylblue.com>
|
|
|
|
Copyright 2009, 2011-2012, David Sansome <me@davidsansome.com>
|
|
|
|
Copyright 2010, 2012, 2014, John Maguire <john.maguire@gmail.com>
|
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
|
|
|
Copyright 2014-2015, Mark Furneaux <mark@furneaux.ca>
|
2014-11-29 20:07:01 +01:00
|
|
|
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: Max Howell <max.howell@methylblue.com> 2003
|
|
|
|
*/
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
#include "analyzerbase.h"
|
2012-11-13 14:41:15 +01:00
|
|
|
|
2014-11-29 20:07:01 +01:00
|
|
|
#include <cmath>
|
2014-11-29 21:05:59 +01:00
|
|
|
#include <cstdint>
|
2012-11-13 14:41:15 +01:00
|
|
|
|
2014-11-29 20:07:01 +01:00
|
|
|
#include <QEvent>
|
2009-12-24 20:16:07 +01:00
|
|
|
#include <QPainter>
|
|
|
|
#include <QPaintEvent>
|
|
|
|
#include <QtDebug>
|
|
|
|
|
2012-11-13 14:41:15 +01:00
|
|
|
#include "engines/enginebase.h"
|
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
|
|
|
#include "core/arraysize.h"
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
// INSTRUCTIONS Base2D
|
2014-02-07 16:34:20 +01:00
|
|
|
// 1. do anything that depends on height() in init(), Base2D will call it before
|
|
|
|
// you are shown
|
2009-12-24 20:16:07 +01:00
|
|
|
// 2. otherwise you can use the constructor to initialise things
|
2014-02-07 16:34:20 +01:00
|
|
|
// 3. reimplement analyze(), and paint to canvas(), Base2D will update the
|
|
|
|
// widget when you return control to it
|
2009-12-24 20:16:07 +01:00
|
|
|
// 4. if you want to manipulate the scope, reimplement transform()
|
|
|
|
// 5. for convenience <vector> <qpixmap.h> <qwdiget.h> are pre-included
|
2014-11-29 20:07:01 +01:00
|
|
|
// TODO(David Sansome): make an INSTRUCTIONS file
|
2014-02-07 16:34:20 +01:00
|
|
|
// can't mod scope in analyze you have to use transform
|
2009-12-24 20:16:07 +01: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
|
|
|
// TODO(John Maguire): for 2D use setErasePixmap Qt function insetead of
|
|
|
|
// m_background
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
// make the linker happy only for gcc < 4.0
|
2014-02-07 16:34:20 +01:00
|
|
|
#if !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 0)) && \
|
|
|
|
!defined(Q_OS_WIN32)
|
2009-12-24 20:16:07 +01:00
|
|
|
template class Analyzer::Base<QWidget>;
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
static const int sBarkBands[] = {
|
|
|
|
100, 200, 300, 400, 510, 630, 770, 920, 1080, 1270, 1480, 1720,
|
|
|
|
2000, 2320, 2700, 3150, 3700, 4400, 5300, 6400, 7700, 9500, 12000, 15500};
|
|
|
|
|
|
|
|
static const int sBarkBandCount = arraysize(sBarkBands);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
Analyzer::Base::Base(QWidget* parent, uint scopeSize)
|
|
|
|
: QWidget(parent),
|
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
|
|
|
timeout_(40) // msec
|
2014-02-07 16:34:20 +01: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
|
|
|
fht_(new FHT(scopeSize)),
|
|
|
|
engine_(nullptr),
|
|
|
|
lastScope_(512),
|
2014-02-07 16:34:20 +01:00
|
|
|
new_frame_(false),
|
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
|
|
|
is_playing_(false),
|
|
|
|
barkband_table_(QList<uint>()),
|
|
|
|
prev_color_index_(0),
|
|
|
|
bands_(0),
|
|
|
|
psychedelic_enabled_(false) {}
|
2014-02-07 16:34:20 +01: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
|
|
|
void Analyzer::Base::hideEvent(QHideEvent*) { timer_.stop(); }
|
2014-02-07 16:34:20 +01: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
|
|
|
void Analyzer::Base::showEvent(QShowEvent*) { timer_.start(timeout(), this); }
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-11-29 20:07:01 +01:00
|
|
|
void Analyzer::Base::transform(Scope& scope) {
|
2014-02-07 16:34:20 +01:00
|
|
|
// this is a standard transformation that should give
|
|
|
|
// an FFT scope that has bands for pretty analyzers
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
// NOTE resizing here is redundant as FHT routines only calculate FHT::size()
|
|
|
|
// values
|
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
|
|
|
// scope.resize( fht_->size() );
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
float* front = static_cast<float*>(&scope.front());
|
|
|
|
|
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
|
|
|
float* f = new float[fht_->size()];
|
|
|
|
fht_->copy(&f[0], front);
|
|
|
|
fht_->logSpectrum(front, &f[0]);
|
|
|
|
fht_->scale(front, 1.0 / 20);
|
2014-02-07 16:34:20 +01: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
|
|
|
scope.resize(fht_->size() / 2); // second half of values are rubbish
|
2014-02-07 16:34:20 +01:00
|
|
|
delete[] f;
|
2010-08-28 20:48:16 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void Analyzer::Base::paintEvent(QPaintEvent* e) {
|
|
|
|
QPainter p(this);
|
|
|
|
p.fillRect(e->rect(), palette().color(QPalette::Window));
|
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
|
|
|
switch (engine_->state()) {
|
2014-02-07 16:34:20 +01:00
|
|
|
case Engine::Playing: {
|
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
|
|
|
const Engine::Scope& thescope = engine_->scope(timeout_);
|
2014-02-07 16:34:20 +01:00
|
|
|
int i = 0;
|
2010-08-28 20:48:16 +02:00
|
|
|
|
2014-04-30 03:38:21 +02:00
|
|
|
// convert to mono here - our built in analyzers need mono, but the
|
2014-02-07 16:34:20 +01:00
|
|
|
// engines provide interleaved pcm
|
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 (uint x = 0; static_cast<int>(x) < fht_->size(); ++x) {
|
|
|
|
lastScope_[x] = static_cast<double>(thescope[i] + thescope[i + 1]) /
|
|
|
|
(2 * (1 << 15));
|
2014-02-07 16:34:20 +01:00
|
|
|
i += 2;
|
|
|
|
}
|
2010-08-28 20:48:16 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
is_playing_ = true;
|
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(lastScope_);
|
|
|
|
analyze(p, lastScope_, new_frame_);
|
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
|
|
|
// scope.resize( fht_->size() );
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
break;
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
case Engine::Paused:
|
2014-02-07 16:34:20 +01:00
|
|
|
is_playing_ = false;
|
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
|
|
|
analyze(p, lastScope_, new_frame_);
|
2014-02-07 16:34:20 +01:00
|
|
|
break;
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
default:
|
2014-02-07 16:34:20 +01:00
|
|
|
is_playing_ = false;
|
|
|
|
demo(p);
|
|
|
|
}
|
2012-10-16 12:20:56 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
new_frame_ = false;
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
int Analyzer::Base::resizeExponent(int exp) {
|
|
|
|
if (exp < 3)
|
|
|
|
exp = 3;
|
|
|
|
else if (exp > 9)
|
|
|
|
exp = 9;
|
|
|
|
|
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 (exp != fht_->sizeExp()) {
|
|
|
|
delete fht_;
|
|
|
|
fht_ = new FHT(exp);
|
2014-02-07 16:34:20 +01:00
|
|
|
}
|
|
|
|
return exp;
|
2010-08-28 20:48:16 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
int Analyzer::Base::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);
|
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
|
|
|
return fht_->size() / 2;
|
2010-08-28 20:48:16 +02:00
|
|
|
}
|
|
|
|
|
2014-11-29 20:07:01 +01:00
|
|
|
void Analyzer::Base::demo(QPainter& p) {
|
2014-02-07 16:34:20 +01:00
|
|
|
static int t = 201; // FIXME make static to namespace perhaps
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
if (t > 999) t = 1; // 0 = wasted calculations
|
|
|
|
if (t < 201) {
|
|
|
|
Scope s(32);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-11-29 20:07:01 +01:00
|
|
|
const double dt = static_cast<double>(t) / 200;
|
2014-02-07 16:34:20 +01:00
|
|
|
for (uint i = 0; i < s.size(); ++i)
|
|
|
|
s[i] = dt * (sin(M_PI + (i * M_PI) / s.size()) + 1.0);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
analyze(p, s, new_frame_);
|
2014-11-29 20:07:01 +01:00
|
|
|
} else {
|
2014-02-07 16:34:20 +01:00
|
|
|
analyze(p, Scope(32, 0), new_frame_);
|
2014-11-29 20:07:01 +01:00
|
|
|
}
|
2014-02-07 16:34:20 +01:00
|
|
|
++t;
|
2009-12-24 20:16:07 +01: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
|
|
|
void Analyzer::Base::psychedelicModeChanged(bool enabled) {
|
|
|
|
psychedelic_enabled_ = enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Analyzer::Base::BandFrequency(int band) const {
|
|
|
|
return ((kSampleRate / 2) * band + kSampleRate / 4) / bands_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Analyzer::Base::updateBandSize(const int scopeSize) {
|
|
|
|
// prevent possible dbz in BandFrequency
|
|
|
|
if (scopeSize == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bands_ = scopeSize;
|
|
|
|
|
|
|
|
barkband_table_.clear();
|
|
|
|
barkband_table_.reserve(bands_ + 1);
|
|
|
|
|
|
|
|
int barkband = 0;
|
|
|
|
for (int i = 0; i < bands_ + 1; ++i) {
|
|
|
|
if (barkband < sBarkBandCount - 1 &&
|
|
|
|
BandFrequency(i) >= sBarkBands[barkband]) {
|
|
|
|
barkband++;
|
|
|
|
}
|
|
|
|
|
|
|
|
barkband_table_.append(barkband);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QColor Analyzer::Base::getPsychedelicColor(const Scope& scope,
|
|
|
|
const int ampFactor,
|
|
|
|
const int bias) {
|
|
|
|
if (scope.size() > barkband_table_.length()) {
|
|
|
|
return palette().color(QPalette::Highlight);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate total magnitudes for different bark bands.
|
|
|
|
double bands[sBarkBandCount]{};
|
|
|
|
|
|
|
|
for (int i = 0; i < barkband_table_.size(); ++i) {
|
|
|
|
bands[barkband_table_[i]] += scope[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now divide the bark bands into thirds and compute their total amplitudes.
|
|
|
|
double rgb[3]{};
|
|
|
|
for (int i = 0; i < sBarkBandCount - 1; ++i) {
|
|
|
|
rgb[(i * 3) / sBarkBandCount] += bands[i] * bands[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
// bias colours for a threshold around normally amplified audio
|
|
|
|
rgb[i] = (int)((sqrt(rgb[i]) * ampFactor) + bias);
|
|
|
|
if (rgb[i] > 255) {
|
|
|
|
rgb[i] = 255;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QColor::fromRgb(rgb[0], rgb[1], rgb[2]);
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void Analyzer::Base::polishEvent() {
|
|
|
|
init(); // virtual
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
2014-11-29 20:07:01 +01:00
|
|
|
void Analyzer::interpolate(const Scope& inVec, Scope& outVec) {
|
2014-02-07 16:34:20 +01:00
|
|
|
double pos = 0.0;
|
2014-11-29 20:07:01 +01:00
|
|
|
const double step = static_cast<double>(inVec.size()) / outVec.size();
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
for (uint i = 0; i < outVec.size(); ++i, pos += step) {
|
|
|
|
const double error = pos - std::floor(pos);
|
2014-11-29 21:05:59 +01:00
|
|
|
const uint64_t offset = static_cast<uint64_t>(pos);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-11-29 21:05:59 +01:00
|
|
|
uint64_t indexLeft = offset + 0;
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
if (indexLeft >= inVec.size()) indexLeft = inVec.size() - 1;
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-11-29 21:05:59 +01:00
|
|
|
uint64_t indexRight = offset + 1;
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
if (indexRight >= inVec.size()) indexRight = inVec.size() - 1;
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
outVec[i] = inVec[indexLeft] * (1.0 - error) + inVec[indexRight] * error;
|
|
|
|
}
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
2014-11-29 20:07:01 +01:00
|
|
|
void Analyzer::initSin(Scope& v, const uint size) {
|
2014-02-07 16:34:20 +01:00
|
|
|
double step = (M_PI * 2) / size;
|
|
|
|
double radian = 0;
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
for (uint i = 0; i < size; i++) {
|
|
|
|
v.push_back(sin(radian));
|
|
|
|
radian += step;
|
|
|
|
}
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
2010-08-28 20:48:16 +02:00
|
|
|
|
|
|
|
void Analyzer::Base::timerEvent(QTimerEvent* e) {
|
|
|
|
QWidget::timerEvent(e);
|
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 (e->timerId() != timer_.timerId()) return;
|
2010-08-28 20:48:16 +02:00
|
|
|
|
2011-06-23 22:36:14 +02:00
|
|
|
new_frame_ = true;
|
2010-08-28 20:48:16 +02:00
|
|
|
update();
|
|
|
|
}
|