You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
3.2KB

  1. // Copyright 2014 Olivier Gillet.
  2. //
  3. // Author: Olivier Gillet (ol.gillet@gmail.com)
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. // See http://creativecommons.org/licenses/MIT/ for more information.
  24. //
  25. // -----------------------------------------------------------------------------
  26. //
  27. // AP diffusion network.
  28. #ifndef CLOUDS_DSP_FX_DIFFUSER_H_
  29. #define CLOUDS_DSP_FX_DIFFUSER_H_
  30. #include "stmlib/stmlib.h"
  31. #include "clouds/dsp/fx/fx_engine.h"
  32. namespace clouds {
  33. class Diffuser {
  34. public:
  35. Diffuser() { }
  36. ~Diffuser() { }
  37. void Init(float* buffer) {
  38. engine_.Init(buffer);
  39. }
  40. void Process(FloatFrame* in_out, size_t size) {
  41. typedef E::Reserve<126,
  42. E::Reserve<180,
  43. E::Reserve<269,
  44. E::Reserve<444,
  45. E::Reserve<151,
  46. E::Reserve<205,
  47. E::Reserve<245,
  48. E::Reserve<405> > > > > > > > Memory;
  49. E::DelayLine<Memory, 0> apl1;
  50. E::DelayLine<Memory, 1> apl2;
  51. E::DelayLine<Memory, 2> apl3;
  52. E::DelayLine<Memory, 3> apl4;
  53. E::DelayLine<Memory, 4> apr1;
  54. E::DelayLine<Memory, 5> apr2;
  55. E::DelayLine<Memory, 6> apr3;
  56. E::DelayLine<Memory, 7> apr4;
  57. E::Context c;
  58. const float kap = 0.625f;
  59. while (size--) {
  60. engine_.Start(&c);
  61. float wet = 0.0f;
  62. c.Read(in_out->l);
  63. c.Read(apl1 TAIL, kap);
  64. c.WriteAllPass(apl1, -kap);
  65. c.Read(apl2 TAIL, kap);
  66. c.WriteAllPass(apl2, -kap);
  67. c.Read(apl3 TAIL, kap);
  68. c.WriteAllPass(apl3, -kap);
  69. c.Read(apl4 TAIL, kap);
  70. c.WriteAllPass(apl4, -kap);
  71. c.Write(wet, 0.0f);
  72. in_out->l += amount_ * (wet - in_out->l);
  73. c.Read(in_out->r);
  74. c.Read(apr1 TAIL, kap);
  75. c.WriteAllPass(apr1, -kap);
  76. c.Read(apr2 TAIL, kap);
  77. c.WriteAllPass(apr2, -kap);
  78. c.Read(apr3 TAIL, kap);
  79. c.WriteAllPass(apr3, -kap);
  80. c.Read(apr4 TAIL, kap);
  81. c.WriteAllPass(apr4, -kap);
  82. c.Write(wet, 0.0f);
  83. in_out->r += amount_ * (wet - in_out->r);
  84. ++in_out;
  85. }
  86. }
  87. void set_amount(float amount) {
  88. amount_ = amount;
  89. }
  90. private:
  91. typedef FxEngine<2048, FORMAT_32_BIT> E;
  92. E engine_;
  93. float amount_;
  94. DISALLOW_COPY_AND_ASSIGN(Diffuser);
  95. };
  96. } // namespace clouds
  97. #endif // CLOUDS_DSP_FX_DIFFUSER_H_