2009-12-24 20:16:07 +01:00
|
|
|
//
|
|
|
|
//
|
|
|
|
// C++ Implementation: Sonogram
|
|
|
|
//
|
|
|
|
// Description:
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Author: Melchior FRANZ <mfranz@kde.org>, (C) 2004
|
|
|
|
//
|
|
|
|
// Copyright: See COPYING file that comes with this distribution
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "sonogram.h"
|
|
|
|
|
2010-03-22 14:49:08 +01:00
|
|
|
#include <QPainter>
|
|
|
|
|
2010-03-21 18:22:05 +01:00
|
|
|
const char* Sonogram::kName = QT_TRANSLATE_NOOP("AnalyzerContainer", "Sonogram");
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
Sonogram::Sonogram(QWidget *parent) :
|
2010-08-28 20:48:16 +02:00
|
|
|
Analyzer::Base(parent, 9)
|
2009-12-24 20:16:07 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Sonogram::~Sonogram()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Sonogram::resizeEvent(QResizeEvent *e)
|
|
|
|
{
|
|
|
|
QWidget::resizeEvent(e);
|
|
|
|
|
2010-08-28 20:48:16 +02:00
|
|
|
//only for gcc < 4.0
|
|
|
|
#if !( __GNUC__ > 4 || ( __GNUC__ == 4 && __GNUC_MINOR__ >= 0 ) )
|
|
|
|
resizeForBands(height() < 128 ? 128 : height());
|
|
|
|
#endif
|
|
|
|
|
2010-03-21 18:22:05 +01:00
|
|
|
canvas_ = QPixmap(size());
|
|
|
|
canvas_.fill(palette().color(QPalette::Background));
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-21 18:22:05 +01:00
|
|
|
void Sonogram::analyze(QPainter& p, const Scope &s)
|
2009-12-24 20:16:07 +01:00
|
|
|
{
|
|
|
|
int x = width() - 1;
|
|
|
|
QColor c;
|
|
|
|
|
2010-03-21 18:22:05 +01:00
|
|
|
QPainter canvas_painter(&canvas_);
|
|
|
|
canvas_painter.drawPixmap(0, 0, canvas_, 1, 0, x, -1);
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
Scope::const_iterator it = s.begin(), end = s.end();
|
|
|
|
for (int y = height() - 1; y;) {
|
|
|
|
if (it >= end || *it < .005)
|
2010-03-21 18:22:05 +01:00
|
|
|
c = palette().color(QPalette::Background);
|
2009-12-24 20:16:07 +01:00
|
|
|
else if (*it < .05)
|
|
|
|
c.setHsv(95, 255, 255 - int(*it * 4000.0));
|
|
|
|
else if (*it < 1.0)
|
|
|
|
c.setHsv(95 - int(*it * 90.0), 255, 255);
|
|
|
|
else
|
|
|
|
c = Qt::red;
|
|
|
|
|
2010-03-21 18:22:05 +01:00
|
|
|
canvas_painter.setPen(c);
|
|
|
|
canvas_painter.drawPoint(x, y--);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
if (it < end)
|
|
|
|
++it;
|
|
|
|
}
|
2010-03-21 18:22:05 +01:00
|
|
|
|
|
|
|
canvas_painter.end();
|
|
|
|
|
|
|
|
p.drawPixmap(0, 0, canvas_);
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
2010-08-28 20:48:16 +02:00
|
|
|
|
|
|
|
void Sonogram::transform(Scope &scope)
|
|
|
|
{
|
|
|
|
float *front = static_cast<float*>(&scope.front());
|
|
|
|
m_fht->power2(front);
|
|
|
|
m_fht->scale(front, 1.0 / 256);
|
|
|
|
scope.resize( m_fht->size() / 2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-21 18:22:05 +01:00
|
|
|
void Sonogram::demo(QPainter& p)
|
2009-12-24 20:16:07 +01:00
|
|
|
{
|
2010-08-28 20:48:16 +02:00
|
|
|
analyze(p, Scope(m_fht->size(), 0));
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|