bs2b.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 BS2B_H
  24. #define BS2B_H
  25. #include "AL/al.h"
  26. /* Number of crossfeed levels */
  27. #define BS2B_CLEVELS 3
  28. /* Normal crossfeed levels */
  29. #define BS2B_HIGH_CLEVEL 3
  30. #define BS2B_MIDDLE_CLEVEL 2
  31. #define BS2B_LOW_CLEVEL 1
  32. /* Easy crossfeed levels */
  33. #define BS2B_HIGH_ECLEVEL BS2B_HIGH_CLEVEL + BS2B_CLEVELS
  34. #define BS2B_MIDDLE_ECLEVEL BS2B_MIDDLE_CLEVEL + BS2B_CLEVELS
  35. #define BS2B_LOW_ECLEVEL BS2B_LOW_CLEVEL + BS2B_CLEVELS
  36. /* Default crossfeed levels */
  37. #define BS2B_DEFAULT_CLEVEL BS2B_HIGH_ECLEVEL
  38. /* Default sample rate (Hz) */
  39. #define BS2B_DEFAULT_SRATE 44100
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif /* __cplusplus */
  43. struct bs2b {
  44. int level; /* Crossfeed level */
  45. int srate; /* Sample rate (Hz) */
  46. /* Lowpass IIR filter coefficients */
  47. double a0_lo;
  48. double b1_lo;
  49. /* Highboost IIR filter coefficients */
  50. double a0_hi;
  51. double a1_hi;
  52. double b1_hi;
  53. /* Global gain against overloading */
  54. double gain;
  55. /* Buffer of last filtered sample.
  56. * [0] - first channel, [1] - second channel
  57. */
  58. struct t_last_sample {
  59. double asis[2];
  60. double lo[2];
  61. double hi[2];
  62. } last_sample;
  63. };
  64. /* Clear buffers and set new coefficients with new crossfeed level value.
  65. * level - crossfeed level of *LEVEL values.
  66. */
  67. void bs2b_set_level(struct bs2b *bs2b, int level);
  68. /* Return current crossfeed level value */
  69. int bs2b_get_level(struct bs2b *bs2b);
  70. /* Clear buffers and set new coefficients with new sample rate value.
  71. * srate - sample rate by Hz.
  72. */
  73. void bs2b_set_srate(struct bs2b *bs2b, int srate);
  74. /* Return current sample rate value */
  75. int bs2b_get_srate(struct bs2b *bs2b);
  76. /* Clear buffer */
  77. void bs2b_clear(struct bs2b *bs2b);
  78. /* Return 1 if buffer is clear */
  79. int bs2b_is_clear(struct bs2b *bs2b);
  80. /* Crossfeeds one stereo sample that are pointed by sample.
  81. * [0] - first channel, [1] - second channel.
  82. * Returns crossfided samle by sample pointer.
  83. */
  84. /* sample points to floats */
  85. void bs2b_cross_feed(struct bs2b *bs2b, ALfp *sample);
  86. #ifdef __cplusplus
  87. } /* extern "C" */
  88. #endif /* __cplusplus */
  89. #endif /* BS2B_H */