Enable proper full C++ exception handling on MSVC
[openal-soft.git] / core / bs2b.h
blob32c77e1010e33fbe4e4bedd0f6cb07c029752ead
1 /*-
2 * Copyright (c) 2005 Boris Mikhaylov
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:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
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.
24 #ifndef CORE_BS2B_H
25 #define CORE_BS2B_H
27 #include <array>
28 #include <cstddef>
30 namespace Bs2b {
32 enum {
33 /* Normal crossfeed levels */
34 LowCLevel = 1,
35 MiddleCLevel = 2,
36 HighCLevel = 3,
38 /* Easy crossfeed levels */
39 LowECLevel = 4,
40 MiddleECLevel = 5,
41 HighECLevel = 6,
43 DefaultCLevel = HighECLevel
46 struct bs2b {
47 int level{}; /* Crossfeed level */
48 int srate{}; /* Sample rate (Hz) */
50 /* Lowpass IIR filter coefficients */
51 float a0_lo{};
52 float b1_lo{};
54 /* Highboost IIR filter coefficients */
55 float a0_hi{};
56 float a1_hi{};
57 float b1_hi{};
59 /* Buffer of filter history
60 * [0] - first channel, [1] - second channel
62 struct t_last_sample {
63 float lo{};
64 float hi{};
66 std::array<t_last_sample,2> history{};
68 /* Clear buffers and set new coefficients with new crossfeed level and
69 * sample rate values.
70 * level - crossfeed level of *Level enum values.
71 * srate - sample rate by Hz.
73 void set_params(int level, int srate);
75 /* Return current crossfeed level value */
76 [[nodiscard]] auto get_level() const noexcept -> int { return level; }
78 /* Return current sample rate value */
79 [[nodiscard]] auto get_srate() const noexcept -> int { return srate; }
81 /* Clear buffer */
82 void clear();
84 void cross_feed(float *Left, float *Right, std::size_t SamplesToDo);
87 } // namespace Bs2b
89 #endif /* CORE_BS2B_H */