EqSpectrumView.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* eqspectrumview.h - defination of EqSpectrumView class.
  2. *
  3. * Copyright (c) 2014 David French <dave/dot/french3/at/googlemail/dot/com>
  4. *
  5. * This file is part of LMMS - https://lmms.io
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2 of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public
  18. * License along with this program (see COPYING); if not, write to the
  19. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  20. * Boston, MA 02110-1301 USA.
  21. *
  22. */
  23. #ifndef EQSPECTRUMVIEW_H
  24. #define EQSPECTRUMVIEW_H
  25. #include <QPainter>
  26. #include <QPainterPath>
  27. #include <QWidget>
  28. #include "fft_helpers.h"
  29. #include "lmms_basics.h"
  30. #include "lmms_math.h"
  31. const int MAX_BANDS = 2048;
  32. class EqAnalyser
  33. {
  34. public:
  35. EqAnalyser();
  36. virtual ~EqAnalyser();
  37. float m_bands[MAX_BANDS];
  38. bool getInProgress();
  39. void clear();
  40. void analyze( sampleFrame *buf, const fpp_t frames );
  41. float getEnergy() const;
  42. int getSampleRate() const;
  43. bool getActive() const;
  44. void setActive(bool active);
  45. private:
  46. fftwf_plan m_fftPlan;
  47. fftwf_complex * m_specBuf;
  48. float m_absSpecBuf[FFT_BUFFER_SIZE+1];
  49. float m_buffer[FFT_BUFFER_SIZE*2];
  50. int m_framesFilledUp;
  51. float m_energy;
  52. int m_sampleRate;
  53. bool m_active;
  54. bool m_inProgress;
  55. float m_fftWindow[FFT_BUFFER_SIZE];
  56. };
  57. class EqSpectrumView : public QWidget
  58. {
  59. Q_OBJECT
  60. public:
  61. explicit EqSpectrumView( EqAnalyser *b, QWidget *_parent = 0 );
  62. virtual ~EqSpectrumView()
  63. {
  64. }
  65. QColor getColor() const;
  66. void setColor( const QColor &value );
  67. protected:
  68. virtual void paintEvent( QPaintEvent *event );
  69. private slots:
  70. void periodicalUpdate();
  71. private:
  72. QColor m_color;
  73. EqAnalyser *m_analyser;
  74. QPainterPath m_path;
  75. float m_peakSum;
  76. float m_pixelsPerUnitWidth;
  77. float m_scale;
  78. int m_skipBands;
  79. bool m_periodicalUpdate;
  80. QList<float> m_bandHeight;
  81. float bandToFreq ( int index );
  82. };
  83. #endif // EQSPECTRUMVIEW_H