Skip to content

Commit

Permalink
add DBG_FILTER macro
Browse files Browse the repository at this point in the history
  • Loading branch information
derselbst committed Nov 16, 2024
1 parent 916cebb commit 5a2c084
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
14 changes: 9 additions & 5 deletions src/rvoice/fluid_iir_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ fluid_iir_filter_apply(fluid_iir_filter_t *iir_filter,
iir_filter->last_q += iir_filter->q_incr;
}

FLUID_LOG(FLUID_DBG, "last_fres: %.2f Hz | target_fres: %.2f Hz |---| last_q: %.4f | target_q: %.4f", iir_filter->last_fres, iir_filter->target_fres, iir_filter->last_q, iir_filter->target_q);
LOG_FILTER("last_fres: %.2f Hz | target_fres: %.2f Hz |---| last_q: %.4f | target_q: %.4f", iir_filter->last_fres, iir_filter->target_fres, iir_filter->last_q, iir_filter->target_q);

fluid_iir_filter_calculate_coefficients(iir_filter, output_rate);

Expand Down Expand Up @@ -174,7 +174,7 @@ DECLARE_FLUID_RVOICE_FUNCTION(fluid_iir_filter_set_fres)

iir_filter->fres = fres;

FLUID_LOG(FLUID_DBG, "fluid_iir_filter_set_fres: fres= %f [acents]",fres);
LOG_FILTER("fluid_iir_filter_set_fres: fres= %f [acents]",fres);
}

static fluid_real_t fluid_iir_filter_q_from_dB(fluid_real_t q_dB)
Expand Down Expand Up @@ -214,7 +214,7 @@ DECLARE_FLUID_RVOICE_FUNCTION(fluid_iir_filter_set_q)
fluid_real_t q = param[0].real;
int flags = iir_filter->flags;

FLUID_LOG(FLUID_DBG, "fluid_iir_filter_set_q: Q= %f [dB]",q);
LOG_FILTER("fluid_iir_filter_set_q: Q= %f [dB]",q);

if(flags & FLUID_IIR_Q_ZERO_OFF && q <= 0.0)
{
Expand All @@ -233,7 +233,7 @@ DECLARE_FLUID_RVOICE_FUNCTION(fluid_iir_filter_set_q)
q = fluid_iir_filter_q_from_dB(q);
}

FLUID_LOG(FLUID_DBG, "fluid_iir_filter_set_q: Q= %f [linear]",q);
LOG_FILTER("fluid_iir_filter_set_q: Q= %f [linear]",q);

if(iir_filter->filter_startup)
{
Expand All @@ -245,7 +245,9 @@ DECLARE_FLUID_RVOICE_FUNCTION(fluid_iir_filter_set_q)
iir_filter->q_incr = (q - iir_filter->last_q) / (q_incr_count);
iir_filter->q_incr_count = q_incr_count;
}
#ifdef DBG_FILTER
iir_filter->target_q = q;
#endif
}

static FLUID_INLINE void
Expand Down Expand Up @@ -376,7 +378,7 @@ void fluid_iir_filter_calc(fluid_iir_filter_t *iir_filter,
fres = 5.f;
}

FLUID_LOG(FLUID_DBG, "%f + %f = %f cents = %f Hz | Q: %f", iir_filter->fres, fres_mod, iir_filter->fres + fres_mod, fres, iir_filter->last_q);
LOG_FILTER("%f + %f = %f cents = %f Hz | Q: %f", iir_filter->fres, fres_mod, iir_filter->fres + fres_mod, fres, iir_filter->last_q);

/* if filter enabled and there is a significant frequency change.. */
fres_diff = fres - iir_filter->last_fres;
Expand All @@ -399,7 +401,9 @@ void fluid_iir_filter_calc(fluid_iir_filter_t *iir_filter,
fres_incr_count *= num_buffers;
iir_filter->fres_incr = fres_diff / (fres_incr_count);
iir_filter->fres_incr_count = fres_incr_count;
#ifdef DBG_FILTER
iir_filter->target_fres = fres;
#endif

// The filter coefficients have to be recalculated (filter cutoff has changed).
calc_coeff_flag = TRUE;
Expand Down
13 changes: 11 additions & 2 deletions src/rvoice/fluid_iir_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@

#include "fluidsynth_priv.h"

#define DBG_FILTER
#ifdef DBG_FILTER
#define LOG_FILTER(...) FLUID_LOG(FLUID_DBG, __VA_ARGS__)
#else
#define LOG_FILTER(...)
#endif

typedef struct _fluid_iir_filter_t fluid_iir_filter_t;

DECLARE_FLUID_RVOICE_FUNCTION(fluid_iir_filter_init);
Expand Down Expand Up @@ -58,14 +65,16 @@ struct _fluid_iir_filter_t

fluid_real_t fres; /* The desired resonance frequency, in absolute cents, this filter is currently set to */
fluid_real_t last_fres; /* The filter's current (smoothed out) resonance frequency in Hz, which will converge towards its target fres once fres_incr_count has become zero */
fluid_real_t target_fres; /* The filter's target fres, that last_fres should converge towards - for debugging only */
fluid_real_t fres_incr; /* The linear increment of fres each sample */
int fres_incr_count; /* The number of samples left for the smoothed last_fres adjustment to complete */

fluid_real_t last_q; /* The filter's current (smoothed) Q-factor (or "bandwidth", or "resonance-friendlyness") on a linear scale. Just like fres, this will converge towards its target Q once q_incr_count has become zero. */
fluid_real_t target_q; /* The filter's target Q - for debugging only */
fluid_real_t q_incr; /* The linear increment of q each sample */
int q_incr_count; /* The number of samples left for the smoothed Q adjustment to complete */
#ifdef DBG_FILTER
fluid_real_t target_fres; /* The filter's target fres, that last_fres should converge towards - for debugging only */
fluid_real_t target_q; /* The filter's target Q - for debugging only */
#endif
};

#endif
Expand Down

0 comments on commit 5a2c084

Please sign in to comment.