PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

119 lines
3.2KB

  1. /* Reverb for Teensy
  2. *
  3. * Author: Joao Rossi Filho
  4. * joaorossifilho@gmail.com
  5. *
  6. * Soon I'll make a commit with nice comments and discription
  7. *
  8. * Copyright (c) 2016 Joao Rossi FIlho
  9. *
  10. * Permission is hereby granted, free of charge, to any person obtaining a copy
  11. * of this software and associated documentation files (the "Software"), to deal
  12. * in the Software without restriction, including without limitation the rights
  13. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14. * copies of the Software, and to permit persons to whom the Software is
  15. * furnished to do so, subject to the following conditions:
  16. *
  17. * The above copyright notice and this permission notice shall be included in all
  18. * copies or substantial portions of the Software.
  19. *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  26. * SOFTWARE.
  27. */
  28. #ifndef effect_reverb_
  29. #define effect_reverb_
  30. #include "AudioStream.h"
  31. #define APF1_BUF_LEN 600
  32. #define APF2_BUF_LEN 1300
  33. #define APF3_BUF_LEN 500
  34. #define LPF1_BUF_LEN 1400
  35. #define LPF2_BUF_LEN 1700
  36. #define LPF3_BUF_LEN 1800
  37. #define LPF4_BUF_LEN 2000
  38. #define APF1_DLY_LEN 586
  39. #define APF2_DLY_LEN 1239
  40. #define APF3_DLY_LEN 485
  41. #define LPF1_DLY_LEN 1398
  42. #define LPF2_DLY_LEN 1637
  43. #define LPF3_DLY_LEN 1774
  44. #define LPF4_DLY_LEN 1947
  45. #define LPF1_DLY_SEC 0.03171
  46. #define LPF2_DLY_SEC 0.03711
  47. #define LPF3_DLY_SEC 0.04023
  48. #define LPF4_DLY_SEC 0.04414
  49. class AudioEffectReverb : public AudioStream
  50. {
  51. public:
  52. AudioEffectReverb(void) : AudioStream(1, inputQueueArray) {
  53. init_comb_filters();
  54. clear_buffers();
  55. reverbTime(5.0);
  56. }
  57. virtual void update(void);
  58. void reverbTime(float);
  59. private:
  60. struct comb_apf {
  61. int32_t g;
  62. int32_t *buffer;
  63. uint32_t buf_len;
  64. uint32_t delay, rd_idx, wr_idx;
  65. };
  66. struct comb_lpf {
  67. int32_t g1, g2, z1;
  68. int32_t *buffer;
  69. uint32_t buf_len;
  70. uint32_t delay, rd_idx, wr_idx;
  71. };
  72. void init_comb_filters(void);
  73. void clear_buffers(void);
  74. static void _do_comb_apf(struct comb_apf *apf, int32_t *in_buf, int32_t *out_buf);
  75. static void _do_comb_lpf(struct comb_lpf *lpf, int32_t *in_buf, int32_t *out_buf);
  76. audio_block_t *inputQueueArray[1];
  77. struct comb_apf apf[3];
  78. struct comb_lpf lpf[4];
  79. float reverb_time_sec;
  80. float g_flt_apf[3];
  81. int32_t g_q31_apf[3];
  82. float g1_flt_lpf[4];
  83. int32_t g1_q31_lpf[4];
  84. float g2_flt_lpf;
  85. int32_t g2_q31_lpf;
  86. int32_t apf1_buf[APF1_BUF_LEN];
  87. int32_t apf2_buf[APF2_BUF_LEN];
  88. int32_t apf3_buf[APF3_BUF_LEN];
  89. int32_t lpf1_buf[LPF1_BUF_LEN];
  90. int32_t lpf2_buf[LPF2_BUF_LEN];
  91. int32_t lpf3_buf[LPF3_BUF_LEN];
  92. int32_t lpf4_buf[LPF4_BUF_LEN];
  93. int32_t q31_buf[AUDIO_BLOCK_SAMPLES];
  94. int32_t sum_buf[AUDIO_BLOCK_SAMPLES];
  95. int32_t aux_buf[AUDIO_BLOCK_SAMPLES];
  96. };
  97. #endif