rtl_fm: half the oversample bugs

Signed-off-by: Steve Markgraf <steve@steve-m.de>
master
Kyle Keen 12 years ago committed by Steve Markgraf
parent a8e7c7b21e
commit 1533422f98
  1. 13
      src/rtl_fm.c

@ -86,7 +86,7 @@ struct fm_state
int signal_len; int signal_len;
FILE *file; FILE *file;
int edge; int edge;
uint32_t freqs[32]; uint32_t freqs[100];
int freq_len; int freq_len;
int freq_now; int freq_now;
uint32_t sample_rate; uint32_t sample_rate;
@ -236,8 +236,9 @@ int low_pass_simple(int16_t *signal2, int len, int step)
for(i2=0; i2<step; i2++) { for(i2=0; i2<step; i2++) {
sum += (int)signal2[i + i2]; sum += (int)signal2[i + i2];
} }
signal2[i] = (int16_t)(sum / step); signal2[i/step] = (int16_t)(sum / step);
} }
signal2[i/step + 1] = signal2[i/step];
return len / step; return len / step;
} }
@ -346,7 +347,7 @@ int post_squelch(struct fm_state *fm)
return 0;} return 0;}
/* weak signal, kill it entirely */ /* weak signal, kill it entirely */
for (i=0; i<len; i++) { for (i=0; i<len; i++) {
fm->signal2[i/2] = 0; fm->signal2[i] = 0;
} }
return 0; return 0;
} }
@ -396,7 +397,7 @@ void full_demod(unsigned char *buf, uint32_t len, struct fm_state *fm)
fm_demod(fm); fm_demod(fm);
sr = post_squelch(fm); sr = post_squelch(fm);
if (fm->post_downsample > 1) { if (fm->post_downsample > 1) {
fm->signal_len = low_pass_simple(fm->signal2, fm->signal_len, fm->post_downsample);} fm->signal_len = low_pass_simple(fm->signal2, fm->signal_len/2, fm->post_downsample)*2;}
/* ignore under runs for now */ /* ignore under runs for now */
fwrite(fm->signal2, 2, fm->signal_len/2, fm->file); fwrite(fm->signal2, 2, fm->signal_len/2, fm->file);
if (fm->freq_len > 1 && !sr && fm->squelch_hits > CONSEQ_SQUELCH) { if (fm->freq_len > 1 && !sr && fm->squelch_hits > CONSEQ_SQUELCH) {
@ -463,7 +464,7 @@ int main(int argc, char **argv)
fm.edge = 0; fm.edge = 0;
fm.fir_enable = 0; fm.fir_enable = 0;
fm.prev_index = -1; fm.prev_index = -1;
fm.post_downsample = 1; fm.post_downsample = 1; // once this works, default = 4
fm.custom_atan = 0; fm.custom_atan = 0;
sem_init(&data_ready, 0, 0); sem_init(&data_ready, 0, 0);
@ -505,7 +506,7 @@ int main(int argc, char **argv)
break; break;
} }
} }
/* double sample_rate to limit to Δθ to ±π */ /* quadruple sample_rate to limit to Δθ to ±π/2 */
fm.sample_rate *= fm.post_downsample; fm.sample_rate *= fm.post_downsample;
if (argc <= optind) { if (argc <= optind) {

Loading…
Cancel
Save