diff options
author | Michael Sevakis <jethead71@rockbox.org> | 2012-04-30 16:27:01 -0400 |
---|---|---|
committer | Michael Sevakis <jethead71@rockbox.org> | 2012-04-30 22:47:37 +0200 |
commit | 57a20d2d638895fffe88a23cbd2960f1102b292f (patch) | |
tree | df1943429ec040a18d854fa0a0091051e4200304 /lib/rbcodec/dsp | |
parent | a32cbf33465367cd6fe36d636da8d03485e9d15d (diff) |
Make DSP's replaygain independent of global_settings.
Moves replaygain definitions to lib/rbcodec/dsp/dsp_misc.h.
Intermediate functions in misc.c handle any adjustment and calling
the rbcodec APIs.
Change-Id: I9f03561bca9aedd13760cf19c4e19aa3c68e7024
Reviewed-on: http://gerrit.rockbox.org/140
Reviewed-by: Michael Sevakis <jethead71@rockbox.org>
Diffstat (limited to 'lib/rbcodec/dsp')
-rw-r--r-- | lib/rbcodec/dsp/dsp_misc.c | 77 | ||||
-rw-r--r-- | lib/rbcodec/dsp/dsp_misc.h | 20 |
2 files changed, 52 insertions, 45 deletions
diff --git a/lib/rbcodec/dsp/dsp_misc.c b/lib/rbcodec/dsp/dsp_misc.c index a98a7e429e..e8bbeb6f5e 100644 --- a/lib/rbcodec/dsp/dsp_misc.c +++ b/lib/rbcodec/dsp/dsp_misc.c @@ -23,12 +23,16 @@ ****************************************************************************/ #include "config.h" #include "sound.h" -#include "settings.h" #include "fixedpoint.h" #include "replaygain.h" #include "dsp_proc_entry.h" #include "dsp_sample_io.h" #include "dsp_misc.h" +#include "pga.h" +#include "channel_mode.h" +#ifdef HAVE_SW_TONE_CONTROLS +#include "tone_controls.h" +#endif #include <string.h> /** Firmware callback interface **/ @@ -77,43 +81,37 @@ int dsp_callback(int msg, intptr_t param) } /** Replaygain settings **/ -static struct dsp_replay_gains current_rpgains; +static struct replaygain_settings current_settings; +static struct dsp_replay_gains current_gains; -static void dsp_replaygain_update(const struct dsp_replay_gains *gains) +static void dsp_replaygain_update( + const struct replaygain_settings *settings, + const struct dsp_replay_gains *gains) { - if (gains == NULL) - { - /* Use defaults */ - memset(¤t_rpgains, 0, sizeof (current_rpgains)); - gains = ¤t_rpgains; - } - else - { - current_rpgains = *gains; /* Stash settings */ - } + if (settings != ¤t_settings) + current_settings = *settings; /* Stash settings */ + + if (gains != ¤t_gains) + current_gains = *gains; /* Stash gains */ int32_t gain = PGA_UNITY; - if (global_settings.replaygain_type != REPLAYGAIN_OFF || - global_settings.replaygain_noclip) + if (settings->type != REPLAYGAIN_OFF || settings->noclip) { - bool track_mode = - get_replaygain_mode(gains->track_gain != 0, - gains->album_gain != 0) == REPLAYGAIN_TRACK; + bool track_mode = settings->type == REPLAYGAIN_TRACK && + gains->track_gain != 0; int32_t peak = (track_mode || gains->album_peak == 0) ? - gains->track_peak : gains->album_peak; + gains->track_peak : gains->album_peak; - if (global_settings.replaygain_type != REPLAYGAIN_OFF) + if (settings->type != REPLAYGAIN_OFF) { gain = (track_mode || gains->album_gain == 0) ? gains->track_gain : gains->album_gain; - if (global_settings.replaygain_preamp) + if (settings->preamp != 0) { - int32_t preamp = get_replaygain_int( - global_settings.replaygain_preamp * 10); - + int32_t preamp = get_replaygain_int(settings->preamp * 10); gain = fp_mul(gain, preamp, 24); } } @@ -124,7 +122,7 @@ static void dsp_replaygain_update(const struct dsp_replay_gains *gains) gain = PGA_UNITY; } - if (global_settings.replaygain_noclip && peak != 0 && + if (settings->noclip && peak != 0 && fp_mul(gain, peak, 24) >= PGA_UNITY) { gain = fp_div(PGA_UNITY, peak, 24); @@ -135,28 +133,21 @@ static void dsp_replaygain_update(const struct dsp_replay_gains *gains) pga_enable_gain(PGA_REPLAYGAIN, gain != PGA_UNITY); } -int get_replaygain_mode(bool have_track_gain, bool have_album_gain) +void dsp_replaygain_set_settings(const struct replaygain_settings *settings) { - bool track = false; + dsp_replaygain_update(settings, ¤t_gains); +} - switch (global_settings.replaygain_type) +void dsp_replaygain_set_gains(const struct dsp_replay_gains *gains) +{ + if (gains == NULL) { - case REPLAYGAIN_TRACK: - track = true; - break; - - case REPLAYGAIN_SHUFFLE: - track = global_settings.playlist_shuffle; - break; + /* Set defaults */ + gains = ¤t_gains; + memset((void *)gains, 0, sizeof (*gains)); } - return (!track && have_album_gain) ? - REPLAYGAIN_ALBUM : (have_track_gain ? REPLAYGAIN_TRACK : -1); -} - -void dsp_set_replaygain(void) -{ - dsp_replaygain_update(¤t_rpgains); + dsp_replaygain_update(¤t_settings, gains); } @@ -217,7 +208,7 @@ static intptr_t misc_handler_configure(struct dsp_proc_entry *this, #endif value = (intptr_t)NULL; /* Default gains */ case REPLAYGAIN_SET_GAINS: - dsp_replaygain_update((void *)value); + dsp_replaygain_set_gains((void *)value); break; #ifdef HAVE_PITCHSCREEN diff --git a/lib/rbcodec/dsp/dsp_misc.h b/lib/rbcodec/dsp/dsp_misc.h index 74587cbb0e..e0035457f5 100644 --- a/lib/rbcodec/dsp/dsp_misc.h +++ b/lib/rbcodec/dsp/dsp_misc.h @@ -26,6 +26,22 @@ /* Set the tri-pdf dithered output */ void dsp_dither_enable(bool enable); /* in dsp_sample_output.c */ +enum replaygain_types +{ + REPLAYGAIN_TRACK = 0, + REPLAYGAIN_ALBUM, + REPLAYGAIN_SHUFFLE, + REPLAYGAIN_OFF +}; + +struct replaygain_settings +{ + bool noclip; /* scale to prevent clips */ + int type; /* 0=track gain, 1=album gain, 2=track gain if + shuffle is on, album gain otherwise, 4=off */ + int preamp; /* scale replaygained tracks by this */ +}; + /* Structure used with REPLAYGAIN_SET_GAINS message */ #define REPLAYGAIN_SET_GAINS (DSP_PROC_SETTING+DSP_PROC_MISC_HANDLER) struct dsp_replay_gains @@ -36,8 +52,8 @@ struct dsp_replay_gains long album_peak; }; -int get_replaygain_mode(bool have_track_gain, bool have_album_gain); -void dsp_set_replaygain(void); +void dsp_replaygain_set_settings(const struct replaygain_settings *settings); +void dsp_replaygain_set_gains(const struct dsp_replay_gains *gains); #ifdef HAVE_PITCHSCREEN void sound_set_pitch(int32_t ratio); |