
/* Code automatically generated by Vult https://github.com/modlfo/vult */
#ifndef FILTER_H
#define FILTER_H
#include <stdint.h>
#include <math.h>
#include "vultin.h"
#include "filter.tables.h"

static_inline float Filter_tanh_table_raw_c0(int index){
   return Filter_tanh_table_c0[index];
};

static_inline float Filter_tanh_table_raw_c1(int index){
   return Filter_tanh_table_c1[index];
};

static_inline float Filter_tanh_table_raw_c2(int index){
   return Filter_tanh_table_c2[index];
};

static_inline float Filter_tanh_table(float z){
   int index;
   index = int_clip(float_to_int((5.f * (24.f + z))),0,240);
   return (float_wrap_array(Filter_tanh_table_c0)[index] + (z * (float_wrap_array(Filter_tanh_table_c1)[index] + (z * float_wrap_array(Filter_tanh_table_c2)[index]))));
}

static_inline float Filter_cvToPitch(float cv){
   return (24.f + (120.f * cv));
};

typedef struct Filter__ctx_type_5 {
   float pre_x;
} Filter__ctx_type_5;

typedef Filter__ctx_type_5 Filter_change_type;

static_inline void Filter__ctx_type_5_init(Filter__ctx_type_5 &_output_){
   Filter__ctx_type_5 _ctx;
   _ctx.pre_x = 0.0f;
   _output_ = _ctx;
   return ;
}

static_inline void Filter_change_init(Filter__ctx_type_5 &_output_){
   Filter__ctx_type_5_init(_output_);
   return ;
}

static_inline uint8_t Filter_change(Filter__ctx_type_5 &_ctx, float x){
   uint8_t v;
   v = (_ctx.pre_x != x);
   _ctx.pre_x = x;
   return v;
}

float Filter_calc_g(float cv, float sr);

typedef struct Filter__ctx_type_7 {
   float z2;
   float z1;
   float inv_den;
   float g;
   Filter__ctx_type_5 _inst6;
   Filter__ctx_type_5 _inst5;
   float R;
} Filter__ctx_type_7;

typedef Filter__ctx_type_7 Filter_process_type;

void Filter__ctx_type_7_init(Filter__ctx_type_7 &_output_);

static_inline void Filter_process_init(Filter__ctx_type_7 &_output_){
   Filter__ctx_type_7_init(_output_);
   return ;
}

float Filter_process(Filter__ctx_type_7 &_ctx, float x, float cv, float q, int sel, float sr);



#endif // FILTER_H
