clap

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

commit 57d65789f112ae3cca987777aa4ecfe734a4632f
parent d77c60f1d9b94658f9e7e9e1604649315c38fa69
Author: Alexandre Bique <bique.alexandre@gmail.com>
Date:   Wed, 22 Oct 2014 20:25:59 +0200

Fixes the synth exemple

Diffstat:
Aexamples/thyns/defs.h | 12++++++++++++
Mexamples/thyns/env.h | 2+-
Mexamples/thyns/filt.h | 3+--
Mexamples/thyns/osc.h | 3+--
Mexamples/thyns/thyns.c | 41++++++++++++++++++++++++++++++++++++++---
5 files changed, 53 insertions(+), 8 deletions(-)

diff --git a/examples/thyns/defs.h b/examples/thyns/defs.h @@ -0,0 +1,12 @@ +#ifndef DEFS_H +# define DEFS_H + +# include <string.h> +# include <math.h> +# include <assert.h> + +# ifndef M_PI +# define M_PI 3.14159265358979323846 +# endif + +#endif /* !DEFS_H */ diff --git a/examples/thyns/env.h b/examples/thyns/env.h @@ -1,7 +1,7 @@ #ifndef ENV_H # define ENV_H -# include <assert.h> +# include "defs.h" enum thyns_env_state { diff --git a/examples/thyns/filt.h b/examples/thyns/filt.h @@ -6,8 +6,7 @@ #ifndef FILT_H # define FILT_H -# include <string.h> -# include <math.h> +# include "defs.h" struct thyns_filt { diff --git a/examples/thyns/osc.h b/examples/thyns/osc.h @@ -1,8 +1,7 @@ #ifndef OSC_H # define OSC_H -# include <assert.h> -# include <math.h> +# include "defs.h" enum thyns_osc_type { diff --git a/examples/thyns/thyns.c b/examples/thyns/thyns.c @@ -14,18 +14,53 @@ struct thyns // osc part struct thyns_osc osc1; struct thyns_osc osc2; - float osc_mix; + double osc_mix; // filter struct thyns_filt filt; struct thyns_env filt_env; - float filt_end_depth; + double filt_env_depth; // amp struct thyns_env amp_env; - float amp; + double amp; }; +static void thyns_init(struct thyns *thyns, uint32_t sr) +{ + thyns->sr = sr; + thyns->pi_sr = M_PI / sr; + + // osc + thyns_osc_init(&thyns->osc1); + thyns_osc_init(&thyns->osc2); + thyns->osc_mix = 0; + + // filter + thyns_filt_init(&thyns->filt); + thyns_filt_set_cutoff(&thyns->filt, 1000, thyns->pi_sr); + thyns_env_init(&thyns->filt_env); + thyns->filt_env_depth = 0; + + // amp + thyns_env_init(&thyns->amp_env); + thyns->amp = 0.7; +} + +double thyns_step(struct thyns *thyns) +{ + double osc1 = thyns_osc_step(&thyns->osc1); + double osc2 = thyns_osc_step(&thyns->osc2); + double oscm = osc1 * (1 - thyns->osc_mix) + osc2 * thyns->osc_mix; + + double fenv = thyns_env_step(&thyns->filt_env); + double cutoff = exp(log(thyns->filt.cutoff) + fenv); + thyns_filt_set_cutoff(&thyns->filt, cutoff, thyns->pi_sr); + double filtered = thyns_filt_step(&thyns->filt, oscm); + + return filtered * thyns->amp * thyns_env_step(&thyns->amp_env); +} + struct clap_plugin * clap_create(uint32_t plugin_index, struct clap_host *host,