summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/dsp.c118
1 files changed, 66 insertions, 52 deletions
diff --git a/apps/dsp.c b/apps/dsp.c
index 0ef5e0ebf6..4ea2a0c3c4 100644
--- a/apps/dsp.c
+++ b/apps/dsp.c
@@ -45,7 +45,7 @@
45#define NATIVE_DEPTH 16 45#define NATIVE_DEPTH 16
46#define SAMPLE_BUF_SIZE 256 46#define SAMPLE_BUF_SIZE 256
47#define RESAMPLE_BUF_SIZE (256 * 4) /* Enough for 11,025 Hz -> 44,100 Hz*/ 47#define RESAMPLE_BUF_SIZE (256 * 4) /* Enough for 11,025 Hz -> 44,100 Hz*/
48#define DEFAULT_REPLAYGAIN 0x01000000 48#define DEFAULT_GAIN 0x01000000
49 49
50#if defined(CPU_COLDFIRE) && !defined(SIMULATOR) 50#if defined(CPU_COLDFIRE) && !defined(SIMULATOR)
51 51
@@ -174,7 +174,7 @@ struct dsp_config
174 long album_gain; 174 long album_gain;
175 long track_peak; 175 long track_peak;
176 long album_peak; 176 long album_peak;
177 long replaygain; /* Note that this is in S8.23 format. */ 177 long replaygain;
178 int sample_depth; 178 int sample_depth;
179 int sample_bytes; 179 int sample_bytes;
180 int stereo_mode; 180 int stereo_mode;
@@ -183,7 +183,8 @@ struct dsp_config
183 bool new_gain; 183 bool new_gain;
184 bool crossfeed_enabled; 184 bool crossfeed_enabled;
185 bool eq_enabled; 185 bool eq_enabled;
186 long eq_precut; /* Note that this is in S8.23 format. */ 186 long eq_precut;
187 long gain; /* Note that this is in S8.23 format. */
187}; 188};
188 189
189struct resample_data 190struct resample_data
@@ -589,6 +590,31 @@ void apply_crossfeed(int32_t* src[], int count)
589} 590}
590#endif 591#endif
591 592
593/* Combine all gains to a global gain. */
594static void set_gain(void)
595{
596 dsp->gain = DEFAULT_GAIN;
597
598 if (dsp->replaygain)
599 {
600 dsp->gain = dsp->replaygain;
601 }
602
603 if (dsp->eq_enabled && dsp->eq_precut)
604 {
605 dsp->gain = (long) (((int64_t) dsp->gain * dsp->eq_precut) >> 24);
606 }
607
608 if (dsp->gain == DEFAULT_GAIN)
609 {
610 dsp->gain = 0;
611 }
612 else
613 {
614 dsp->gain >>= 1;
615 }
616}
617
592/** 618/**
593 * Use to enable the equalizer. 619 * Use to enable the equalizer.
594 * 620 *
@@ -606,8 +632,8 @@ void dsp_set_eq(bool enable)
606 */ 632 */
607void dsp_set_eq_precut(int precut) 633void dsp_set_eq_precut(int precut)
608{ 634{
609 /* Needs to be in s8.23 format amplitude for apply_gain() */ 635 dsp->eq_precut = get_replaygain_int(precut * -10);
610 dsp->eq_precut = get_replaygain_int(precut * -10) >> 1; 636 set_gain();
611} 637}
612 638
613/** 639/**
@@ -678,51 +704,38 @@ static void eq_process(int32_t **x, unsigned num)
678 */ 704 */
679static void apply_gain(int32_t* _src[], int _count) 705static void apply_gain(int32_t* _src[], int _count)
680{ 706{
681 int32_t** src = _src; 707 if (dsp->gain)
682 int count = _count;
683 int32_t* s0 = src[0];
684 int32_t* s1 = src[1];
685 long gain = 0;
686 int32_t s;
687 int i;
688 int32_t *d;
689
690 if (dsp->replaygain)
691 {
692 gain = dsp->replaygain;
693 }
694
695 if (dsp->eq_enabled)
696 { 708 {
697 gain += dsp->eq_precut; /* FIXME: This isn't that easy right? */ 709 int32_t** src = _src;
698 } 710 int count = _count;
699 711 int32_t* s0 = src[0];
700 /* Don't bother if the gain is zero */ 712 int32_t* s1 = src[1];
701 if (gain == 0) 713 long gain = dsp->gain;
702 { 714 int32_t s;
703 return; 715 int i;
704 } 716 int32_t *d;
705 717
706 if (s0 != s1) 718 if (s0 != s1)
707 { 719 {
708 d = &sample_buf[SAMPLE_BUF_SIZE / 2]; 720 d = &sample_buf[SAMPLE_BUF_SIZE / 2];
709 src[1] = d; 721 src[1] = d;
710 s = *s1++; 722 s = *s1++;
711 723
724 for (i = 0; i < count; i++)
725 FRACMUL_8_LOOP(s, gain, s1, d);
726 }
727 else
728 {
729 src[1] = &sample_buf[0];
730 }
731
732 d = &sample_buf[0];
733 src[0] = d;
734 s = *s0++;
735
712 for (i = 0; i < count; i++) 736 for (i = 0; i < count; i++)
713 FRACMUL_8_LOOP(s, gain, s1, d); 737 FRACMUL_8_LOOP(s, gain, s0, d);
714 }
715 else
716 {
717 src[1] = &sample_buf[0];
718 } 738 }
719
720 d = &sample_buf[0];
721 src[0] = d;
722 s = *s0++;
723
724 for (i = 0; i < count; i++)
725 FRACMUL_8_LOOP(s, gain, s0, d);
726} 739}
727 740
728void channels_set(int value) 741void channels_set(int value)
@@ -1093,16 +1106,16 @@ void dsp_set_replaygain(bool always)
1093 if (gain == 0) 1106 if (gain == 0)
1094 { 1107 {
1095 /* So that noclip can work even with no gain information. */ 1108 /* So that noclip can work even with no gain information. */
1096 gain = DEFAULT_REPLAYGAIN; 1109 gain = DEFAULT_GAIN;
1097 } 1110 }
1098 1111
1099 if (global_settings.replaygain_noclip && (peak != 0) 1112 if (global_settings.replaygain_noclip && (peak != 0)
1100 && ((((int64_t) gain * peak) >> 24) >= DEFAULT_REPLAYGAIN)) 1113 && ((((int64_t) gain * peak) >> 24) >= DEFAULT_GAIN))
1101 { 1114 {
1102 gain = (((int64_t) DEFAULT_REPLAYGAIN << 24) / peak); 1115 gain = (((int64_t) DEFAULT_GAIN << 24) / peak);
1103 } 1116 }
1104 1117
1105 if (gain == DEFAULT_REPLAYGAIN) 1118 if (gain == DEFAULT_GAIN)
1106 { 1119 {
1107 /* Nothing to do, disable processing. */ 1120 /* Nothing to do, disable processing. */
1108 gain = 0; 1121 gain = 0;
@@ -1111,6 +1124,7 @@ void dsp_set_replaygain(bool always)
1111 } 1124 }
1112 1125
1113 /* Store in S8.23 format to simplify calculations. */ 1126 /* Store in S8.23 format to simplify calculations. */
1114 dsp->replaygain = gain >> 1; 1127 dsp->replaygain = gain;
1128 set_gain();
1115 } 1129 }
1116} 1130}