clap

CLAP Audio Plugin API
Log | Files | Refs | README | LICENSE

commit 5d480de905a988f29860556b361d941d724de97a
parent 8d874c91ed02b21b5db90b24cf481fb2c9da534e
Author: Alexandre Bique <bique.alexandre@gmail.com>
Date:   Wed,  7 Jan 2015 10:46:27 +0100

thyns: fix bugs

Diffstat:
Mexamples/thyns/params.h | 1+
Mexamples/thyns/plugin.c | 2+-
Mexamples/thyns/voice.h | 31+++++++++++++++----------------
Mtools/clap-info/clap-info.c | 34+++++++++++++++++++++++++++++++---
4 files changed, 48 insertions(+), 20 deletions(-)

diff --git a/examples/thyns/params.h b/examples/thyns/params.h @@ -20,6 +20,7 @@ thyns_params_init(struct thyns_params *params) thyns_filt_params_init(params->filt); thyns_env_params_init(params->amp_env); thyns_env_params_init(params->filt_env); + thyns_voice_params_init(params->voice); } #endif /* !PARAMS_H */ diff --git a/examples/thyns/plugin.c b/examples/thyns/plugin.c @@ -140,7 +140,7 @@ thyns_params_get(struct clap_plugin *plugin, i += THYNS_ENV_PARAM_COUNT; if (index < i + THYNS_VOICE_PARAM_COUNT) { - thyns_env_param_info(index - i, p->thyns.params.voice[index - i], + thyns_voice_param_info(index - i, p->thyns.params.voice[index - i], "", param); return true; } diff --git a/examples/thyns/voice.h b/examples/thyns/voice.h @@ -13,6 +13,14 @@ enum thyns_voice_param_index THYNS_VOICE_PARAM_COUNT, }; +static inline void +thyns_voice_params_init(union clap_param_value *values) +{ + values[THYNS_VOICE_PARAM_OSC_MIX].f = 0.5; + values[THYNS_VOICE_PARAM_FILT_ENV_DEPTH].f = 0.2; + values[THYNS_VOICE_PARAM_AMP].f = 0.2; +} + # include "params.h" struct thyns_voice @@ -29,16 +37,13 @@ struct thyns_voice // osc part struct thyns_osc osc1; struct thyns_osc osc2; - double osc_mix; // filter struct thyns_filt filt; struct thyns_env filt_env; - double filt_env_depth; // amp struct thyns_env amp_env; - double amp; union clap_param_value *values[THYNS_VOICE_PARAM_COUNT]; @@ -104,14 +109,6 @@ thyns_voice_param_info(uint32_t index, } static inline void -thyns_voice_params_init(union clap_param_value *values) -{ - values[THYNS_VOICE_PARAM_OSC_MIX].f = 0.5; - values[THYNS_VOICE_PARAM_FILT_ENV_DEPTH].f = 0.2; - values[THYNS_VOICE_PARAM_AMP].f = 0.2; -} - -static inline void thyns_voice_init(struct thyns_voice *voice, uint32_t sr) { voice->prev = NULL; @@ -123,7 +120,6 @@ thyns_voice_init(struct thyns_voice *voice, uint32_t sr) // osc thyns_osc_init(&voice->osc1, sr); thyns_osc_init(&voice->osc2, sr); - voice->osc_mix = 0; // filter thyns_filt_init(&voice->filt, sr); @@ -239,12 +235,15 @@ thyns_voice_step(struct thyns_voice *voice) { double osc1 = thyns_osc_step(&voice->osc1); double osc2 = thyns_osc_step(&voice->osc2); - double oscm = osc1 * (1 - voice->osc_mix) + osc2 * voice->osc_mix; - double fenv = thyns_env_step(&voice->filt_env) * voice->filt_env_depth; + double oscm = voice->values[THYNS_VOICE_PARAM_OSC_MIX]->f; + double osc = osc1 * (1 - oscm) + osc2 * oscm; + double fenv = thyns_env_step(&voice->filt_env) * + voice->values[THYNS_VOICE_PARAM_FILT_ENV_DEPTH]->f; double cutoff = exp(log(voice->filt.values[THYNS_FILT_PARAM_CUTOFF]->f) + fenv); - double filtered = thyns_filt_step(&voice->filt, oscm, cutoff, + double filtered = thyns_filt_step(&voice->filt, osc, cutoff, voice->filt.values[THYNS_FILT_PARAM_RESONANCE]->f); - double amp = voice->amp * thyns_env_step(&voice->amp_env); + double amp = voice->values[THYNS_VOICE_PARAM_AMP]->f + * thyns_env_step(&voice->amp_env); return filtered * amp; } diff --git a/tools/clap-info/clap-info.c b/tools/clap-info/clap-info.c @@ -79,10 +79,38 @@ static void print_params(struct clap_plugin *plugin) if (!params->get(plugin, i, &param)) continue; - fprintf(stdout, " => {id: %s, name: %s, desc: %s, display: %s, type: %d, " - "is_per_note: %d, is_used: %d, is_periodic: %d}\n", - param.id, param.name, param.desc, param.display, param.type, + fprintf(stdout, " => {id: %s, name: %s, desc: %s, display: %s, " + "is_per_note: %d, is_used: %d, is_periodic: %d", + param.id, param.name, param.desc, param.display, param.is_per_note, param.is_used, param.is_periodic); + + switch (param.type) { + case CLAP_PARAM_FLOAT: + fprintf(stdout, ", type: float, value: %f, min: %f, max: %f", + param.value.f, param.min.f, param.max.f); + break; + + case CLAP_PARAM_INT: + fprintf(stdout, ", type: int, value: %d, min: %d, max: %d", + param.value.i, param.min.i, param.max.i); + break; + + case CLAP_PARAM_ENUM: + fprintf(stdout, ", type: enum, value: %d, min: %d, max: %d", + param.value.i, param.min.i, param.max.i); + break; + + case CLAP_PARAM_BOOL: + fprintf(stdout, ", type: bool, value: %d, min: %d, max: %d", + param.value.i, param.min.i, param.max.i); + break; + + case CLAP_PARAM_GROUP: + fprintf(stdout, ", type: group"); + break; + } + + fprintf(stdout, "}\n"); } fprintf(stdout, "-------------------\n");