Ejemplo n.º 1
0
static void *demod_thread_fn(void *arg)
{
	while (!do_exit) {
		safe_cond_wait(&ready, &ready_m);
		pthread_rwlock_wrlock(&both.rw);
		downsample(&both);
		memcpy(left.buf,  both.buf, 2*both.len_out);
		memcpy(right.buf, both.buf, 2*both.len_out);
		pthread_rwlock_unlock(&both.rw);
		rotate_90(left.buf, left.len_in);
		downsample(&left);
		memcpy(left_demod.buf, left.buf, 2*left.len_out);
		demodulate(&left_demod);
		if (dc_filter) {
			dc_block_filter(&left_demod);}
		//if (oversample) {
		//	downsample(&left);}
		arbitrary_upsample(left_demod.result, stereo.buf_left, left_demod.result_len, stereo.bl_len);
		rotate_m90(right.buf, right.len_in);
		downsample(&right);
		memcpy(right_demod.buf, right.buf, 2*right.len_out);
		demodulate(&right_demod);
		if (dc_filter) {
			dc_block_filter(&right_demod);}
		//if (oversample) {
		//	downsample(&right);}
		arbitrary_upsample(right_demod.result, stereo.buf_right, right_demod.result_len, stereo.br_len);
		output();
	}
	rtlsdr_cancel_async(dev);
	return 0;
}
void NarrowbandAMAudio::execute(const buffer_c8_t& buffer) {
	if( !configured ) {
		return;
	}

	const auto decim_0_out = decim_0.execute(buffer, dst_buffer);
	const auto decim_1_out = decim_1.execute(decim_0_out, dst_buffer);
	const auto decim_2_out = decim_2.execute(decim_1_out, dst_buffer);
	const auto channel_out = channel_filter.execute(decim_2_out, dst_buffer);

	// TODO: Feed channel_stats post-decimation data?
	feed_channel_stats(channel_out);
	channel_spectrum.feed(channel_out, channel_filter_pass_f, channel_filter_stop_f);

	auto audio = demodulate(channel_out);
	audio_compressor.execute_in_place(audio);
	audio_output.write(audio);
}
int main(int argc, char **argv)
{
  FILE *head_fp;
  Ilist just;
  Plist demodulators, p;
  Mindex idx;
  Term t;
  int rewritten = 0;
  BOOL verbose = string_member("verbose", argv, argc);;

  if (string_member("help", argv, argc) ||
      string_member("-help", argv, argc) ||
      argc < 2) {
    printf("\n%s, version %s, %s\n",PROGRAM_NAME,PROGRAM_VERSION,PROGRAM_DATE);
    printf("%s", Help_string);
    exit(1);
  }

  init_standard_ladr();

  head_fp = fopen(argv[1], "r");
  if (head_fp == NULL)
    fatal_error("demodulator file can't be opened for reading");

  t = read_commands(head_fp, stderr, verbose, KILL_UNKNOWN);

  if (!is_term(t, "clauses", 1) && !is_term(t, "formulas", 1))
    fatal_error("formulas(demodulators) not found");

  /* Read list of demodulators. */

  demodulators = read_clause_list(head_fp, stderr, TRUE);

  fclose(head_fp);

  /* AC-canonicalize and index the demodulators. */

  if (assoc_comm_symbols() || comm_symbols())
    idx = mindex_init(DISCRIM_WILD, BACKTRACK_UNIF, 0);
  else
    idx = mindex_init(DISCRIM_BIND, ORDINARY_UNIF, 0);

  for (p = demodulators; p != NULL; p = p->next) {
    /* assume positive equality unit */
    Topform d = p->v;
    Literals lit = d->literals;
    Term alpha = lit->atom->args[0];
    mark_oriented_eq(lit->atom);  /* don not check for termination */
    if (assoc_comm_symbols())
      ac_canonical(lit->atom, -1);
    mindex_update(idx, alpha, INSERT);
  }

  if (verbose)
    fwrite_clause_list(stdout, demodulators, "demodulators", CL_FORM_BARE);

  /* Read and demodulate terms. */

  t = read_term(stdin, stderr);

  while (t != NULL) {
    rewritten++;
    if (verbose) {
      fprintf(stdout, "\nBefore:   "); fwrite_term_nl(stdout, t);
    }

    if (assoc_comm_symbols())
      ac_canonical(t, -1);
    just = NULL;
    t = demodulate(t, idx, &just, FALSE);

    if (verbose)
      fprintf(stdout, "After:    ");

    fwrite_term_nl(stdout, t);
    fflush(stdout);

    zap_ilist(just);
    zap_term(t);
    t = read_term(stdin, stderr);
  }

  printf("%% %s %s: rewrote %d terms with %d rewrite steps in %.2f seconds.\n",
	 PROGRAM_NAME, argv[1], rewritten, demod_rewrites(), user_seconds());
    
  exit(0);

}  /* main */