rtl_power: fix NaN on 32 bit platforms (T. Kaminski)

pull/11/merge
Kyle Keen 2014-10-17 12:22:03 -04:00
rodzic 8ad17c2c95
commit 1b1c03d4e9
1 zmienionych plików z 11 dodań i 11 usunięć

Wyświetl plik

@ -99,7 +99,7 @@ struct tuning_state
int gain;
int bin_e;
int16_t *fft_buf;
long *avg; /* length == 2^bin_e */
int64_t *avg; /* length == 2^bin_e */
int samples;
int downsample;
int downsample_passes; /* for the recursive filter */
@ -461,19 +461,19 @@ void rms_power(struct tuning_state *ts)
int i, s;
uint8_t *buf = ts->buf8;
int buf_len = ts->buf_len;
long p, t;
int64_t p, t;
double dc, err;
p = t = 0L;
for (i=0; i<buf_len; i++) {
s = (int)buf[i] - 127;
t += (long)s;
p += (long)(s * s);
t += (int64_t)s;
p += (int64_t)(s * s);
}
/* correct for dc offset in squares */
dc = (double)t / (double)buf_len;
err = t * 2 * dc - dc * dc * buf_len;
p -= (long)round(err);
p -= (int64_t)round(err);
if (!ts->peak_hold) {
ts->avg[0] += p;
@ -642,7 +642,7 @@ void frequency_range(char *arg, struct misc_settings *ms)
ts->comp_fir_size = ms->comp_fir_size;
ts->peak_hold = ms->peak_hold;
ts->linear = ms->linear;
ts->avg = (long*)malloc((1<<c.bin_e) * sizeof(long));
ts->avg = (int64_t*)malloc((1<<c.bin_e) * sizeof(int64_t));
if (!ts->avg) {
fprintf(stderr, "Error: malloc.\n");
exit(1);
@ -772,11 +772,11 @@ void remove_dc(int16_t *data, int length)
{
int i;
int16_t ave;
long sum = 0L;
int64_t sum = 0L;
for (i=0; i < length; i+=2) {
sum += data[i];
}
ave = (int16_t)(sum / (long)(length));
ave = (int16_t)(sum / (int64_t)(length));
if (ave == 0) {
return;}
for (i=0; i < length; i+=2) {
@ -822,10 +822,10 @@ void downsample_iq(int16_t *data, int length)
//remove_dc(data+1, length-1);
}
long real_conj(int16_t real, int16_t imag)
int64_t real_conj(int16_t real, int16_t imag)
/* real(n * conj(n)) */
{
return ((long)real*(long)real + (long)imag*(long)imag);
return ((int64_t)real*(int64_t)real + (int64_t)imag*(int64_t)imag);
}
void scanner(void)
@ -913,7 +913,7 @@ void scanner(void)
void csv_dbm(struct tuning_state *ts)
{
int i, len, ds;
long tmp;
int64_t tmp;
double dbm;
char *sep = ", ";
len = 1 << ts->bin_e;