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.

112 lines
4.3KB

  1. // Copyright 2012 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. // Macros for linearly interpolating parameters - used when the modulated signal
  28. // is a sine or triangle - which makes the 4kHz quantization obvious.
  29. #ifndef BRAIDS_PARAMETER_INTERPOLATION_H_
  30. #define BRAIDS_PARAMETER_INTERPOLATION_H_
  31. // Macro for linear interpolation of parameters.
  32. #define BEGIN_INTERPOLATE_PARAMETERS \
  33. int32_t parameter_0_start = previous_parameter_[0]; \
  34. int32_t parameter_1_start = previous_parameter_[1]; \
  35. int32_t parameter_0_delta = parameter_[0] - previous_parameter_[0]; \
  36. int32_t parameter_1_end = parameter_[1] - previous_parameter_[1]; \
  37. int32_t parameter_increment = 32767 / size; \
  38. int32_t parameter_xfade = 0;
  39. #define INTERPOLATE_PARAMETERS \
  40. parameter_xfade += parameter_increment; \
  41. int32_t parameter_0 = parameter_0_start + \
  42. (parameter_0_delta * parameter_xfade >> 15); \
  43. int32_t parameter_1 = parameter_0_start + \
  44. (parameter_0_delta * parameter_xfade >> 15);
  45. #define END_INTERPOLATE_PARAMETERS \
  46. previous_parameter_[0] = parameter_[0]; \
  47. previous_parameter_[1] = parameter_[1];
  48. #define BEGIN_INTERPOLATE_PARAMETER_0 \
  49. int32_t parameter_0_start = previous_parameter_[0]; \
  50. int32_t parameter_0_delta = parameter_[0] - previous_parameter_[0]; \
  51. int32_t parameter_increment = 32767 / size; \
  52. int32_t parameter_xfade = 0;
  53. #define INTERPOLATE_PARAMETER_0 \
  54. parameter_xfade += parameter_increment; \
  55. int32_t parameter_0 = parameter_0_start + \
  56. (parameter_0_delta * parameter_xfade >> 15);
  57. #define END_INTERPOLATE_PARAMETER_0 \
  58. previous_parameter_[0] = parameter_[0];
  59. #define BEGIN_INTERPOLATE_PARAMETER_1 \
  60. int32_t parameter_1_start = previous_parameter_[1]; \
  61. int32_t parameter_1_delta = parameter_[1] - previous_parameter_[1]; \
  62. int32_t parameter_increment = 32767 / size; \
  63. int32_t parameter_xfade = 0;
  64. #define INTERPOLATE_PARAMETER_1 \
  65. parameter_xfade += parameter_increment; \
  66. int32_t parameter_1 = parameter_1_start + \
  67. (parameter_1_delta * parameter_xfade >> 15);
  68. #define END_INTERPOLATE_PARAMETER_1 \
  69. previous_parameter_[1] = parameter_[1];
  70. #define BEGIN_INTERPOLATE_PARAMETER \
  71. int32_t parameter_start = previous_parameter_; \
  72. int32_t parameter_delta = parameter_ - previous_parameter_; \
  73. int32_t parameter_increment = 32767 / size; \
  74. int32_t parameter_xfade = 0;
  75. #define INTERPOLATE_PARAMETER \
  76. parameter_xfade += parameter_increment; \
  77. int32_t parameter = parameter_start + \
  78. (parameter_delta * parameter_xfade >> 15);
  79. #define END_INTERPOLATE_PARAMETER \
  80. previous_parameter_ = parameter_;
  81. #define BEGIN_INTERPOLATE_PHASE_INCREMENT \
  82. uint32_t phase_increment = previous_phase_increment_; \
  83. uint32_t phase_increment_increment = \
  84. previous_phase_increment_ < phase_increment_ \
  85. ? (phase_increment_ - previous_phase_increment_) / size \
  86. : ~((previous_phase_increment_ - phase_increment_) / size);
  87. #define INTERPOLATE_PHASE_INCREMENT \
  88. phase_increment += phase_increment_increment;
  89. #define END_INTERPOLATE_PHASE_INCREMENT \
  90. previous_phase_increment_ = phase_increment;
  91. #endif // BRAIDS_PARAMETER_INTERPOLATION_H_