audio_effect_eq.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /**************************************************************************/
  2. /* audio_effect_eq.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef AUDIO_EFFECT_EQ_H
  31. #define AUDIO_EFFECT_EQ_H
  32. #include "servers/audio/audio_effect.h"
  33. #include "servers/audio/effects/eq_filter.h"
  34. class AudioEffectEQ;
  35. class AudioEffectEQInstance : public AudioEffectInstance {
  36. GDCLASS(AudioEffectEQInstance, AudioEffectInstance);
  37. friend class AudioEffectEQ;
  38. Ref<AudioEffectEQ> base;
  39. Vector<EQ::BandProcess> bands[2];
  40. Vector<float> gains;
  41. public:
  42. virtual void process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) override;
  43. };
  44. class AudioEffectEQ : public AudioEffect {
  45. GDCLASS(AudioEffectEQ, AudioEffect);
  46. friend class AudioEffectEQInstance;
  47. EQ eq;
  48. Vector<float> gain;
  49. HashMap<StringName, int> prop_band_map;
  50. Vector<String> band_names;
  51. protected:
  52. bool _set(const StringName &p_name, const Variant &p_value);
  53. bool _get(const StringName &p_name, Variant &r_ret) const;
  54. void _get_property_list(List<PropertyInfo> *p_list) const;
  55. static void _bind_methods();
  56. public:
  57. Ref<AudioEffectInstance> instantiate() override;
  58. void set_band_gain_db(int p_band, float p_volume);
  59. float get_band_gain_db(int p_band) const;
  60. int get_band_count() const;
  61. AudioEffectEQ(EQ::Preset p_preset = EQ::PRESET_6_BANDS);
  62. };
  63. class AudioEffectEQ6 : public AudioEffectEQ {
  64. GDCLASS(AudioEffectEQ6, AudioEffectEQ);
  65. public:
  66. AudioEffectEQ6() :
  67. AudioEffectEQ(EQ::PRESET_6_BANDS) {}
  68. };
  69. class AudioEffectEQ10 : public AudioEffectEQ {
  70. GDCLASS(AudioEffectEQ10, AudioEffectEQ);
  71. public:
  72. AudioEffectEQ10() :
  73. AudioEffectEQ(EQ::PRESET_10_BANDS) {}
  74. };
  75. class AudioEffectEQ21 : public AudioEffectEQ {
  76. GDCLASS(AudioEffectEQ21, AudioEffectEQ);
  77. public:
  78. AudioEffectEQ21() :
  79. AudioEffectEQ(EQ::PRESET_21_BANDS) {}
  80. };
  81. #endif // AUDIO_EFFECT_EQ_H