summaryrefslogtreecommitdiff
path: root/apps/dsp.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dsp.c')
-rw-r--r--apps/dsp.c71
1 files changed, 57 insertions, 14 deletions
diff --git a/apps/dsp.c b/apps/dsp.c
index 0ffaaea8d8..f306069a87 100644
--- a/apps/dsp.c
+++ b/apps/dsp.c
@@ -116,9 +116,10 @@ struct crossfeed_data
116 /* 8ch */ 116 /* 8ch */
117}; 117};
118 118
119/* Current setup is one lowshelf filters, three peaking filters and one 119/* Current setup is one lowshelf filters three peaking filters and one
120 highshelf filter. Varying the number of shelving filters make no sense, 120 * highshelf filter. Varying the number of shelving filters make no sense,
121 but adding peaking filters is possible. */ 121 * but adding peaking filters is possible.
122 */
122struct eq_state 123struct eq_state
123{ 124{
124 char enabled[5]; /* 00h - Flags for active filters */ 125 char enabled[5]; /* 00h - Flags for active filters */
@@ -171,6 +172,13 @@ static long dither_bias IBSS_ATTR;
171struct crossfeed_data crossfeed_data IBSS_ATTR; /* A */ 172struct crossfeed_data crossfeed_data IBSS_ATTR; /* A */
172/* Equalizer */ 173/* Equalizer */
173static struct eq_state eq_data; /* A/V */ 174static struct eq_state eq_data; /* A/V */
175#ifdef HAVE_SW_TONE_CONTROLS
176static int prescale;
177static int bass;
178static int treble;
179/* Filter struct for software bass/treble controls */
180static struct eqfilter tone_filter;
181#endif
174 182
175/* Settings applicable to audio codec only */ 183/* Settings applicable to audio codec only */
176static int pitch_ratio = 1000; 184static int pitch_ratio = 1000;
@@ -704,11 +712,7 @@ void dsp_set_crossfeed(bool enable)
704 712
705void dsp_set_crossfeed_direct_gain(int gain) 713void dsp_set_crossfeed_direct_gain(int gain)
706{ 714{
707 /* Work around bug in get_replaygain_int which returns 0 for 0 dB */ 715 crossfeed_data.gain = get_replaygain_int(gain * -10) << 7;
708 if (gain == 0)
709 crossfeed_data.gain = 0x7fffffff;
710 else
711 crossfeed_data.gain = get_replaygain_int(gain * -10) << 7;
712} 716}
713 717
714void dsp_set_crossfeed_cross_params(long lf_gain, long hf_gain, long cutoff) 718void dsp_set_crossfeed_cross_params(long lf_gain, long hf_gain, long cutoff)
@@ -716,8 +720,8 @@ void dsp_set_crossfeed_cross_params(long lf_gain, long hf_gain, long cutoff)
716 long g1 = get_replaygain_int(lf_gain * -10) << 3; 720 long g1 = get_replaygain_int(lf_gain * -10) << 3;
717 long g2 = get_replaygain_int(hf_gain * -10) << 3; 721 long g2 = get_replaygain_int(hf_gain * -10) << 3;
718 722
719 filter_bishelf_coefs(0xffffffff/NATIVE_FREQUENCY*cutoff, g1, g2, 723 filter_shelf_coefs(0xffffffff/NATIVE_FREQUENCY*cutoff, g1, g2,
720 crossfeed_data.coefs); 724 crossfeed_data.coefs);
721} 725}
722 726
723/* Applies crossfeed to the stereo signal in src. 727/* Applies crossfeed to the stereo signal in src.
@@ -985,6 +989,36 @@ static void channels_process_sound_chan_mono(int count, int32_t *buf[])
985} 989}
986#endif /* DSP_HAVE_ASM_SOUND_CHAN_MONO */ 990#endif /* DSP_HAVE_ASM_SOUND_CHAN_MONO */
987 991
992#ifdef HAVE_SW_TONE_CONTROLS
993static void set_tone_controls(void)
994{
995 filter_bishelf_coefs(0xffffffff/NATIVE_FREQUENCY*200,
996 0xffffffff/NATIVE_FREQUENCY*3500,
997 bass, treble, -prescale, tone_filter.coefs);
998}
999
1000int dsp_callback(int msg, intptr_t param)
1001{
1002 switch (msg) {
1003 case DSP_CALLBACK_SET_PRESCALE:
1004 prescale = param;
1005 set_tone_controls();
1006 break;
1007 /* prescaler is always set after calling any of these, so we wait with
1008 * calculating coefs until the above case is hit.
1009 */
1010 case DSP_CALLBACK_SET_BASS:
1011 bass = param;
1012 break;
1013 case DSP_CALLBACK_SET_TREBLE:
1014 treble = param;
1015 default:
1016 break;
1017 }
1018 return 0;
1019}
1020#endif
1021
988#ifndef DSP_HAVE_ASM_SOUND_CHAN_CUSTOM 1022#ifndef DSP_HAVE_ASM_SOUND_CHAN_CUSTOM
989static void channels_process_sound_chan_custom(int count, int32_t *buf[]) 1023static void channels_process_sound_chan_custom(int count, int32_t *buf[])
990{ 1024{
@@ -1068,12 +1102,12 @@ int dsp_process(char *dst, const char *src[], int count)
1068 int written = 0; 1102 int written = 0;
1069 int samples; 1103 int samples;
1070 1104
1071 #if defined(CPU_COLDFIRE) && !defined(SIMULATOR) 1105#if defined(CPU_COLDFIRE) && !defined(SIMULATOR)
1072 /* set emac unit for dsp processing, and save old macsr, we're running in 1106 /* set emac unit for dsp processing, and save old macsr, we're running in
1073 codec thread context at this point, so can't clobber it */ 1107 codec thread context at this point, so can't clobber it */
1074 unsigned long old_macsr = coldfire_get_macsr(); 1108 unsigned long old_macsr = coldfire_get_macsr();
1075 coldfire_set_macsr(EMAC_FRACTIONAL | EMAC_SATURATE); 1109 coldfire_set_macsr(EMAC_FRACTIONAL | EMAC_SATURATE);
1076 #endif 1110#endif
1077 1111
1078 while (count > 0) 1112 while (count > 0)
1079 { 1113 {
@@ -1085,8 +1119,17 @@ int dsp_process(char *dst, const char *src[], int count)
1085 break; /* I'm pretty sure we're downsampling here */ 1119 break; /* I'm pretty sure we're downsampling here */
1086 if (dsp->apply_crossfeed) 1120 if (dsp->apply_crossfeed)
1087 dsp->apply_crossfeed(tmp, samples); 1121 dsp->apply_crossfeed(tmp, samples);
1122 /* TODO: EQ and tone controls need separate structs for audio and voice
1123 * DSP processing thanks to filter history. isn't really audible now, but
1124 * might be the day we start handling voice more delicately.
1125 */
1088 if (eq_enabled) 1126 if (eq_enabled)
1089 eq_process(samples, tmp); 1127 eq_process(samples, tmp);
1128#ifdef HAVE_SW_TONE_CONTROLS
1129 if ((bass | treble) != 0)
1130 eq_filter(tmp, &tone_filter, samples, dsp->data.num_channels,
1131 FILTER_BISHELF_SHIFT);
1132#endif
1090 if (dsp->channels_process) 1133 if (dsp->channels_process)
1091 dsp->channels_process(samples, tmp); 1134 dsp->channels_process(samples, tmp);
1092 dsp->output_samples(samples, &dsp->data, tmp, (int16_t *)dst); 1135 dsp->output_samples(samples, &dsp->data, tmp, (int16_t *)dst);
@@ -1095,10 +1138,10 @@ int dsp_process(char *dst, const char *src[], int count)
1095 yield(); 1138 yield();
1096 } 1139 }
1097 1140
1098 #if defined(CPU_COLDFIRE) && !defined(SIMULATOR) 1141#if defined(CPU_COLDFIRE) && !defined(SIMULATOR)
1099 /* set old macsr again */ 1142 /* set old macsr again */
1100 coldfire_set_macsr(old_macsr); 1143 coldfire_set_macsr(old_macsr);
1101 #endif 1144#endif
1102 return written; 1145 return written;
1103} 1146}
1104 1147