2 Calf Box, an open source musical instrument.
3 Copyright (C) 2010-2011 Krzysztof Foltman
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "config-api.h"
23 #include "onepole-float.h"
32 #define MODULE_PARAMS tone_control_params
34 struct tone_control_params
36 float lowpass
, highpass
;
39 struct tone_control_module
41 struct cbox_module module
;
43 struct tone_control_params
*params
, *old_params
;
45 struct cbox_onepolef_coeffs lowpass_coeffs
, highpass_coeffs
;
47 struct cbox_onepolef_state lowpass_state
[2], highpass_state
[2];
49 float tpdsr
; // 2 pi / sr
52 gboolean
tone_control_process_cmd(struct cbox_command_target
*ct
, struct cbox_command_target
*fb
, struct cbox_osc_command
*cmd
, GError
**error
)
54 struct tone_control_module
*m
= (struct tone_control_module
*)ct
->user_data
;
56 EFFECT_PARAM("/lowpass", "f", lowpass
, double, , 5, 20000) else
57 EFFECT_PARAM("/highpass", "f", highpass
, double, , 5, 20000) else
58 if (!strcmp(cmd
->command
, "/status") && !strcmp(cmd
->arg_types
, ""))
60 if (!cbox_check_fb_channel(fb
, cmd
->command
, error
))
62 return cbox_execute_on(fb
, NULL
, "/lowpass", "f", error
, m
->params
->lowpass
)
63 && cbox_execute_on(fb
, NULL
, "/highpass", "f", error
, m
->params
->highpass
)
64 && CBOX_OBJECT_DEFAULT_STATUS(&m
->module
, fb
, error
)
68 return cbox_object_default_process_cmd(ct
, fb
, cmd
, error
);
72 void tone_control_process_event(struct cbox_module
*module
, const uint8_t *data
, uint32_t len
)
74 // struct tone_control_module *m = (struct tone_control_module *)module;
77 void tone_control_process_block(struct cbox_module
*module
, cbox_sample_t
**inputs
, cbox_sample_t
**outputs
)
79 struct tone_control_module
*m
= (struct tone_control_module
*)module
;
81 if (m
->params
!= m
->old_params
)
83 cbox_onepolef_set_lowpass(&m
->lowpass_coeffs
, m
->params
->lowpass
* m
->tpdsr
);
84 cbox_onepolef_set_highpass(&m
->highpass_coeffs
, m
->params
->highpass
* m
->tpdsr
);
85 m
->old_params
= m
->params
;
88 cbox_onepolef_process_to(&m
->lowpass_state
[0], &m
->lowpass_coeffs
, inputs
[0], outputs
[0]);
89 cbox_onepolef_process_to(&m
->lowpass_state
[1], &m
->lowpass_coeffs
, inputs
[1], outputs
[1]);
90 cbox_onepolef_process(&m
->highpass_state
[0], &m
->highpass_coeffs
, outputs
[0]);
91 cbox_onepolef_process(&m
->highpass_state
[1], &m
->highpass_coeffs
, outputs
[1]);
94 MODULE_SIMPLE_DESTROY_FUNCTION(tone_control
)
96 MODULE_CREATE_FUNCTION(tone_control
)
98 static int inited
= 0;
104 struct tone_control_module
*m
= malloc(sizeof(struct tone_control_module
));
105 CALL_MODULE_INIT(m
, 2, 2, tone_control
);
106 m
->module
.process_event
= tone_control_process_event
;
107 m
->module
.process_block
= tone_control_process_block
;
109 m
->tpdsr
= 2 * M_PI
* m
->module
.srate_inv
;
111 m
->old_params
= NULL
;
112 m
->params
= malloc(sizeof(struct tone_control_params
));
114 m
->params
->lowpass
= cbox_config_get_float(cfg_section
, "lowpass", 8000.f
);
115 m
->params
->highpass
= cbox_config_get_float(cfg_section
, "highpass", 75.f
);
117 cbox_onepolef_reset(&m
->lowpass_state
[0]);
118 cbox_onepolef_reset(&m
->lowpass_state
[1]);
119 cbox_onepolef_reset(&m
->highpass_state
[0]);
120 cbox_onepolef_reset(&m
->highpass_state
[1]);
126 struct cbox_module_keyrange_metadata tone_control_keyranges
[] = {
129 struct cbox_module_livecontroller_metadata tone_control_controllers
[] = {
132 DEFINE_MODULE(tone_control
, 2, 2)