コード例 #1
0
ファイル: dab2eti.c プロジェクト: ashh87/dabtools
static void *demod_thread_fn(void *arg)
{
  struct dab_state_t *dab = arg;
  struct sdr_state_t *sdr = dab->device_state;
  int i,j;

  while (!do_exit) {
    sem_wait(&data_ready);
    int ok = sdr_demod(&dab->tfs[dab->tfidx], sdr);
    if (ok) {
      dab_process_frame(dab);
    }
    //dab_fic_parser(dab->fib,&sinfo,&ana);
    // calculate error rates
    //dab_analyzer_calculate_error_rates(&ana,dab);

    int prev_freq = sdr->frequency;
    if (abs(sdr->coarse_freq_shift)>1) {
      if (sdr->coarse_freq_shift<0)
	sdr->frequency = sdr->frequency -1000;
      else
	sdr->frequency = sdr->frequency +1000;
      
      rtlsdr_set_center_freq(dev,sdr->frequency);
      
    }
    
    if (abs(sdr->coarse_freq_shift) ==1) {
      
      if (sdr->coarse_freq_shift<0)
	sdr->frequency = sdr->frequency -rand() % 1000;
      else
	sdr->frequency = sdr->frequency +rand() % 1000;
      
      rtlsdr_set_center_freq(dev,sdr->frequency);
      //fprintf(stderr,"new center freq : %i\n",rtlsdr_get_center_freq(dev));
      
    } 
    if (abs(sdr->coarse_freq_shift)<1 && (abs(sdr->fine_freq_shift) > 50)) {
      sdr->frequency = sdr->frequency + (sdr->fine_freq_shift/3);
      rtlsdr_set_center_freq(dev,sdr->frequency);
      //fprintf(stderr,"ffs : %f\n",sdr->fine_freq_shift);

    }

    //if (sdr->frequency != prev_freq) {
    //  fprintf(stderr,"Adjusting centre-frequency to %dHz\n",sdr->frequency);
    //}    
    ccount += 1;
    if (ccount == 10) {
      ccount = 0;
      //print_status(dab);
    }
  }
  return 0;
}
コード例 #2
0
ファイル: dab2eti.cpp プロジェクト: sheimers/libdabplus
void *dab2eti::demod_thread_fn(void *arg)
{
  struct dab_state_t *dab = (dab_state_t *)arg;
  struct sdr_state_t *sdr = (sdr_state_t *)dab->device_state;

  while (!do_exit) {
    sem_wait(&data_ready);
    int ok = sdr_demod(&dab->tfs[dab->tfidx], sdr);
    if (ok) {
      dab_process_frame(dab);
    }
    //dab_fic_parser(dab->fib,&sinfo,&ana);
    // calculate error rates
    //dab_analyzer_calculate_error_rates(&ana,dab);

    // if the user changed the frequency
    if(new_frequency){ 
      sdr->frequency = frequency;
      new_frequency = false;
    }

    // if the user changed the gain
    if(new_gain){
      int r;
      if (gain == AUTO_GAIN) {
	r = rtlsdr_set_tuner_gain_mode(dev, 0);
      } else {
	r = rtlsdr_set_tuner_gain_mode(dev, 1);
	r = rtlsdr_set_tuner_gain(dev, gain);
      }
      if (r != 0) {
	fprintf(stderr, "WARNING: Failed to set tuner gain.\n");
      } else if (gain == AUTO_GAIN) {
	fprintf(stderr, "Tuner gain set to automatic.\n");
      } else {
	fprintf(stderr, "Tuner gain set to %0.2f dB.\n", gain/10.0);
      }
      new_gain = false;
    }
    

    
    // automatic fine tuning
    if (abs(sdr->coarse_freq_shift)>1) {
      if (sdr->coarse_freq_shift<0)
	sdr->frequency = sdr->frequency -1000;
      else
	sdr->frequency = sdr->frequency +1000;
      
      rtlsdr_set_center_freq(dev,sdr->frequency);
      
    }
    
    if (abs(sdr->coarse_freq_shift) ==1) {
      
      if (sdr->coarse_freq_shift<0)
	sdr->frequency = sdr->frequency -rand() % 1000;
      else
	sdr->frequency = sdr->frequency +rand() % 1000;
      
      rtlsdr_set_center_freq(dev,sdr->frequency);
      //fprintf(stderr,"new center freq : %i\n",rtlsdr_get_center_freq(dev));
      
    } 
    if (abs(sdr->coarse_freq_shift)<1 && (abs(sdr->fine_freq_shift) > 50)) {
      sdr->frequency = sdr->frequency + (sdr->fine_freq_shift/3);
      rtlsdr_set_center_freq(dev,sdr->frequency);
      //fprintf(stderr,"ffs : %f\n",sdr->fine_freq_shift);

    }

    //if (sdr->frequency != prev_freq) {
    //  fprintf(stderr,"Adjusting centre-frequency to %dHz\n",sdr->frequency);
    //}    
    ccount += 1;
    if (ccount == 10) {
      ccount = 0;
      //print_status(dab);
    }
  }
  return 0;
}