summaryrefslogtreecommitdiff
path: root/plugins/supereq/ff_rdft.c
blob: 70a09350f70a4c2e8fe130699d77fe26e59c826e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <stdint.h>
#include <complex.h>
#include "libavcodec/avfft.h"
#include "libavutil/avutil.h"

void rfft(int n,int isign,float *x)
{
  static int wsize=0;
  static float *w = NULL;
  static RDFTContext *s = NULL;
  static RDFTContext *si = NULL;
  int newwsize;

  if (n == 0) {
      if (w) {
          av_free(w);
          w  = NULL;
          wsize  = 0;
      }
      if (s) {
          av_rdft_end (s);
          s = NULL;
      }
      if (si) {
          av_rdft_end (si);
          si = NULL;
      }
    return;
  }

  newwsize = n/2;
  if (newwsize > wsize) {
    wsize = newwsize;
    if (s) {
        av_rdft_end (s);
        s = NULL;
    }
      if (si) {
          av_rdft_end (si);
          si = NULL;
      }
    if (w) {
        av_free (w);
        w = NULL;
    }
    w = (float *)av_malloc(sizeof(float)*wsize);
  }

  if (!s) {
      s = av_rdft_init(n,DFT_R2C);
  }
  if (!si) {
      si = av_rdft_init(n,IDFT_C2R);
  }

  if (isign == 1) {
      av_rdft_calc (s, x);
  }
  else {
      av_rdft_calc (si, x);
  }
}