reverb.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*************************************************************************/
  2. /* reverb.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 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. // Author: Juan Linietsky <reduzio@gmail.com>, (C) 2006
  31. #ifndef REVERB_H
  32. #define REVERB_H
  33. #include "core/math/audio_frame.h"
  34. #include "core/os/memory.h"
  35. #include "core/typedefs.h"
  36. class Reverb {
  37. public:
  38. enum {
  39. INPUT_BUFFER_MAX_SIZE = 1024,
  40. };
  41. private:
  42. enum {
  43. MAX_COMBS = 8,
  44. MAX_ALLPASS = 4,
  45. MAX_ECHO_MS = 500
  46. };
  47. static const float comb_tunings[MAX_COMBS];
  48. static const float allpass_tunings[MAX_ALLPASS];
  49. struct Comb {
  50. int size;
  51. float *buffer;
  52. float feedback;
  53. float damp; //lowpass
  54. float damp_h; //history
  55. int pos;
  56. int extra_spread_frames;
  57. Comb() {
  58. size = 0;
  59. buffer = 0;
  60. feedback = 0;
  61. damp_h = 0;
  62. pos = 0;
  63. }
  64. };
  65. struct AllPass {
  66. int size;
  67. float *buffer;
  68. int pos;
  69. int extra_spread_frames;
  70. AllPass() {
  71. size = 0;
  72. buffer = 0;
  73. pos = 0;
  74. }
  75. };
  76. Comb comb[MAX_COMBS];
  77. AllPass allpass[MAX_ALLPASS];
  78. float *input_buffer;
  79. float *echo_buffer;
  80. int echo_buffer_size;
  81. int echo_buffer_pos;
  82. float hpf_h1, hpf_h2;
  83. struct Parameters {
  84. float room_size;
  85. float damp;
  86. float wet;
  87. float dry;
  88. float mix_rate;
  89. float extra_spread_base;
  90. float extra_spread;
  91. float predelay;
  92. float predelay_fb;
  93. float hpf;
  94. } params;
  95. void configure_buffers();
  96. void update_parameters();
  97. void clear_buffers();
  98. public:
  99. void set_room_size(float p_size);
  100. void set_damp(float p_damp);
  101. void set_wet(float p_wet);
  102. void set_dry(float p_dry);
  103. void set_predelay(float p_predelay); // in ms
  104. void set_predelay_feedback(float p_predelay_fb); // in ms
  105. void set_highpass(float p_frq);
  106. void set_mix_rate(float p_mix_rate);
  107. void set_extra_spread(float p_spread);
  108. void set_extra_spread_base(float p_sec);
  109. void process(float *p_src, float *p_dst, int p_frames);
  110. Reverb();
  111. ~Reverb();
  112. };
  113. #endif