audio_effect_delay.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*************************************************************************/
  2. /* audio_effect_delay.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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 AUDIOEFFECTDELAY_H
  31. #define AUDIOEFFECTDELAY_H
  32. #include "servers/audio/audio_effect.h"
  33. class AudioEffectDelay;
  34. class AudioEffectDelayInstance : public AudioEffectInstance {
  35. GDCLASS(AudioEffectDelayInstance, AudioEffectInstance)
  36. friend class AudioEffectDelay;
  37. Ref<AudioEffectDelay> base;
  38. Vector<AudioFrame> ring_buffer;
  39. unsigned int ring_buffer_pos;
  40. unsigned int ring_buffer_mask;
  41. /* feedback buffer */
  42. Vector<AudioFrame> feedback_buffer;
  43. unsigned int feedback_buffer_pos;
  44. AudioFrame h;
  45. void _process_chunk(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count);
  46. public:
  47. virtual void process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count);
  48. };
  49. class AudioEffectDelay : public AudioEffect {
  50. GDCLASS(AudioEffectDelay, AudioEffect)
  51. friend class AudioEffectDelayInstance;
  52. enum {
  53. MAX_DELAY_MS = 3000,
  54. MAX_TAPS = 2
  55. };
  56. float dry;
  57. bool tap_1_active;
  58. float tap_1_delay_ms;
  59. float tap_1_level;
  60. float tap_1_pan;
  61. bool tap_2_active;
  62. float tap_2_delay_ms;
  63. float tap_2_level;
  64. float tap_2_pan;
  65. bool feedback_active;
  66. float feedback_delay_ms;
  67. float feedback_level;
  68. float feedback_lowpass;
  69. protected:
  70. static void _bind_methods();
  71. public:
  72. void set_dry(float p_dry);
  73. float get_dry();
  74. void set_tap1_active(bool p_active);
  75. bool is_tap1_active() const;
  76. void set_tap1_delay_ms(float p_delay_ms);
  77. float get_tap1_delay_ms() const;
  78. void set_tap1_level_db(float p_level_db);
  79. float get_tap1_level_db() const;
  80. void set_tap1_pan(float p_pan);
  81. float get_tap1_pan() const;
  82. void set_tap2_active(bool p_active);
  83. bool is_tap2_active() const;
  84. void set_tap2_delay_ms(float p_delay_ms);
  85. float get_tap2_delay_ms() const;
  86. void set_tap2_level_db(float p_level_db);
  87. float get_tap2_level_db() const;
  88. void set_tap2_pan(float p_pan);
  89. float get_tap2_pan() const;
  90. void set_feedback_active(bool p_active);
  91. bool is_feedback_active() const;
  92. void set_feedback_delay_ms(float p_delay_ms);
  93. float get_feedback_delay_ms() const;
  94. void set_feedback_level_db(float p_level_db);
  95. float get_feedback_level_db() const;
  96. void set_feedback_lowpass(float p_lowpass);
  97. float get_feedback_lowpass() const;
  98. Ref<AudioEffectInstance> instance();
  99. AudioEffectDelay();
  100. };
  101. #endif // AUDIOEFFECTDELAY_H