summaryrefslogtreecommitdiff
path: root/src/audio/fdct.cc
blob: 620fc37501dee4355eda82e2a33c53273e180f3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// This file is part of the 64k demo project.
// It implements the 512-point Forward Discrete Cosine Transform.
// Used for analyzing audio files into spectrograms.

#include "dct.h"
#include <math.h>

void fdct_512(const float *input, float *output) {
  const float PI = 3.14159265358979323846f;
  for (int k = 0; k < DCT_SIZE; ++k) {
    float sum = 0.0f;
    for (int n = 0; n < DCT_SIZE; ++n) {
      sum +=
          input[n] * cosf(PI / (float)DCT_SIZE * ((float)n + 0.5f) * (float)k);
    }
    output[k] = sum;
  }
}