1
0
Fork 0
forked from len0rd/rockbox

Consolidate compressor settings into a struct.

Doing that makes things cleaner for later on.

Change-Id: I4e279aa57ace16a348acc0fc09059592325ec95f
This commit is contained in:
Michael Sevakis 2012-04-26 17:19:16 -04:00
parent 97a535d83c
commit 0842d7f7e1
8 changed files with 222 additions and 217 deletions

View file

@ -126,15 +126,20 @@ static int timestretch_callback(int action,const struct menu_item_ex *this_item)
/* compressor submenu */ /* compressor submenu */
MENUITEM_SETTING(compressor_threshold, MENUITEM_SETTING(compressor_threshold,
&global_settings.compressor_threshold, lowlatency_callback); &global_settings.compressor_settings.threshold,
lowlatency_callback);
MENUITEM_SETTING(compressor_gain, MENUITEM_SETTING(compressor_gain,
&global_settings.compressor_makeup_gain, lowlatency_callback); &global_settings.compressor_settings.makeup_gain,
lowlatency_callback);
MENUITEM_SETTING(compressor_ratio, MENUITEM_SETTING(compressor_ratio,
&global_settings.compressor_ratio, lowlatency_callback); &global_settings.compressor_settings.ratio,
lowlatency_callback);
MENUITEM_SETTING(compressor_knee, MENUITEM_SETTING(compressor_knee,
&global_settings.compressor_knee, lowlatency_callback); &global_settings.compressor_settings.knee,
lowlatency_callback);
MENUITEM_SETTING(compressor_release, MENUITEM_SETTING(compressor_release,
&global_settings.compressor_release_time, lowlatency_callback); &global_settings.compressor_settings.release_time,
lowlatency_callback);
MAKE_MENU(compressor_menu,ID2P(LANG_COMPRESSOR), NULL, Icon_NOICON, MAKE_MENU(compressor_menu,ID2P(LANG_COMPRESSOR), NULL, Icon_NOICON,
&compressor_threshold, &compressor_gain, &compressor_ratio, &compressor_threshold, &compressor_gain, &compressor_ratio,
&compressor_knee, &compressor_release); &compressor_knee, &compressor_release);

View file

