summaryrefslogtreecommitdiff
path: root/lib/rbcodec/dsp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbcodec/dsp')
-rw-r--r--lib/rbcodec/dsp/dsp_misc.c77
-rw-r--r--lib/rbcodec/dsp/dsp_misc.h20
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 @@
23 ****************************************************************************/ 23 ****************************************************************************/
24#include "config.h" 24#include "config.h"
25#include "sound.h" 25#include "sound.h"
26#include "settings.h"
27#include "fixedpoint.h" 26#include "fixedpoint.h"
28#include "replaygain.h" 27#include "replaygain.h"
29#include "dsp_proc_entry.h" 28#include "dsp_proc_entry.h"
30#include "dsp_sample_io.h" 29#include "dsp_sample_io.h"
31#include "dsp_misc.h" 30#include "dsp_misc.h"
31#include "pga.h"
32#include "channel_mode.h"
33#ifdef HAVE_SW_TONE_CONTROLS
34#include "tone_controls.h"
35#endif
32#include <string.h> 36#include <string.h>
33 37
34/** Firmware callback interface **/ 38/** Firmware callback interface **/
@@ -77,43 +81,37 @@ int dsp_callback(int msg, intptr_t param)
77} 81}
78 82
79/** Replaygain settings **/ 83/** Replaygain settings **/
80static struct dsp_replay_gains current_rpgains; 84static struct replaygain_settings current_settings;
85static struct dsp_replay_gains current_gains;
81 86
82static void dsp_replaygain_update(const struct dsp_replay_gains *gains) 87static void dsp_replaygain_update(
88 const struct replaygain_settings *settings,
89 const struct dsp_replay_gains *gains)
83{ 90{
84 if (gains == NULL) 91 if (settings != &current_settings)
85 { 92 current_settings = *settings; /* Stash settings */
86 /* Use defaults */ 93
87 memset(&current_rpgains, 0, sizeof (current_rpgains)); 94 if (gains != &current_gains)
88 gains = &current_rpgains; 95 current_gains = *gains; /* Stash gains */
89 }
90 else
91 {
92 current_rpgains = *gains; /* Stash settings */
93 }
94 96
95 int32_t gain = PGA_UNITY; 97 int32_t gain = PGA_UNITY;
96 98
97 if (global_settings.replaygain_type != REPLAYGAIN_OFF || 99 if (settings->type != REPLAYGAIN_OFF || settings->noclip)
98 global_settings.replaygain_noclip)
99 { 100 {
100 bool track_mode = 101 bool track_mode = settings->type == REPLAYGAIN_TRACK &&
101 get_replaygain_mode(gains->track_gain != 0, 102 gains->track_gain != 0;
102 gains->album_gain != 0) == REPLAYGAIN_TRACK;
103 103
104 int32_t peak = (track_mode || gains->album_peak == 0) ? 104 int32_t peak = (track_mode || gains->album_peak == 0) ?
105 gains->track_peak : gains->album_peak; 105 gains->track_peak : gains->album_peak;
106 106
107 if (global_settings.replaygain_type != REPLAYGAIN_OFF) 107 if (settings->type != REPLAYGAIN_OFF)
108 { 108 {
109 gain = (track_mode || gains->album_gain == 0) ? 109 gain = (track_mode || gains->album_gain == 0) ?
110 gains->track_gain : gains->album_gain; 110 gains->track_gain : gains->album_gain;
111 111
112 if (global_settings.replaygain_preamp) 112 if (settings->preamp != 0)
113 { 113 {
114 int32_t preamp = get_replaygain_int( 114 int32_t preamp = get_replaygain_int(settings->preamp * 10);
115 global_settings.replaygain_preamp * 10);
116
117 gain = fp_mul(gain, preamp, 24); 115 gain = fp_mul(gain, preamp, 24);
118 } 116 }
119 } 117 }
@@ -124,7 +122,7 @@ static void dsp_replaygain_update(const struct dsp_replay_gains *gains)
124 gain = PGA_UNITY; 122 gain = PGA_UNITY;
125 } 123 }
126 124
127 if (global_settings.replaygain_noclip && peak != 0 && 125 if (settings->noclip && peak != 0 &&
128 fp_mul(gain, peak, 24) >= PGA_UNITY) 126 fp_mul(gain, peak, 24) >= PGA_UNITY)
129 { 127 {
130 gain = fp_div(PGA_UNITY, peak, 24); 128 gain = fp_div(PGA_UNITY, peak, 24);
@@ -135,28 +133,21 @@ static void dsp_replaygain_update(const struct dsp_replay_gains *gains)
135 pga_enable_gain(PGA_REPLAYGAIN, gain != PGA_UNITY); 133 pga_enable_gain(PGA_REPLAYGAIN, gain != PGA_UNITY);
136} 134}
137 135
138int get_replaygain_mode(bool have_track_gain, bool have_album_gain) 136void dsp_replaygain_set_settings(const struct replaygain_settings *settings)
139{ 137{
140 bool track = false; 138 dsp_replaygain_update(settings, &current_gains);
139}
141 140
142 switch (global_settings.replaygain_type) 141void dsp_replaygain_set_gains(const struct dsp_replay_gains *gains)
142{
143 if (gains == NULL)
143 { 144 {
144 case REPLAYGAIN_TRACK: 145 /* Set defaults */
145 track = true; 146 gains = &current_gains;
146 break; 147 memset((void *)gains, 0, sizeof (*gains));
147
148 case REPLAYGAIN_SHUFFLE:
149 track = global_settings.playlist_shuffle;
150 break;
151 } 148 }
152 149
153 return (!track && have_album_gain) ? 150 dsp_replaygain_update(&current_settings, gains);
154 REPLAYGAIN_ALBUM : (have_track_gain ? REPLAYGAIN_TRACK : -1);
155}
156
157void dsp_set_replaygain(void)
158{
159 dsp_replaygain_update(&current_rpgains);
160} 151}
161 152
162 153
@@ -217,7 +208,7 @@ static intptr_t misc_handler_configure(struct dsp_proc_entry *this,
217#endif 208#endif
218 value = (intptr_t)NULL; /* Default gains */ 209 value = (intptr_t)NULL; /* Default gains */
219 case REPLAYGAIN_SET_GAINS: 210 case REPLAYGAIN_SET_GAINS:
220 dsp_replaygain_update((void *)value); 211 dsp_replaygain_set_gains((void *)value);
221 break; 212 break;
222 213
223#ifdef HAVE_PITCHSCREEN 214#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 @@
26/* Set the tri-pdf dithered output */ 26/* Set the tri-pdf dithered output */
27void dsp_dither_enable(bool enable); /* in dsp_sample_output.c */ 27void dsp_dither_enable(bool enable); /* in dsp_sample_output.c */
28 28
29enum replaygain_types
30{
31 REPLAYGAIN_TRACK = 0,
32 REPLAYGAIN_ALBUM,
33 REPLAYGAIN_SHUFFLE,
34 REPLAYGAIN_OFF
35};
36
37struct replaygain_settings
38{
39 bool noclip; /* scale to prevent clips */
40 int type; /* 0=track gain, 1=album gain, 2=track gain if
41 shuffle is on, album gain otherwise, 4=off */
42 int preamp; /* scale replaygained tracks by this */
43};
44
29/* Structure used with REPLAYGAIN_SET_GAINS message */ 45/* Structure used with REPLAYGAIN_SET_GAINS message */
30#define REPLAYGAIN_SET_GAINS (DSP_PROC_SETTING+DSP_PROC_MISC_HANDLER) 46#define REPLAYGAIN_SET_GAINS (DSP_PROC_SETTING+DSP_PROC_MISC_HANDLER)
31struct dsp_replay_gains 47struct dsp_replay_gains
@@ -36,8 +52,8 @@ struct dsp_replay_gains
36 long album_peak; 52 long album_peak;
37}; 53};
38 54
39int get_replaygain_mode(bool have_track_gain, bool have_album_gain); 55void dsp_replaygain_set_settings(const struct replaygain_settings *settings);
40void dsp_set_replaygain(void); 56void dsp_replaygain_set_gains(const struct dsp_replay_gains *gains);
41 57
42#ifdef HAVE_PITCHSCREEN 58#ifdef HAVE_PITCHSCREEN
43void sound_set_pitch(int32_t ratio); 59void sound_set_pitch(int32_t ratio);