Skip to content
Snippets Groups Projects
Commit c57e07e1 authored by Raphael Grimm's avatar Raphael Grimm
Browse files

Add frequency to spectogram

parent 48f8e98d
No related branches found
No related tags found
No related merge requests found
......@@ -2,18 +2,20 @@
namespace simox::qt
{
SimoxQwtSpectrogramData::SimoxQwtSpectrogramData(std::size_t iterations, std::size_t max_fft_width) :
_iterations{iterations}
SimoxQwtSpectrogramData::SimoxQwtSpectrogramData(
std::size_t iterations,
std::size_t bucket_count,
float frequency)
{
setInterval(Qt::XAxis, QwtInterval(0, iterations));
setInterval(Qt::YAxis, QwtInterval(0, max_fft_width));
setFrequency(frequency, bucket_count);
setIterations(iterations);
setInterval(Qt::ZAxis, QwtInterval(0.0, 10.0));
}
double SimoxQwtSpectrogramData::value(double fx, double fy) const
{
const std::size_t x = fx;
const std::size_t y = fy;
const std::size_t y = fy / _bucket_height;
if (x >= _vals.size())
{
return 0;
......@@ -65,5 +67,13 @@ namespace simox::qt
void SimoxQwtSpectrogramData::setIterations(std::size_t iterations)
{
_iterations = iterations;
setInterval(Qt::XAxis, QwtInterval(0, iterations));
}
void SimoxQwtSpectrogramData::setFrequency(float freq, std::size_t bucket_count)
{
_bucket_height = freq / 2 / bucket_count;
_bucket_count = bucket_count;
setInterval(Qt::YAxis, QwtInterval(0, freq / 2));
}
}
......@@ -11,7 +11,7 @@ namespace simox::qt
class SimoxQwtSpectrogramData: public QwtRasterData
{
public:
SimoxQwtSpectrogramData(std::size_t iterations, std::size_t max_fft_width);
SimoxQwtSpectrogramData(std::size_t iterations, std::size_t max_fft_width, float frequency);
virtual double value(double fx, double fy) const;
......@@ -20,8 +20,11 @@ namespace simox::qt
const std::vector<float>& update(std::vector<float> v);
std::size_t iterations() const;
void setIterations(std::size_t iterations);
void setFrequency(float freq, std::size_t bucket_count);
private:
std::deque<std::vector<float>> _vals;
std::size_t _iterations;
float _bucket_height;
std::size_t _bucket_count;
};
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment