EqSpectrumView.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 <QWidget>
  27. #include "fft_helpers.h"
  28. #include "lmms_basics.h"
  29. #include "lmms_math.h"
  30. const int MAX_BANDS = 2048;
  31. class EqAnalyser
  32. {
  33. public:
  34. EqAnalyser();
  35. virtual ~EqAnalyser();
  36. float m_bands[MAX_BANDS];
  37. bool getInProgress();
  38. void clear();
  39. void analyze( sampleFrame *buf, const fpp_t frames );
  40. float getEnergy() const;
  41. int getSampleRate() const;
  42. bool getActive() const;
  43. void setActive(bool active);
  44. private:
  45. fftwf_plan m_fftPlan;
  46. fftwf_complex * m_specBuf;
  47. float m_absSpecBuf[FFT_BUFFER_SIZE+1];
  48. float m_buffer[FFT_BUFFER_SIZE*2];
  49. int m_framesFilledUp;
  50. float m_energy;
  51. int m_sampleRate;
  52. bool m_active;
  53. bool m_inProgress;
  54. float m_fftWindow[FFT_BUFFER_SIZE];
  55. };
  56. class EqSpectrumView : public QWidget
  57. {
  58. Q_OBJECT
  59. public:
  60. explicit EqSpectrumView( EqAnalyser *b, QWidget *_parent = 0 );
  61. virtual ~EqSpectrumView()
  62. {
  63. }
  64. QColor getColor() const;
  65. void setColor( const QColor &value );
  66. protected:
  67. virtual void paintEvent( QPaintEvent *event );
  68. private slots:
  69. void periodicalUpdate();
  70. private:
  71. QColor m_color;
  72. EqAnalyser *m_analyser;
  73. QPainterPath m_path;
  74. float m_peakSum;
  75. float m_pixelsPerUnitWidth;
  76. float m_scale;
  77. int m_skipBands;
  78. bool m_periodicalUpdate;
  79. QList<float> m_bandHeight;
  80. float bandToFreq ( int index );
  81. };
  82. #endif // EQSPECTRUMVIEW_H