diff options
author | Sylvain Munaut <tnt@246tNt.com> | 2012-03-29 23:35:36 +0200 |
---|---|---|
committer | Sylvain Munaut <tnt@246tNt.com> | 2012-03-29 23:35:36 +0200 |
commit | 60d88b6ed2424c19ecb6465de0b7a6ffcd52d851 (patch) | |
tree | 0ca5e10bf86dc37097a39c72df9dab854728ef58 /firmware/src/tuner_e4k.c | |
parent | a95b61f39742efe22908eef4385e8499f126cc78 (diff) |
tuner_e4k: Fix closest_arr_idx
The previous method tried to do clever stuff assuming the sequence is
sorted. Unfortunately:
1) this didn't really find the 'closest' match
2) this didn't work for the first or last interval
3) this didn't work for freq slightly above or below the last/first freq
All in all, it's easier to try them all.
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Diffstat (limited to 'firmware/src/tuner_e4k.c')
-rw-r--r-- | firmware/src/tuner_e4k.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/firmware/src/tuner_e4k.c b/firmware/src/tuner_e4k.c index 7bd59dc..898fcf3 100644 --- a/firmware/src/tuner_e4k.c +++ b/firmware/src/tuner_e4k.c @@ -152,19 +152,20 @@ static const uint32_t rf_filt_center_l[] = { static int closest_arr_idx(const uint32_t *arr, unsigned int arr_size, uint32_t freq) { - unsigned int i; - uint32_t last_delta = 0xffffffff; + unsigned int i, bi; + uint32_t best_delta = 0xffffffff; - /* iterate over the array containing an ordered list of the center + /* iterate over the array containing a list of the center * frequencies, selecting the closest one */ for (i = 0; i < arr_size; i++) { uint32_t delta = unsigned_delta(freq, arr[i]); - if (last_delta < delta) - return i-1; - last_delta = delta; + if (delta < best_delta) { + best_delta = delta; + bi = i; + } } - return -ERANGE; + return bi; } /* return 4-bit index as to which RF filter to select */ |