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>
This commit is contained in:
parent
a95b61f397
commit
60d88b6ed2
|
@ -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 */
|
||||
|
|
Reference in New Issue