1 /*************************************************************************/
2 /*  cp_player_data_filter.cpp                                            */
3 /*************************************************************************/
4 /*                       This file is part of:                           */
5 /*                           GODOT ENGINE                                */
6 /*                      https://godotengine.org                          */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur.                 */
9 /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md)    */
10 /*                                                                       */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the       */
13 /* "Software"), to deal in the Software without restriction, including   */
14 /* without limitation the rights to use, copy, modify, merge, publish,   */
15 /* distribute, sublicense, and/or sell copies of the Software, and to    */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions:                                             */
18 /*                                                                       */
19 /* The above copyright notice and this permission notice shall be        */
20 /* included in all copies or substantial portions of the Software.       */
21 /*                                                                       */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
29 /*************************************************************************/
30 
31 #include "cp_player_data.h"
32 
33 static float filter_cutoff[256] = {
34 	130, 132, 134, 136, 138, 140, 142, 144,
35 	146, 148, 151, 153, 155, 157, 160, 162,
36 	164, 167, 169, 172, 174, 177, 179, 182,
37 	184, 187, 190, 193, 195, 198, 201, 204,
38 	207, 210, 213, 216, 220, 223, 226, 229,
39 	233, 236, 239, 243, 246, 250, 254, 257,
40 	261, 265, 269, 273, 277, 281, 285, 289,
41 	293, 297, 302, 306, 311, 315, 320, 324,
42 	329, 334, 339, 344, 349, 354, 359, 364,
43 	369, 375, 380, 386, 391, 397, 403, 409,
44 	415, 421, 427, 433, 440, 446, 452, 459,
45 	466, 472, 479, 486, 493, 501, 508, 515,
46 	523, 530, 538, 546, 554, 562, 570, 578,
47 	587, 595, 604, 613, 622, 631, 640, 649,
48 	659, 668, 678, 688, 698, 708, 718, 729,
49 	739, 750, 761, 772, 783, 795, 806, 818,
50 	830, 842, 854, 867, 880, 892, 905, 918,
51 	932, 945, 959, 973, 987, 1002, 1016, 1031,
52 	1046, 1061, 1077, 1092, 1108, 1124, 1141, 1157,
53 	1174, 1191, 1209, 1226, 1244, 1262, 1280, 1299,
54 	1318, 1337, 1357, 1376, 1396, 1417, 1437, 1458,
55 	1479, 1501, 1523, 1545, 1567, 1590, 1613, 1637,
56 	1661, 1685, 1709, 1734, 1760, 1785, 1811, 1837,
57 	1864, 1891, 1919, 1947, 1975, 2004, 2033, 2062,
58 	2093, 2123, 2154, 2185, 2217, 2249, 2282, 2315,
59 	2349, 2383, 2418, 2453, 2489, 2525, 2561, 2599,
60 	2637, 2675, 2714, 2753, 2793, 2834, 2875, 2917,
61 	2959, 3003, 3046, 3091, 3135, 3181, 3227, 3274,
62 	3322, 3370, 3419, 3469, 3520, 3571, 3623, 3675,
63 	3729, 3783, 3838, 3894, 3951, 4008, 4066, 4125,
64 	4186, 4246, 4308, 4371, 4434, 4499, 4564, 4631,
65 	4698, 4766, 4836, 4906, 4978, 5050, 5123, 5198
66 };
67 
process()68 void CPPlayer::Filter_Control::process() {
69 
70 	final_cutoff = it_cutoff;
71 	if (envelope_cutoff >= 0) {
72 
73 		envelope_cutoff = envelope_cutoff * 255 / 64;
74 		final_cutoff = final_cutoff * envelope_cutoff / 255;
75 		if (final_cutoff >= 0xFF) final_cutoff = 0xFE;
76 	}
77 }
78 
set_filter_parameters(int * p_cutoff,uint8_t * p_reso)79 void CPPlayer::Filter_Control::set_filter_parameters(int *p_cutoff, uint8_t *p_reso) {
80 
81 	*p_cutoff = filter_cutoff[final_cutoff];
82 	*p_reso = it_reso;
83 }
84