From eef7400dc4c55adf166a09142d859900d537c803 Mon Sep 17 00:00:00 2001 From: Alexey Yakovenko Date: Sat, 20 Mar 2010 19:01:38 +0100 Subject: moved eq reconfiguration to separate thread --- plugins/supereq/supereq.c | 47 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) (limited to 'plugins/supereq') diff --git a/plugins/supereq/supereq.c b/plugins/supereq/supereq.c index d3509312..f9f98940 100644 --- a/plugins/supereq/supereq.c +++ b/plugins/supereq/supereq.c @@ -29,40 +29,73 @@ void equ_clearbuf(int bps,int srate); void equ_init(int wb); void equ_quit(void); -float last_srate = 0; -int last_nch = 0, last_bps = 0; -float lbands[18] = {1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0}; -float rbands[18] = {1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0}; -void *paramsroot; +static float last_srate = 0; +static int last_nch = 0, last_bps = 0; +static float lbands[18] = {1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0}; +static float rbands[18] = {1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0}; +static void *paramsroot; + +static int params_changed = 0; +static intptr_t tid = 0; +static uintptr_t mutex = 0; int supereq_plugin_start (void) { equ_init (14); paramsroot = paramlist_alloc (); + last_srate = 44100; + last_nch = 2; + last_bps = 16; + equ_makeTable (lbands, rbands, paramsroot, last_srate); + equ_clearbuf (last_bps,last_srate); + mutex = deadbeef->mutex_create (); return 0; } int supereq_plugin_stop (void) { + if (tid) { + deadbeef->thread_join (tid); + deadbeef->mutex_free (mutex); + mutex = 0; + } equ_quit (); paramlist_free (paramsroot); return 0; } +void +supereq_regen_table_thread (void *param) { + void *params = paramlist_alloc (); + deadbeef->mutex_lock (mutex); + equ_makeTable (lbands, rbands, params, last_srate); + paramlist_free (paramsroot); + paramsroot = params; + deadbeef->mutex_unlock (mutex); + tid = 0; +} int supereq_process_int16 (int16_t *samples, int nsamples, int nch, int bps, int srate) { if ((nch != 1 && nch != 2) || (bps != 8 && bps != 16 && bps != 24)) return nsamples; + if (params_changed && !tid) { + tid = deadbeef->thread_start (supereq_regen_table_thread, NULL); + params_changed = 0; + } if (last_srate != srate) { + deadbeef->mutex_lock (mutex); equ_makeTable (lbands, rbands, paramsroot, srate); last_srate = srate; last_nch = nch; last_bps = bps; + deadbeef->mutex_unlock (mutex); equ_clearbuf(bps,srate); } else if (last_nch != nch || last_bps != bps) { + deadbeef->mutex_lock (mutex); last_nch = nch; last_bps = bps; + deadbeef->mutex_unlock (mutex); equ_clearbuf(bps,srate); } equ_modifySamples((char *)samples,nsamples,nch,bps); @@ -76,8 +109,10 @@ supereq_get_band (int band) { void supereq_set_band (int band, float value) { - last_srate = 0; + deadbeef->mutex_lock (mutex); lbands[band] = rbands[band] = value; + deadbeef->mutex_unlock (mutex); + params_changed = 1; } static DB_supereq_dsp_t plugin = { -- cgit v1.2.3