summaryrefslogtreecommitdiff
path: root/apps/dsp.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dsp.c')
-rw-r--r--apps/dsp.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/apps/dsp.c b/apps/dsp.c
index 21effc5da3..701ffb4e55 100644
--- a/apps/dsp.c
+++ b/apps/dsp.c
@@ -23,13 +23,14 @@
23#include "playback.h" 23#include "playback.h"
24#include "system.h" 24#include "system.h"
25#include "settings.h" 25#include "settings.h"
26#include "replaygain.h"
26#include "debug.h" 27#include "debug.h"
27 28
28/* The "dither" code to convert the 24-bit samples produced by libmad was 29/* The "dither" code to convert the 24-bit samples produced by libmad was
29 * taken from the coolplayer project - coolplayer.sourceforge.net 30 * taken from the coolplayer project - coolplayer.sourceforge.net
30 */ 31 */
31 32
32/* 16-bit samples are scaled based on these constants. The shift should be 33/* 16-bit samples are scaled based on these constants. The shift should be
33 * no more than 15. 34 * no more than 15.
34 */ 35 */
35#define WORD_SHIFT 12 36#define WORD_SHIFT 12
@@ -336,7 +337,7 @@ static inline long clip_sample(long sample)
336 return sample; 337 return sample;
337} 338}
338 339
339/* The "dither" code to convert the 24-bit samples produced by libmad was 340/* The "dither" code to convert the 24-bit samples produced by libmad was
340 * taken from the coolplayer project - coolplayer.sourceforge.net 341 * taken from the coolplayer project - coolplayer.sourceforge.net
341 */ 342 */
342 343
@@ -386,15 +387,15 @@ static void apply_gain(long* src[], int count)
386 long* d1 = (s0 == s1) ? d0 : &sample_buf[SAMPLE_BUF_SIZE / 2]; 387 long* d1 = (s0 == s1) ? d0 : &sample_buf[SAMPLE_BUF_SIZE / 2];
387 long gain = dsp.replaygain; 388 long gain = dsp.replaygain;
388 long i; 389 long i;
389 390
390 src[0] = d0; 391 src[0] = d0;
391 src[1] = d1; 392 src[1] = d1;
392 393
393 for (i = 0; i < count; i++) 394 for (i = 0; i < count; i++)
394 { 395 {
395 *d0++ = FRACMUL_8(*s0++, gain); 396 *d0++ = FRACMUL_8(*s0++, gain);
396 } 397 }
397 398
398 if (src [0] != src [1]) 399 if (src [0] != src [1])
399 { 400 {
400 for (i = 0; i < count; i++) 401 for (i = 0; i < count; i++)
@@ -639,7 +640,7 @@ void dsp_set_replaygain(bool always)
639 long gain = 0; 640 long gain = 0;
640 641
641 dsp.new_gain = false; 642 dsp.new_gain = false;
642 643
643 if (global_settings.replaygain || global_settings.replaygain_noclip) 644 if (global_settings.replaygain || global_settings.replaygain_noclip)
644 { 645 {
645 long peak; 646 long peak;
@@ -648,28 +649,36 @@ void dsp_set_replaygain(bool always)
648 { 649 {
649 gain = (global_settings.replaygain_track || !dsp.album_gain) 650 gain = (global_settings.replaygain_track || !dsp.album_gain)
650 ? dsp.track_gain : dsp.album_gain; 651 ? dsp.track_gain : dsp.album_gain;
652
653 if (global_settings.replaygain_preamp)
654 {
655 long preamp = get_replaygain_int(
656 global_settings.replaygain_preamp * 10);
657
658 gain = (long) ((((int64_t) gain * preamp)) >> 24);
659 }
651 } 660 }
652 661
653 peak = (global_settings.replaygain_track || !dsp.album_peak) 662 peak = (global_settings.replaygain_track || !dsp.album_peak)
654 ? dsp.track_peak : dsp.album_peak; 663 ? dsp.track_peak : dsp.album_peak;
655 664
656 if (gain == 0) 665 if (gain == 0)
657 { 666 {
658 /* So that noclip can work even with no gain information. */ 667 /* So that noclip can work even with no gain information. */
659 gain = DEFAULT_REPLAYGAIN; 668 gain = DEFAULT_REPLAYGAIN;
660 } 669 }
661 670
662 if (global_settings.replaygain_noclip && (peak != 0) 671 if (global_settings.replaygain_noclip && (peak != 0)
663 && ((((int64_t) gain * peak) >> 24) >= DEFAULT_REPLAYGAIN)) 672 && ((((int64_t) gain * peak) >> 24) >= DEFAULT_REPLAYGAIN))
664 { 673 {
665 gain = (((int64_t) DEFAULT_REPLAYGAIN << 24) / peak); 674 gain = (((int64_t) DEFAULT_REPLAYGAIN << 24) / peak);
666 } 675 }
667 676
668 if (gain == DEFAULT_REPLAYGAIN) 677 if (gain == DEFAULT_REPLAYGAIN)
669 { 678 {
670 /* Nothing to do, disable processing. */ 679 /* Nothing to do, disable processing. */
671 gain = 0; 680 gain = 0;
672 681
673 } 682 }
674 } 683 }
675 684