@ -780,9 +780,6 @@ void settings_apply(bool read_disk)
{ {
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
int rc; int rc;
#endif
#if CONFIG_CODEC == SWCODEC
int i;
#endif #endif
sound_settings_apply(); sound_settings_apply();
@ -991,7 +988,7 @@ void settings_apply(bool read_disk)
/* Configure software equalizer, hardware eq is handled in audio_init() */ /* Configure software equalizer, hardware eq is handled in audio_init() */
dsp_set_eq(global_settings.eq_enabled); dsp_set_eq(global_settings.eq_enabled);
dsp_set_eq_precut(global_settings.eq_precut); dsp_set_eq_precut(global_settings.eq_precut);
for(i = 0; i < 5; i++) { for(int i = 0; i < 5; i++) {
dsp_set_eq_coefs(i); dsp_set_eq_coefs(i);
} }
@ -999,7 +996,7 @@ void settings_apply(bool read_disk)
#ifdef HAVE_PITCHSCREEN #ifdef HAVE_PITCHSCREEN
dsp_timestretch_enable(global_settings.timestretch_enabled); dsp_timestretch_enable(global_settings.timestretch_enabled);
#endif #endif
dsp_set_compressor(); dsp_set_compressor(&global_settings.compressor_settings);
#endif #endif
#ifdef HAVE_SPDIF_POWER #ifdef HAVE_SPDIF_POWER

View file

@ -772,11 +772,14 @@ struct user_settings
#endif #endif
#if CONFIG_CODEC == SWCODEC #if CONFIG_CODEC == SWCODEC
int compressor_threshold; struct compressor_settings
int compressor_makeup_gain; {
int compressor_ratio; int threshold;
int compressor_knee; int makeup_gain;
int compressor_release_time; int ratio;
int knee;
int release_time;
} compressor_settings;
#endif #endif
int sleeptimer_duration; /* In minutes; 0=off */ int sleeptimer_duration; /* In minutes; 0=off */

View file

@ -436,7 +436,7 @@ static void crossfeed_cross_set(int val)
static void compressor_set(int val) static void compressor_set(int val)
{ {
(void)val; (void)val;
dsp_set_compressor(); dsp_set_compressor(&global_settings.compressor_settings);
} }
static const char* db_format(char* buffer, size_t buffer_size, int value, static const char* db_format(char* buffer, size_t buffer_size, int value,
@ -1482,25 +1482,26 @@ const struct settings_list settings[] = {
#endif #endif
/* compressor */ /* compressor */
INT_SETTING_NOWRAP(F_SOUNDSETTING, compressor_threshold, INT_SETTING_NOWRAP(F_SOUNDSETTING, compressor_settings.threshold,
LANG_COMPRESSOR_THRESHOLD, 0, LANG_COMPRESSOR_THRESHOLD, 0,
"compressor threshold", UNIT_DB, 0, -24, "compressor threshold", UNIT_DB, 0, -24,
-3, formatter_unit_0_is_off, getlang_unit_0_is_off, compressor_set), -3, formatter_unit_0_is_off, getlang_unit_0_is_off,
CHOICE_SETTING(F_SOUNDSETTING|F_NO_WRAP, compressor_makeup_gain, compressor_set),
CHOICE_SETTING(F_SOUNDSETTING|F_NO_WRAP, compressor_settings.makeup_gain,
LANG_COMPRESSOR_GAIN, 1, "compressor makeup gain", LANG_COMPRESSOR_GAIN, 1, "compressor makeup gain",
"off,auto", compressor_set, 2, "off,auto", compressor_set, 2,
ID2P(LANG_OFF), ID2P(LANG_AUTO)), ID2P(LANG_OFF), ID2P(LANG_AUTO)),
CHOICE_SETTING(F_SOUNDSETTING|F_NO_WRAP, compressor_ratio, CHOICE_SETTING(F_SOUNDSETTING|F_NO_WRAP, compressor_settings.ratio,
LANG_COMPRESSOR_RATIO, 1, "compressor ratio", LANG_COMPRESSOR_RATIO, 1, "compressor ratio",
"2:1,4:1,6:1,10:1,limit", compressor_set, 5, "2:1,4:1,6:1,10:1,limit", compressor_set, 5,
ID2P(LANG_COMPRESSOR_RATIO_2), ID2P(LANG_COMPRESSOR_RATIO_4), ID2P(LANG_COMPRESSOR_RATIO_2), ID2P(LANG_COMPRESSOR_RATIO_4),
ID2P(LANG_COMPRESSOR_RATIO_6), ID2P(LANG_COMPRESSOR_RATIO_10), ID2P(LANG_COMPRESSOR_RATIO_6), ID2P(LANG_COMPRESSOR_RATIO_10),
ID2P(LANG_COMPRESSOR_RATIO_LIMIT)), ID2P(LANG_COMPRESSOR_RATIO_LIMIT)),
CHOICE_SETTING(F_SOUNDSETTING|F_NO_WRAP, compressor_knee, CHOICE_SETTING(F_SOUNDSETTING|F_NO_WRAP, compressor_settings.knee,
LANG_COMPRESSOR_KNEE, 1, "compressor knee", LANG_COMPRESSOR_KNEE, 1, "compressor knee",
"hard knee,soft knee", compressor_set, 2, "hard knee,soft knee", compressor_set, 2,
ID2P(LANG_COMPRESSOR_HARD_KNEE), ID2P(LANG_COMPRESSOR_SOFT_KNEE)), ID2P(LANG_COMPRESSOR_HARD_KNEE), ID2P(LANG_COMPRESSOR_SOFT_KNEE)),
INT_SETTING_NOWRAP(F_SOUNDSETTING, compressor_release_time, INT_SETTING_NOWRAP(F_SOUNDSETTING, compressor_settings.release_time,
LANG_COMPRESSOR_RELEASE, 500, LANG_COMPRESSOR_RELEASE, 500,
"compressor release time", UNIT_MS, 100, 1000, "compressor release time", UNIT_MS, 100, 1000,
100, NULL, NULL, compressor_set), 100, NULL, NULL, compressor_set),

View file

@ -29,6 +29,8 @@
/*#define LOGF_ENABLE*/ /*#define LOGF_ENABLE*/
#include "logf.h" #include "logf.h"
static struct compressor_settings curr_set; /* Cached settings */
static int32_t comp_rel_slope IBSS_ATTR; /* S7.24 format */ static int32_t comp_rel_slope IBSS_ATTR; /* S7.24 format */
static int32_t comp_makeup_gain IBSS_ATTR; /* S7.24 format */ static int32_t comp_makeup_gain IBSS_ATTR; /* S7.24 format */
static int32_t comp_curve[66] IBSS_ATTR; /* S7.24 format */ static int32_t comp_curve[66] IBSS_ATTR; /* S7.24 format */
@ -38,64 +40,62 @@ static int32_t release_gain IBSS_ATTR; /* S7.24 format */
/** COMPRESSOR UPDATE /** COMPRESSOR UPDATE
* Called via the menu system to configure the compressor process */ * Called via the menu system to configure the compressor process */
bool compressor_update(void) bool compressor_update(const struct compressor_settings *settings)
{ {
static int curr_set[5]; /* make settings values useful */
int new_set[5] = { int threshold = settings->threshold;
global_settings.compressor_threshold, bool auto_gain = settings->makeup_gain == 1;
global_settings.compressor_makeup_gain, static const int comp_ratios[] = { 2, 4, 6, 10, 0 };
global_settings.compressor_ratio, int ratio = comp_ratios[settings->ratio];
global_settings.compressor_knee, bool soft_knee = settings->knee == 1;
global_settings.compressor_release_time}; int release = settings->release_time * NATIVE_FREQUENCY / 1000;
/* make menu values useful */
int threshold = new_set[0];
bool auto_gain = (new_set[1] == 1);
const int comp_ratios[] = {2, 4, 6, 10, 0};
int ratio = comp_ratios[new_set[2]];
bool soft_knee = (new_set[3] == 1);
int release = new_set[4] * NATIVE_FREQUENCY / 1000;
bool changed = false; bool changed = false;
bool active = (threshold < 0); bool active = threshold < 0;
for (int i = 0; i < 5; i++) if (memcmp(settings, &curr_set, sizeof (curr_set)))
{
if (curr_set[i] != new_set[i])
{ {
/* Compressor settings have changed since last call */
changed = true; changed = true;
curr_set[i] = new_set[i];
#if defined(ROCKBOX_HAS_LOGF) && defined(LOGF_ENABLE) #if defined(ROCKBOX_HAS_LOGF) && defined(LOGF_ENABLE)
switch (i) if (settings->threshold != curr_set.threshold)
{ {
case 0:
logf(" Compressor Threshold: %d dB\tEnabled: %s", logf(" Compressor Threshold: %d dB\tEnabled: %s",
threshold, active ? "Yes" : "No"); threshold, active ? "Yes" : "No");
break; }
case 1:
if (settings->makeup_gain != curr_set.makeup_gain)
{
logf(" Compressor Makeup Gain: %s", logf(" Compressor Makeup Gain: %s",
auto_gain ? "Auto" : "Off"); auto_gain ? "Auto" : "Off");
break; }
case 2:
if (settings->ratio != cur_set.ratio)
{
if (ratio) if (ratio)
{ logf(" Compressor Ratio: %d:1", ratio); } { logf(" Compressor Ratio: %d:1", ratio); }
else else
{ logf(" Compressor Ratio: Limit"); } { logf(" Compressor Ratio: Limit"); }
break;
case 3:
logf(" Compressor Knee: %s", soft_knee?"Soft":"Hard");
break;
case 4:
logf(" Compressor Release: %d", release);
break;
}
#endif
}
} }
if (changed && active) if (settings->knee != cur_set.knee)
{ {
logf(" Compressor Knee: %s", soft_knee?"Soft":"Hard");
}
if (settings->release_time != cur_set.release_time)
{
logf(" Compressor Release: %d", release);
}
#endif
curr_set = *settings;
}
if (!changed || !active)
return active;
/* configure variables for compressor operation */ /* configure variables for compressor operation */
static const int32_t db[] = { static const int32_t db[] = {
/* positive db equivalents in S15.16 format */ /* positive db equivalents in S15.16 format */
@ -244,8 +244,6 @@ bool compressor_update(void)
logf("Release slope:\t%.6f", (float)comp_rel_slope / UNITY); logf("Release slope:\t%.6f", (float)comp_rel_slope / UNITY);
release_gain = UNITY; release_gain = UNITY;
}
return active; return active;
} }

View file

@ -23,7 +23,7 @@
#define COMPRESSOR_H #define COMPRESSOR_H
void compressor_process(int count, struct dsp_data *data, int32_t *buf[]); void compressor_process(int count, struct dsp_data *data, int32_t *buf[]);
bool compressor_update(void); bool compressor_update(const struct compressor_settings *settings);
void compressor_reset(void); void compressor_reset(void);
#endif /* COMPRESSOR_H */ #endif /* COMPRESSOR_H */

View file

@ -1565,9 +1565,9 @@ void dsp_set_replaygain(void)
/** SET COMPRESSOR /** SET COMPRESSOR
* Called by the menu system to configure the compressor process */ * Called by the menu system to configure the compressor process */
void dsp_set_compressor(void) void dsp_set_compressor(const struct compressor_settings *settings)
{ {
/* enable/disable the compressor */ /* enable/disable the compressor */
AUDIO_DSP.compressor_process = compressor_update() ? AUDIO_DSP.compressor_process = compressor_update(settings) ?
compressor_process : NULL; compressor_process : NULL;
} }

View file

@ -120,6 +120,7 @@ int32_t sound_get_pitch(void);
void dsp_set_timestretch(int32_t percent); void dsp_set_timestretch(int32_t percent);
int32_t dsp_get_timestretch(void); int32_t dsp_get_timestretch(void);
int dsp_callback(int msg, intptr_t param); int dsp_callback(int msg, intptr_t param);
void dsp_set_compressor(void); struct compressor_settings;
void dsp_set_compressor(const struct compressor_settings *settings);
#endif #endif