rtl_fm: better suffix parsing

Signed-off-by: Steve Markgraf <steve@steve-m.de>
master
Kyle Keen 11 years ago committed by Steve Markgraf
parent cb8907dd4e
commit a6d7fff9ca
  1. 35
      src/rtl_fm.c

@ -211,8 +211,8 @@ void low_pass(struct fm_state *fm, unsigned char *buf, uint32_t len)
{ {
int i=0, i2=0; int i=0, i2=0;
while (i < (int)len) { while (i < (int)len) {
fm->now_r += ((int)buf[i] - 128); fm->now_r += ((int)buf[i] - 127);
fm->now_j += ((int)buf[i+1] - 128); fm->now_j += ((int)buf[i+1] - 127);
i += 2; i += 2;
fm->prev_index++; fm->prev_index++;
if (fm->prev_index < fm->downsample) { if (fm->prev_index < fm->downsample) {
@ -254,8 +254,8 @@ void low_pass_fir(struct fm_state *fm, unsigned char *buf, uint32_t len)
int i=0, i2=0, i3=0; int i=0, i2=0, i3=0;
while (i < (int)len) { while (i < (int)len) {
i3 = fm->prev_index; i3 = fm->prev_index;
fm->now_r += ((int)buf[i] - 128) * fm->fir[i3] * fm->downsample / fm->fir_sum; fm->now_r += ((int)buf[i] - 127) * fm->fir[i3] * fm->downsample / fm->fir_sum;
fm->now_j += ((int)buf[i+1] - 128) * fm->fir[i3] * fm->downsample / fm->fir_sum; fm->now_j += ((int)buf[i+1] - 127) * fm->fir[i3] * fm->downsample / fm->fir_sum;
i += 2; i += 2;
fm->prev_index++; fm->prev_index++;
if (fm->prev_index < fm->downsample) { if (fm->prev_index < fm->downsample) {
@ -679,24 +679,30 @@ static void *demod_thread_fn(void *arg)
return 0; return 0;
} }
double atofs(char* f) double atofs(char *f)
/* standard suffixes */ /* standard suffixes */
{ {
char* chop; char last;
int len;
double suff = 1.0; double suff = 1.0;
chop = malloc((strlen(f)+1)*sizeof(char)); len = strlen(f);
strncpy(chop, f, strlen(f)-1); last = f[len-1];
switch (f[strlen(f)-1]) { f[len-1] = '\0';
switch (last) {
case 'g':
case 'G': case 'G':
suff *= 1e3; suff *= 1e3;
case 'm':
case 'M': case 'M':
suff *= 1e3; suff *= 1e3;
case 'k': case 'k':
case 'K':
suff *= 1e3; suff *= 1e3;
suff *= atof(chop);} suff *= atof(f);
free(chop); f[len-1] = last;
if (suff != 1.0) { return suff;
return suff;} }
f[len-1] = last;
return atof(f); return atof(f);
} }
@ -764,7 +770,7 @@ int main(int argc, char **argv)
pthread_rwlock_init(&data_rw, NULL); pthread_rwlock_init(&data_rw, NULL);
pthread_mutex_init(&data_mutex, NULL); pthread_mutex_init(&data_mutex, NULL);
while ((opt = getopt(argc, argv, "d:f:g:s:b:l:o:t:r:p:EFA:NWMULRDC")) != -1) { while ((opt = getopt(argc, argv, "d:f:g:s:b:l:o:t:r:p:EFA:NWMULRDCh")) != -1) {
switch (opt) { switch (opt) {
case 'd': case 'd':
dev_index = atoi(optarg); dev_index = atoi(optarg);
@ -853,6 +859,7 @@ int main(int argc, char **argv)
case 'R': case 'R':
fm.mode_demod = &raw_demod; fm.mode_demod = &raw_demod;
break; break;
case 'h':
default: default:
usage(); usage();
break; break;

Loading…
Cancel
Save