bs2b.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. #include "alspan.h"
  28. namespace Bs2b {
  29. enum {
  30. /* Normal crossfeed levels */
  31. LowCLevel = 1,
  32. MiddleCLevel = 2,
  33. HighCLevel = 3,
  34. /* Easy crossfeed levels */
  35. LowECLevel = 4,
  36. MiddleECLevel = 5,
  37. HighECLevel = 6,
  38. DefaultCLevel = HighECLevel
  39. };
  40. struct bs2b {
  41. int level{}; /* Crossfeed level */
  42. int srate{}; /* Sample rate (Hz) */
  43. /* Lowpass IIR filter coefficients */
  44. float a0_lo{};
  45. float b1_lo{};
  46. /* Highboost IIR filter coefficients */
  47. float a0_hi{};
  48. float a1_hi{};
  49. float b1_hi{};
  50. /* Buffer of filter history
  51. * [0] - first channel, [1] - second channel
  52. */
  53. struct t_last_sample {
  54. float lo{};
  55. float hi{};
  56. };
  57. std::array<t_last_sample,2> history{};
  58. /* Clear buffers and set new coefficients with new crossfeed level and
  59. * sample rate values.
  60. * level - crossfeed level of *Level enum values.
  61. * srate - sample rate by Hz.
  62. */
  63. void set_params(int level, int srate);
  64. /* Return current crossfeed level value */
  65. [[nodiscard]] auto get_level() const noexcept -> int { return level; }
  66. /* Return current sample rate value */
  67. [[nodiscard]] auto get_srate() const noexcept -> int { return srate; }
  68. /* Clear buffer */
  69. void clear();
  70. void cross_feed(const al::span<float> Left, const al::span<float> Right);
  71. };
  72. } // namespace Bs2b
  73. #endif /* CORE_BS2B_H */