Beispiel #1
0
void polyphase_seg(float* data) {
    int i,n;
    static fftw_plan planfwd;
    float *p;

    if (!planfwd) {
      planfwd=fftw_create_plan(P_FFT_LEN, FFTW_FORWARD, 
		FFTW_MEASURE | FFTW_IN_PLACE | FFTW_USE_WISDOM );
    }

    for (i=0;i<P_FFT_LEN;i++) {
        f_data[2*i] = 0;
        f_data[2*i+1] = 0;
        for (n=0;n<N_WINDOWS;n++) {
            f_data[2*i] += data[2*i+2*n*P_FFT_LEN]*filter_r[P_FFT_LEN*n + i];
            f_data[2*i+1] += data[2*i+2*n*P_FFT_LEN+1]*filter_i[P_FFT_LEN*n + i];
        }
    }
    fftw_one(planfwd, (fftw_complex *)f_data, (fftw_complex *)NULL);
    /*for (i=0;i<P_FFT_LEN;i++) {
        fprintf( stderr, "%f %f\n", f_data[2*i], f_data[2*i+1]);
    }*/
    //fprintf( stderr, "%f %f ", f_data[2*3], f_data[2*3+1] );
    p = f_data;
    for (i=0; i<P_FFT_LEN; i++) {
        output_samples(p, i, obuf_pos);
        p += IFFT_LEN*2;
    }
    obuf_pos+=IFFT_LEN*2/CHAR_BIT;
}
static int print_ad(int fd)
{
	size_t size = sid_sample_size * ((sample_rate + 9) / 10); /* 100msec */
	unsigned char *sample_buf;
	size_t remain, len;
	unsigned int overrun;

	sample_buf = malloc(size);
	if (!sample_buf) {
		fprintf(stderr, "Out of memory.\n");
		return -1;
	}
	if (ioctl(fd, SID_IOC_SET_FREQ, sample_rate) < 0) {
		fprintf(stderr, "Failed to set sample rate.\n");
		return -1;
	}
	for (remain = sid_sample_size * nr_sample; remain > 0; remain -= len) {
		if (size > remain)
			size = remain;
		len = read(fd, sample_buf, size);
		if (len < 0) {
			fprintf(stderr, "Read error.\n");
			free(sample_buf);
			return -1;
		}
		if (ioctl(fd, SID_IOC_GET_OVERRUN, &overrun) < 0) {
			fprintf(stderr, "Failed to get overrun state.\n");
			free(sample_buf);
			return -1;
		}
		if (overrun > 0) {
			fprintf(stderr, "Overrun occurred.\n");
			if (overrun < 0xffffffffUL)
				printf("\n(Overrun: "
				       "approx. %u samples dropped)\n\n",
				       overrun);
			else
				printf("\n(Overrun: "
				       "many samples dropped)\n\n");
		}
		output_samples((unsigned short *)sample_buf,
			       len / sid_sample_size);
	}
	free(sample_buf);

	return 0;
}
Beispiel #3
0
void process_seg(float* data) {
    int i;
    float* p = data;
    static float dbuff[FFT_LEN*2];
    static fftw_plan  planfwd,planinverse;

    if (!planfwd) {
      planfwd=fftw_create_plan(FFT_LEN, FFTW_BACKWARD, 
		FFTW_MEASURE | FFTW_IN_PLACE | FFTW_USE_WISDOM );
      planinverse=fftw_create_plan(IFFT_LEN, FFTW_FORWARD,
		FFTW_MEASURE | FFTW_IN_PLACE | FFTW_USE_WISDOM );
    }

    fftw_one(planfwd, (fftw_complex *)data, (fftw_complex *)NULL);
    data[0]=0;
    data[1]=0;
    fftw(planinverse, NSTRIPS, (fftw_complex *)data, 1, IFFT_LEN, 
  			(fftw_complex *)NULL, 1, IFFT_LEN);
    for (i=0; i<NSTRIPS; i++) {
        output_samples(p, i, obuf_pos);
        p += IFFT_LEN*2;
    }
    obuf_pos+=IFFT_LEN*2/CHAR_BIT;
}
void concurrency_handler::on_shutdown(shutdown_event_data &data) {
    cancel();
    output_samples(data.node_id);
}
Beispiel #5
0
/* Initialize. Play out what we need to. Get out. */
int press_play(char *data_filename, char *wave_filename) {
  double *one_audio;
  double *zero_audio;
  void *out_file;
  FILE *in_file;
  char cur_byte;
  int is_pos;
  int (*output_samples)(void *,double *,size_t);

  make_output_audio(&zero_audio, &one_audio,DEFAULT_WAVELENGTH);

  /* If there's no filename, use the standard input */
  if (data_filename == NULL)
    in_file = stdin;
  else
    in_file = fopen(data_filename,"r");

  if (in_file == NULL) {
    cosby_print_err("Couldn't open %s\n",data_filename);
    return -1;
  }
  if (wave_filename == NULL) {
    output_samples = &output_to_speaker;
    if (init_speaker_output(&out_file) < 0)
      return -1;
  } else {
    output_samples = &output_to_file;
    init_file_output(&out_file, wave_filename);
  } 
  /* Output five seconds of 0 */
  for (int c=0;c<DEFAULT_SAMPLE_RATE*5/DEFAULT_WAVELENGTH;c++) {
    output_samples(out_file,zero_audio,DEFAULT_WAVELENGTH);
  }

  /* Output a byte of all 1s */
  for (int n=7;n>=0;n--) {
    output_samples(out_file,one_audio,DEFAULT_WAVELENGTH/2);
  }
  is_pos = 1;

  /* Loop through the data and output the appropriate
     portion of the appropriate wave.

     If you understand this part, you pretty much understand
     playback. You could just take the sine instead of all that fancy
     FFT bull. FFTW is at its most ineffecient when it's generating a
     single wave. It's expensive to make the plan, so it's usually
     used by running the same plan over and over.
  */
  while (fread(&cur_byte,1,1,in_file)) {
    for (int n=7;n>=0;n--) {
      if (get_nth_bit(cur_byte,n)) {
	if (is_pos) {
	  /* positive one */
	  output_samples(out_file,one_audio,DEFAULT_WAVELENGTH/2);
	} else {
	  /* negative one */
	  output_samples(out_file,one_audio+DEFAULT_WAVELENGTH/4,DEFAULT_WAVELENGTH-DEFAULT_WAVELENGTH/2);
	}
      } else {
	if (is_pos) {
	  /* positive zero */
	  output_samples(out_file,zero_audio,DEFAULT_WAVELENGTH/2);
	} else {
	  /* negative zero */
	  output_samples(out_file,zero_audio+DEFAULT_WAVELENGTH/2,DEFAULT_WAVELENGTH-DEFAULT_WAVELENGTH/2);
	}
	is_pos = !is_pos;
      }
    }
  }

  /* and an extra half a wave for padding */
  if (is_pos) {
    /* positive zero */
    output_samples(out_file,zero_audio,DEFAULT_WAVELENGTH/2);
  } else {
    /* negative zero */
    output_samples(out_file,zero_audio+DEFAULT_WAVELENGTH/2,DEFAULT_WAVELENGTH-DEFAULT_WAVELENGTH/2);
  }

  if (wave_filename == NULL) {
    /* FIXME You forgot to close the soundcard on the way out, you jerk! */
  } else {
    sf_close((SNDFILE *)out_file);
  }

  /* Close the input file, free the audio */
  if (data_filename != NULL)
    fclose(in_file);
  free_audio_output(zero_audio, one_audio);
  return 0;
}