Exemple #1
0
static int plot_spectrum(const char *filename_png)
{
	struct vidframe *vf = NULL;
	struct vidsz sz = {NUM_FREQ+1, NUM_FREQ/2};
	unsigned long peak_mag = 0;
	size_t peak_bin = 0;
	size_t i;
	unsigned x;
	int err;

	err = vidframe_alloc(&vf, VID_FMT_RGB32, &sz);
	if (err)
		goto out;

	/* find the peak amplitude and its bin */
	for (i=0; i<NUM_FREQ; i++) {

		if (magv[i] > peak_mag) {
			peak_mag = magv[i];
			peak_bin = i;
		}
	}
	re_printf("peak magnitude is %u in bin %u\n", peak_mag, peak_bin);

	vidframe_fill(vf, 255, 255, 255);

	for (x=0; x<NUM_FREQ; x++) {

		unsigned h;

		h = (unsigned)((sz.h-1) * 1.0 * magv[x] / peak_mag);

		vidframe_draw_vline(vf, x, sz.h-1-h, h, 255, 0, 0);
	}

	err = png_save_vidframe(vf, filename_png);
	if (err)
		goto out;

 out:
	mem_deref(vf);

	return err;
}
Exemple #2
0
static inline void clear_frame(struct vidframe *vf)
{
	vidframe_fill(vf, 0, 0, 0);
}