audio_effect_eq.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. #pragma once
  31. #include "servers/audio/audio_effect.h"
  32. #include "servers/audio/effects/eq_filter.h"
  33. class AudioEffectEQ;
  34. class AudioEffectEQInstance : public AudioEffectInstance {
  35. GDCLASS(AudioEffectEQInstance, AudioEffectInstance);
  36. friend class AudioEffectEQ;
  37. Ref<AudioEffectEQ> base;
  38. Vector<EQ::BandProcess> bands[2];
  39. Vector<float> gains;
  40. public:
  41. virtual void process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) override;
  42. };
  43. class AudioEffectEQ : public AudioEffect {
  44. GDCLASS(AudioEffectEQ, AudioEffect);
  45. friend class AudioEffectEQInstance;
  46. EQ eq;
  47. Vector<float> gain;
  48. HashMap<StringName, int> prop_band_map;
  49. Vector<String> band_names;
  50. protected:
  51. bool _set(const StringName &p_name, const Variant &p_value);
  52. bool _get(const StringName &p_name, Variant &r_ret) const;
  53. void _get_property_list(List<PropertyInfo> *p_list) const;
  54. static void _bind_methods();
  55. public:
  56. Ref<AudioEffectInstance> instantiate() override;
  57. void set_band_gain_db(int p_band, float p_volume);
  58. float get_band_gain_db(int p_band) const;
  59. int get_band_count() const;
  60. AudioEffectEQ(EQ::Preset p_preset = EQ::PRESET_6_BANDS);
  61. };
  62. class AudioEffectEQ6 : public AudioEffectEQ {
  63. GDCLASS(AudioEffectEQ6, AudioEffectEQ);
  64. public:
  65. AudioEffectEQ6() :
  66. AudioEffectEQ(EQ::PRESET_6_BANDS) {}
  67. };
  68. class AudioEffectEQ10 : public AudioEffectEQ {
  69. GDCLASS(AudioEffectEQ10, AudioEffectEQ);
  70. public:
  71. AudioEffectEQ10() :
  72. AudioEffectEQ(EQ::PRESET_10_BANDS) {}
  73. };
  74. class AudioEffectEQ21 : public AudioEffectEQ {
  75. GDCLASS(AudioEffectEQ21, AudioEffectEQ);
  76. public:
  77. AudioEffectEQ21() :
  78. AudioEffectEQ(EQ::PRESET_21_BANDS) {}
  79. };