audio_effect_chorus.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*************************************************************************/
  2. /* audio_effect_chorus.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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 AUDIOEFFECTCHORUS_H
  31. #define AUDIOEFFECTCHORUS_H
  32. #include "servers/audio/audio_effect.h"
  33. class AudioEffectChorus;
  34. class AudioEffectChorusInstance : public AudioEffectInstance {
  35. GDCLASS(AudioEffectChorusInstance, AudioEffectInstance);
  36. friend class AudioEffectChorus;
  37. Ref<AudioEffectChorus> base;
  38. Vector<AudioFrame> audio_buffer;
  39. unsigned int buffer_pos;
  40. unsigned int buffer_mask;
  41. AudioFrame filter_h[4];
  42. uint64_t cycles[4];
  43. void _process_chunk(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count);
  44. public:
  45. virtual void process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count);
  46. };
  47. class AudioEffectChorus : public AudioEffect {
  48. GDCLASS(AudioEffectChorus, AudioEffect);
  49. friend class AudioEffectChorusInstance;
  50. public:
  51. enum {
  52. MAX_DELAY_MS = 50,
  53. MAX_DEPTH_MS = 20,
  54. MAX_WIDTH_MS = 50,
  55. MAX_VOICES = 4,
  56. CYCLES_FRAC = 16,
  57. CYCLES_MASK = (1 << CYCLES_FRAC) - 1,
  58. MAX_CHANNELS = 4,
  59. MS_CUTOFF_MAX = 16000
  60. };
  61. private:
  62. struct Voice {
  63. float delay;
  64. float rate;
  65. float depth;
  66. float level;
  67. float cutoff;
  68. float pan;
  69. Voice() {
  70. delay = 12.0;
  71. rate = 1;
  72. depth = 0;
  73. level = 0;
  74. cutoff = MS_CUTOFF_MAX;
  75. pan = 0;
  76. }
  77. } voice[MAX_VOICES];
  78. int voice_count;
  79. float wet;
  80. float dry;
  81. protected:
  82. void _validate_property(PropertyInfo &property) const;
  83. static void _bind_methods();
  84. public:
  85. void set_voice_count(int p_voices);
  86. int get_voice_count() const;
  87. void set_voice_delay_ms(int p_voice, float p_delay_ms);
  88. float get_voice_delay_ms(int p_voice) const;
  89. void set_voice_rate_hz(int p_voice, float p_rate_hz);
  90. float get_voice_rate_hz(int p_voice) const;
  91. void set_voice_depth_ms(int p_voice, float p_depth_ms);
  92. float get_voice_depth_ms(int p_voice) const;
  93. void set_voice_level_db(int p_voice, float p_level_db);
  94. float get_voice_level_db(int p_voice) const;
  95. void set_voice_cutoff_hz(int p_voice, float p_cutoff_hz);
  96. float get_voice_cutoff_hz(int p_voice) const;
  97. void set_voice_pan(int p_voice, float p_pan);
  98. float get_voice_pan(int p_voice) const;
  99. void set_wet(float amount);
  100. float get_wet() const;
  101. void set_dry(float amount);
  102. float get_dry() const;
  103. Ref<AudioEffectInstance> instance();
  104. AudioEffectChorus();
  105. };
  106. #endif // AUDIOEFFECTCHORUS_H