PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
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.

186 lines
4.9KB

  1. /* Audio Library for Teensy 3.X
  2. * Copyright (c) 2018, Paul Stoffregen, paul@pjrc.com
  3. *
  4. * Development of this audio library was funded by PJRC.COM, LLC by sales of
  5. * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop
  6. * open source software by purchasing Teensy or other PJRC products.
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice, development funding notice, and this permission
  16. * notice shall be included in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. */
  26. #ifndef effect_freeverb_h_
  27. #define effect_freeverb_h_
  28. #include <Arduino.h>
  29. #include "AudioStream.h"
  30. class AudioEffectFreeverb : public AudioStream
  31. {
  32. public:
  33. AudioEffectFreeverb();
  34. virtual void update();
  35. void roomsize(float n) {
  36. if (n > 1.0f) n = 1.0f;
  37. else if (n < 0.0) n = 0.0f;
  38. combfeeback = (int)(n * 9175.04f) + 22937;
  39. }
  40. void damping(float n) {
  41. if (n > 1.0f) n = 1.0f;
  42. else if (n < 0.0) n = 0.0f;
  43. int x1 = (int)(n * 13107.2f);
  44. int x2 = 32768 - x1;
  45. __disable_irq();
  46. combdamp1 = x1;
  47. combdamp2 = x2;
  48. __enable_irq();
  49. }
  50. private:
  51. audio_block_t *inputQueueArray[1];
  52. int16_t comb1buf[1116];
  53. int16_t comb2buf[1188];
  54. int16_t comb3buf[1277];
  55. int16_t comb4buf[1356];
  56. int16_t comb5buf[1422];
  57. int16_t comb6buf[1491];
  58. int16_t comb7buf[1557];
  59. int16_t comb8buf[1617];
  60. uint16_t comb1index;
  61. uint16_t comb2index;
  62. uint16_t comb3index;
  63. uint16_t comb4index;
  64. uint16_t comb5index;
  65. uint16_t comb6index;
  66. uint16_t comb7index;
  67. uint16_t comb8index;
  68. int16_t comb1filter;
  69. int16_t comb2filter;
  70. int16_t comb3filter;
  71. int16_t comb4filter;
  72. int16_t comb5filter;
  73. int16_t comb6filter;
  74. int16_t comb7filter;
  75. int16_t comb8filter;
  76. int16_t combdamp1;
  77. int16_t combdamp2;
  78. int16_t combfeeback;
  79. int16_t allpass1buf[556];
  80. int16_t allpass2buf[441];
  81. int16_t allpass3buf[341];
  82. int16_t allpass4buf[225];
  83. uint16_t allpass1index;
  84. uint16_t allpass2index;
  85. uint16_t allpass3index;
  86. uint16_t allpass4index;
  87. };
  88. class AudioEffectFreeverbStereo : public AudioStream
  89. {
  90. public:
  91. AudioEffectFreeverbStereo();
  92. virtual void update();
  93. void roomsize(float n) {
  94. if (n > 1.0f) n = 1.0f;
  95. else if (n < 0.0) n = 0.0f;
  96. combfeeback = (int)(n * 9175.04f) + 22937;
  97. }
  98. void damping(float n) {
  99. if (n > 1.0f) n = 1.0f;
  100. else if (n < 0.0) n = 0.0f;
  101. int x1 = (int)(n * 13107.2f);
  102. int x2 = 32768 - x1;
  103. __disable_irq();
  104. combdamp1 = x1;
  105. combdamp2 = x2;
  106. __enable_irq();
  107. }
  108. private:
  109. audio_block_t *inputQueueArray[1];
  110. int16_t comb1bufL[1116];
  111. int16_t comb2bufL[1188];
  112. int16_t comb3bufL[1277];
  113. int16_t comb4bufL[1356];
  114. int16_t comb5bufL[1422];
  115. int16_t comb6bufL[1491];
  116. int16_t comb7bufL[1557];
  117. int16_t comb8bufL[1617];
  118. uint16_t comb1indexL;
  119. uint16_t comb2indexL;
  120. uint16_t comb3indexL;
  121. uint16_t comb4indexL;
  122. uint16_t comb5indexL;
  123. uint16_t comb6indexL;
  124. uint16_t comb7indexL;
  125. uint16_t comb8indexL;
  126. int16_t comb1filterL;
  127. int16_t comb2filterL;
  128. int16_t comb3filterL;
  129. int16_t comb4filterL;
  130. int16_t comb5filterL;
  131. int16_t comb6filterL;
  132. int16_t comb7filterL;
  133. int16_t comb8filterL;
  134. int16_t comb1bufR[1139];
  135. int16_t comb2bufR[1211];
  136. int16_t comb3bufR[1300];
  137. int16_t comb4bufR[1379];
  138. int16_t comb5bufR[1445];
  139. int16_t comb6bufR[1514];
  140. int16_t comb7bufR[1580];
  141. int16_t comb8bufR[1640];
  142. uint16_t comb1indexR;
  143. uint16_t comb2indexR;
  144. uint16_t comb3indexR;
  145. uint16_t comb4indexR;
  146. uint16_t comb5indexR;
  147. uint16_t comb6indexR;
  148. uint16_t comb7indexR;
  149. uint16_t comb8indexR;
  150. int16_t comb1filterR;
  151. int16_t comb2filterR;
  152. int16_t comb3filterR;
  153. int16_t comb4filterR;
  154. int16_t comb5filterR;
  155. int16_t comb6filterR;
  156. int16_t comb7filterR;
  157. int16_t comb8filterR;
  158. int16_t combdamp1;
  159. int16_t combdamp2;
  160. int16_t combfeeback;
  161. int16_t allpass1bufL[556];
  162. int16_t allpass2bufL[441];
  163. int16_t allpass3bufL[341];
  164. int16_t allpass4bufL[225];
  165. uint16_t allpass1indexL;
  166. uint16_t allpass2indexL;
  167. uint16_t allpass3indexL;
  168. uint16_t allpass4indexL;
  169. int16_t allpass1bufR[579];
  170. int16_t allpass2bufR[464];
  171. int16_t allpass3bufR[364];
  172. int16_t allpass4bufR[248];
  173. uint16_t allpass1indexR;
  174. uint16_t allpass2indexR;
  175. uint16_t allpass3indexR;
  176. uint16_t allpass4indexR;
  177. };
  178. #endif