avfilter/avf_showcqt: change fft left-right separation

This simplifies the code

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
pull/151/head
Muhammad Faiz 9 years ago committed by Michael Niedermayer
parent d13a2df8de
commit 145c5a9978
  1. 56
      libavfilter/avf_showcqt.c

@ -68,8 +68,7 @@ typedef struct {
AVFrame *outpicref; AVFrame *outpicref;
FFTContext *fft_context; FFTContext *fft_context;
FFTComplex *fft_data; FFTComplex *fft_data;
FFTComplex *fft_result_left; FFTComplex *fft_result;
FFTComplex *fft_result_right;
uint8_t *spectogram; uint8_t *spectogram;
SparseCoeff *coeff_sort; SparseCoeff *coeff_sort;
SparseCoeff *coeffs[VIDEO_WIDTH]; SparseCoeff *coeffs[VIDEO_WIDTH];
@ -125,8 +124,7 @@ static av_cold void uninit(AVFilterContext *ctx)
for (k = 0; k < VIDEO_WIDTH; k++) for (k = 0; k < VIDEO_WIDTH; k++)
av_freep(&s->coeffs[k]); av_freep(&s->coeffs[k]);
av_freep(&s->fft_data); av_freep(&s->fft_data);
av_freep(&s->fft_result_left); av_freep(&s->fft_result);
av_freep(&s->fft_result_right);
av_freep(&s->coeff_sort); av_freep(&s->coeff_sort);
av_freep(&s->spectogram); av_freep(&s->spectogram);
av_freep(&s->font_alpha); av_freep(&s->font_alpha);
@ -345,11 +343,10 @@ static int config_output(AVFilterLink *outlink)
s->fft_data = av_malloc_array(fft_len, sizeof(*s->fft_data)); s->fft_data = av_malloc_array(fft_len, sizeof(*s->fft_data));
s->coeff_sort = av_malloc_array(fft_len, sizeof(*s->coeff_sort)); s->coeff_sort = av_malloc_array(fft_len, sizeof(*s->coeff_sort));
s->fft_result_left = av_malloc_array(fft_len, sizeof(*s->fft_result_left)); s->fft_result = av_malloc_array(fft_len + 1, sizeof(*s->fft_result));
s->fft_result_right = av_malloc_array(fft_len, sizeof(*s->fft_result_right));
s->fft_context = av_fft_init(s->fft_bits, 0); s->fft_context = av_fft_init(s->fft_bits, 0);
if (!s->fft_data || !s->coeff_sort || !s->fft_result_left || !s->fft_result_right || !s->fft_context) if (!s->fft_data || !s->coeff_sort || !s->fft_result || !s->fft_context)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
#if CONFIG_LIBFREETYPE #if CONFIG_LIBFREETYPE
@ -541,43 +538,32 @@ static int plot_cqt(AVFilterLink *inlink)
int font_height = (FONT_HEIGHT/2) * video_scale; int font_height = (FONT_HEIGHT/2) * video_scale;
/* real part contains left samples, imaginary part contains right samples */ /* real part contains left samples, imaginary part contains right samples */
memcpy(s->fft_result_left, s->fft_data, fft_len * sizeof(*s->fft_data)); memcpy(s->fft_result, s->fft_data, fft_len * sizeof(*s->fft_data));
av_fft_permute(s->fft_context, s->fft_result_left); av_fft_permute(s->fft_context, s->fft_result);
av_fft_calc(s->fft_context, s->fft_result_left); av_fft_calc(s->fft_context, s->fft_result);
s->fft_result[fft_len] = s->fft_result[0];
/* separate left and right, (and multiply by 2.0) */
s->fft_result_right[0].re = 2.0f * s->fft_result_left[0].im;
s->fft_result_right[0].im = 0;
s->fft_result_left[0].re = 2.0f * s->fft_result_left[0].re;
s->fft_result_left[0].im = 0;
for (x = 1; x <= fft_len >> 1; x++) {
FFTSample tmpy = s->fft_result_left[fft_len-x].im - s->fft_result_left[x].im;
s->fft_result_right[x].re = s->fft_result_left[x].im + s->fft_result_left[fft_len-x].im;
s->fft_result_right[x].im = s->fft_result_left[x].re - s->fft_result_left[fft_len-x].re;
s->fft_result_right[fft_len-x].re = s->fft_result_right[x].re;
s->fft_result_right[fft_len-x].im = -s->fft_result_right[x].im;
s->fft_result_left[x].re = s->fft_result_left[x].re + s->fft_result_left[fft_len-x].re;
s->fft_result_left[x].im = tmpy;
s->fft_result_left[fft_len-x].re = s->fft_result_left[x].re;
s->fft_result_left[fft_len-x].im = -s->fft_result_left[x].im;
}
/* calculating cqt */ /* calculating cqt */
for (x = 0; x < VIDEO_WIDTH; x++) { for (x = 0; x < VIDEO_WIDTH; x++) {
int u; int u;
FFTComplex l = {0,0}; FFTComplex v = {0,0};
FFTComplex r = {0,0}; FFTComplex w = {0,0};
FFTComplex l, r;
for (u = 0; u < s->coeffs_len[x]; u++) { for (u = 0; u < s->coeffs_len[x]; u++) {
FFTSample value = s->coeffs[x][u].value; FFTSample value = s->coeffs[x][u].value;
int index = s->coeffs[x][u].index; int index = s->coeffs[x][u].index;
l.re += value * s->fft_result_left[index].re; v.re += value * s->fft_result[index].re;
l.im += value * s->fft_result_left[index].im; v.im += value * s->fft_result[index].im;
r.re += value * s->fft_result_right[index].re; w.re += value * s->fft_result[fft_len - index].re;
r.im += value * s->fft_result_right[index].im; w.im += value * s->fft_result[fft_len - index].im;
} }
/* separate left and right, (and multiply by 2.0) */
l.re = v.re + w.re;
l.im = v.im - w.im;
r.re = w.im + v.im;
r.im = w.re - v.re;
/* result is power, not amplitude */ /* result is power, not amplitude */
result[x][0] = l.re * l.re + l.im * l.im; result[x][0] = l.re * l.re + l.im * l.im;
result[x][2] = r.re * r.re + r.im * r.im; result[x][2] = r.re * r.re + r.im * r.im;

Loading…
Cancel
Save