22 #include <linux/slab.h>
23 #include <linux/kernel.h>
24 #include <linux/module.h>
26 #include <asm/div64.h>
31 #define INT_PI ((s32)(3.141592653589 * 32768.0))
33 #define compat_remainder(a, b) \
34 ((float)(((s32)((a)*100))%((s32)((b)*100)))/100.0)
36 #define baseband_freq(carrier, srate, tone) ((s32)( \
37 (compat_remainder(carrier + tone, srate)) / srate * 2 * INT_PI))
42 #define FREQ_A2_CARRIER baseband_freq(54687.5, 2689.36, 0.0)
43 #define FREQ_A2_DUAL baseband_freq(54687.5, 2689.36, 274.1)
44 #define FREQ_A2_STEREO baseband_freq(54687.5, 2689.36, 117.5)
52 #define FREQ_A2M_CARRIER ((s32)(2.114516 * 32768.0))
53 #define FREQ_A2M_DUAL ((s32)(2.754916 * 32768.0))
54 #define FREQ_A2M_STEREO ((s32)(2.462326 * 32768.0))
56 #define FREQ_EIAJ_CARRIER ((s32)(1.963495 * 32768.0))
57 #define FREQ_EIAJ_DUAL ((s32)(2.562118 * 32768.0))
58 #define FREQ_EIAJ_STEREO ((s32)(2.601053 * 32768.0))
60 #define FREQ_BTSC_DUAL ((s32)(1.963495 * 32768.0))
61 #define FREQ_BTSC_DUAL_REF ((s32)(1.374446 * 32768.0))
63 #define FREQ_BTSC_SAP ((s32)(2.471532 * 32768.0))
64 #define FREQ_BTSC_SAP_REF ((s32)(1.730072 * 32768.0))
67 #define FREQ_NOISE_START ((s32)(0.100000 * 32768.0))
68 #define FREQ_NOISE_END ((s32)(1.200000 * 32768.0))
74 #define dprintk(level, fmt, arg...) if (dsp_debug >= level) \
75 printk(KERN_DEBUG "%s/0: " fmt, core->name , ## arg)
83 return -int_cos(x -
INT_PI);
90 t4 = t2*x/32768*x/32768/3/4;
91 t6 = t4*x/32768*x/32768/5/6;
92 t8 = t6*x/32768*x/32768/7/8;
93 ret = 32768-t2+t4-t6+
t8;
109 for (i = 0; i <
N; i++) {
110 s32 s = x[
i] + ((
s64)coeff*s_prev/32768) - s_prev2;
115 tmp = (
s64)s_prev2 * s_prev2 + (
s64)s_prev * s_prev -
116 (
s64)coeff * s_prev2 * s_prev / 32768;
128 u32 sum = int_goertzel(x, N, freq);
132 static u32 noise_magnitude(
s16 x[],
u32 N,
u32 freq_start,
u32 freq_end)
145 freq_step = (freq_end - freq_start) / (samples - 1);
147 for (i = 0; i < samples; i++) {
148 sum += int_goertzel(x, N, freq_start);
149 freq_start += freq_step;
157 s32 carrier, stereo,
dual, noise;
158 s32 carrier_freq, stereo_freq, dual_freq;
184 carrier = freq_magnitude(x, N, carrier_freq);
185 stereo = freq_magnitude(x, N, stereo_freq);
186 dual = freq_magnitude(x, N, dual_freq);
189 dprintk(1,
"detect a2/a2m/eiaj: carrier=%d, stereo=%d, dual=%d, "
190 "noise=%d\n", carrier, stereo, dual, noise);
199 if ((carrier >
max(stereo, dual)*2) &&
200 (carrier <
max(stereo, dual)*6) &&
201 (carrier > 20 && carrier < 200) &&
202 (
max(stereo, dual) >
min(stereo, dual))) {
208 if ((carrier >
max(stereo, dual)*2) &&
209 (carrier <
max(stereo, dual)*8) &&
210 (carrier > 20 && carrier < 200) &&
212 (
max(stereo, dual) >
min(stereo, dual)*2)) {
225 dprintk(1,
"detect btsc: dual_ref=%d, dual=%d, sap_ref=%d, sap=%d"
226 "\n", dual_ref, dual, sap_ref, sap);
238 unsigned int spl = bpl/4;
244 dprintk(1,
"read RDS samples: current_address=%08x (offset=%08x), "
245 "sample_count=%d, aud_intstat=%08x\n", current_address,
246 current_address - srch->
fifo_start, sample_count,
255 for (i = 0; i < sample_count; i++) {
262 dprintk(2,
"RDS samples dump: ");
263 for (i = 0; i < sample_count; i++)
264 printk(
"%hd ", samples[i]);
287 samples = read_rds_samples(core, &N);
297 ret = detect_a2_a2m_eiaj(core, samples, N);
300 ret = detect_btsc(core, samples, N);
314 dprintk(1,
"stereo/sap detection result:%s%s%s\n",