bs2b.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*-
  2. * Copyright (c) 2005 Boris Mikhaylov
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining
  5. * a copy of this software and associated documentation files (the
  6. * "Software"), to deal in the Software without restriction, including
  7. * without limitation the rights to use, copy, modify, merge, publish,
  8. * distribute, sublicense, and/or sell copies of the Software, and to
  9. * permit persons to whom the Software is furnished to do so, subject to
  10. * the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be
  13. * included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  18. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  19. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  20. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  21. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #ifndef CORE_BS2B_H
  24. #define CORE_BS2B_H
  25. #include <array>
  26. #include <cstddef>
  27. namespace Bs2b {
  28. enum {
  29. /* Normal crossfeed levels */
  30. LowCLevel = 1,
  31. MiddleCLevel = 2,
  32. HighCLevel = 3,
  33. /* Easy crossfeed levels */
  34. LowECLevel = 4,
  35. MiddleECLevel = 5,
  36. HighECLevel = 6,
  37. DefaultCLevel = HighECLevel
  38. };
  39. struct bs2b {
  40. int level{}; /* Crossfeed level */
  41. int srate{}; /* Sample rate (Hz) */
  42. /* Lowpass IIR filter coefficients */
  43. float a0_lo{};
  44. float b1_lo{};
  45. /* Highboost IIR filter coefficients */
  46. float a0_hi{};
  47. float a1_hi{};
  48. float b1_hi{};
  49. /* Buffer of filter history
  50. * [0] - first channel, [1] - second channel
  51. */
  52. struct t_last_sample {
  53. float lo{};
  54. float hi{};
  55. };
  56. std::array<t_last_sample,2> history{};
  57. /* Clear buffers and set new coefficients with new crossfeed level and
  58. * sample rate values.
  59. * level - crossfeed level of *Level enum values.
  60. * srate - sample rate by Hz.
  61. */
  62. void set_params(int level, int srate);
  63. /* Return current crossfeed level value */
  64. [[nodiscard]] auto get_level() const noexcept -> int { return level; }
  65. /* Return current sample rate value */
  66. [[nodiscard]] auto get_srate() const noexcept -> int { return srate; }
  67. /* Clear buffer */
  68. void clear();
  69. void cross_feed(float *Left, float *Right, std::size_t SamplesToDo);
  70. };
  71. } // namespace Bs2b
  72. #endif /* CORE_BS2B_H */