libsidplayfp 3.0.0
filt_tables.h
1/*
2 * This file is part of libsidplayfp, a SID player engine.
3 *
4 * Copyright (C) 2025-2026 Leandro Nini
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21
22// Based on cRSID lightweight RealSID by Hermit (Mihaly Horvath)
23
24#include <array>
25#include <cstddef>
26
27constexpr int ResLength = 0x10;
28using res_array_t = std::array<unsigned short, ResLength>;
29
30#if __cplusplus > 202302L // std::exp2 is constexpr since c++26
31# include <cmath>
32
33 constexpr int CRSID_FILTERTABLE_RESOLUTION = 12;
34 constexpr int Magnitude = (1 << CRSID_FILTERTABLE_RESOLUTION);
35
36 //8580 Resonance-DAC (1/Q) curve
37 constexpr auto createRes8580()
38 {
39 res_array_t arr {};
40
41 for (int i=0; i<ResLength; i++)
42 {
43 arr[i] = (std::exp2((4 - i) / 8.0)) * Magnitude;
44 }
45
46 return arr;
47 }
48
49 //6581 Resonance-DAC (1/Q) curve
50 constexpr auto createRes6581()
51 {
52 res_array_t arr {};
53
54 for (int i=0; i<ResLength; i++)
55 {
56 arr[i] = (i>5 ? 8.0 / i : 1.41) * Magnitude;
57 }
58
59 return arr;
60 }
61
62 static constexpr auto Resonances8580 = createRes8580();
63 static constexpr auto Resonances6581 = createRes6581();
64#else
65
66 // 8580 Resonance-DAC (1/Q) curve: Magnitude:$1000
67 static const res_array_t Resonances8580 =
68 {
69 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
70 0x16A0,0x14BF,0x1306,0x1172,0x1000,0x0EAC,0x0D74,0x0C56,0x0B50,0x0A5F,0x0983,0x08B9,0x0800,0x0756,0x06BA,0x062B,
71 //0xFF, 0xFE, 0xFC, 0xF8, 0xF0, 0xE8, 0xD5, 0xC5, 0xB3, 0xA4, 0x97, 0x8A, 0x80, 0x77, 0x6E, 0x66 <- calculated then refined manually to sound best
72 };
73
74 // 6581 Resonance-DAC (1/Q) curve: Magnitude:$1000
75 static const res_array_t Resonances6581 =
76 {
77 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
78 0x168F,0x168F,0x168F,0x168F,0x168F,0x168F,0x1555,0x1249,0x1000,0x0E38,0x0CCC,0x0BA2,0x0AAA,0x09D8,0x0924,0x0888,
79 //0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xF9, 0xF6, 0xF2, 0xEC, 0xE4, 0xCD, 0xBA, 0xAB, 0x9E, 0x92, 0x86 <- calculated then refined manually to sound best
80 };
81
82#endif