audio_effect_helper.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #ifndef AVPLAYER2_AUDIO_EFFECT_HELPER_H
  2. #define AVPLAYER2_AUDIO_EFFECT_HELPER_H
  3. #pragma once
  4. #include <QBrush>
  5. #include <QFont>
  6. #include <QPen>
  7. #include <QWidget>
  8. #include "audio_play_thread.h"
  9. class BarHelper
  10. {
  11. public:
  12. explicit BarHelper();
  13. virtual ~BarHelper() {};
  14. public:
  15. enum GraphicType { e_GtBar, e_GtLine, e_GtPie };
  16. enum VisualType { e_VtSampleing, e_VtFrequency };
  17. typedef struct VisualFormat
  18. {
  19. GraphicType gType;
  20. VisualType vType;
  21. VisualFormat()
  22. : gType(e_GtBar)
  23. , vType(e_VtSampleing)
  24. {}
  25. } VisualFormat;
  26. public:
  27. void paint(QPainter* painter, QPaintEvent* event, const AudioData& data);
  28. void draw_data_style(QPainter* painter, const QRect& rt, const AudioData& data);
  29. void set_draw_fmt(const VisualFormat& fmt) { m_visualFmt = fmt; }
  30. private:
  31. void get_data(const AudioData& data, std::vector<int>& v, bool left = true) const;
  32. void normal_data(std::vector<int>& v, const int height);
  33. void normal_overzero(std::vector<int>& v);
  34. void normal_audio_to_size(std::vector<int>& v, const int size);
  35. void normal_to_size(std::vector<int>& v, const int size);
  36. void data_sample_old(std::vector<int>& v, const uint32_t num); //wav sampling
  37. void data_sample(std::vector<int>& v, const uint32_t num); //wav sampling
  38. void binary_data(std::vector<int>& v);
  39. void data_frequency(std::vector<int>& v, const uint32_t num);
  40. void draw_data_bar(QPainter* painter, std::vector<int>& data, int n, int w, int h, int h_inter);
  41. void draw_data_line(QPainter* painter, std::vector<int>& data, int n, int w, int h, int h_inter);
  42. void draw_data_arc(QPainter* painter, std::vector<int>& data, int n, int w, int h);
  43. void draw_data_polygon(
  44. QPainter* painter, std::vector<int>& data, int n, int w, int h, int r_offset = 50);
  45. private:
  46. QBrush m_background;
  47. QBrush m_brush;
  48. QFont m_textFont;
  49. QPen m_pen;
  50. QPen m_textPen;
  51. AudioFrameFmt m_datafmt;
  52. VisualFormat m_visualFmt;
  53. };
  54. #endif // AVPLAYER2_AUDIO_EFFECT_HELPER_H