Ring Modulator: Initial rudimentary implementation
[calf.git] / src / calf / plugin_tools.h
bloba61ce0cbfdf936957fab68bf81589292789dbf76
1 /* Calf DSP plugin pack
2 * Tools to use in plugins
4 * Copyright (C) 2001-2010 Krzysztof Foltman, Markus Schmidt, Thor Harald Johansen and others
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
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 GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General
17 * Public License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02111-1307, USA.
21 #ifndef CALF_PLUGIN_TOOLS_H
22 #define CALF_PLUGIN_TOOLS_H
24 #include <config.h>
26 #include "giface.h"
27 #include "vumeter.h"
29 namespace calf_plugins {
31 class vumeters
33 public:
34 struct meter_data
36 int level_idx;
37 int clip_idx;
38 dsp::vumeter meter;
41 std::vector<meter_data> meters;
42 float *const *params;
44 void init(float *const *prms, int *lvls, int *clps, int length, uint32_t srate) {
45 meters.resize(length);
46 for (int i = 0; i < length; i++) {
47 meter_data &md = meters[i];
48 md.level_idx = lvls[i];
49 md.clip_idx = clps[i];
50 md.meter.set_reverse(lvls[i] < -1);
51 md.meter.set_falloff(1.f, srate);
53 params = prms;
55 void process(float *values) {
56 for (size_t i = 0; i < meters.size(); ++i) {
57 meter_data &md = meters[i];
58 if ((md.level_idx != -1 && params[(int)fabs(md.level_idx)] != NULL) ||
59 (md.clip_idx != -1 && params[(int)fabs(md.clip_idx)] != NULL))
61 md.meter.process(values[i]);
62 if (md.level_idx != -1 && params[(int)fabs(md.level_idx)])
63 *params[(int)fabs(md.level_idx)] = md.meter.level;
64 if (md.clip_idx != -1 && params[(int)fabs(md.clip_idx)])
65 *params[(int)fabs(md.clip_idx)] = md.meter.clip > 0 ? 1.f : 0.f;
69 void fall(unsigned int numsamples) {
70 for (size_t i = 0; i < meters.size(); ++i)
71 if (meters[i].level_idx != -1)
72 meters[i].meter.fall(numsamples);
76 struct debug_send_configure_iface: public send_configure_iface
78 void send_configure(const char *key, const char *value)
80 printf("send_configure key=%s value=%s\n", key, value);
86 #endif