mirror of
https://github.com/alexkay/spek.git
synced 2026-11-28 03:32:05 +03:00
C99-ify
This commit is contained in:
1 parent
546d61c0a8
commit
d64ffa56e8
2 files changed
+12
-9
No files matched your search
+10
-8
@@ -23,12 +23,15 @@
|
||||
|
||||
struct spek_fft_plan * spek_fft_plan_new(int n, int threshold)
|
||||
{
|
||||
int bits;
|
||||
struct spek_fft_plan *p = malloc(sizeof(struct spek_fft_plan));
|
||||
p->input = av_mallocz(sizeof(float) * n);
|
||||
p->output = av_mallocz(sizeof(float) * (n / 2 + 1));
|
||||
p->threshold = threshold;
|
||||
for(bits = 0; n; n >>= 1, ++bits);
|
||||
int bits = 0;
|
||||
while (n) {
|
||||
n >>= 1;
|
||||
++bits;
|
||||
}
|
||||
p->n = 1 << --bits;
|
||||
p->cx = av_rdft_init(bits, DFT_R2C);
|
||||
return p;
|
||||
@@ -36,17 +39,16 @@ struct spek_fft_plan * spek_fft_plan_new(int n, int threshold)
|
||||
|
||||
void spek_fft_execute(struct spek_fft_plan *p)
|
||||
{
|
||||
int i;
|
||||
int n = p->n;
|
||||
|
||||
av_rdft_calc(p->cx, p->input);
|
||||
|
||||
// Calculate magnitudes.
|
||||
int n = p->n;
|
||||
p->output[0] = p->input[0] * p->input[0] / (n * n);
|
||||
p->output[n / 2] = p->input[1] * p->input[1] / (n * n);
|
||||
for (i = 1; i < n / 2; i++) {
|
||||
float val;
|
||||
val = p->input[i * 2] * p->input[i * 2] + p->input[i * 2 + 1] * p->input[i * 2 + 1];
|
||||
for (int i = 1; i < n / 2; i++) {
|
||||
float val =
|
||||
p->input[i * 2] * p->input[i * 2] +
|
||||
p->input[i * 2 + 1] * p->input[i * 2 + 1];
|
||||
val /= n * n;
|
||||
val = 10.0 * log10f (val);
|
||||
p->output[i] = val < p->threshold ? p->threshold : val;
|
||||
|
||||
+2
-1
@@ -25,7 +25,8 @@ extern "C" {
|
||||
|
||||
#include <libavcodec/avfft.h>
|
||||
|
||||
struct spek_fft_plan {
|
||||
struct spek_fft_plan
|
||||
{
|
||||
// Internal data.
|
||||
RDFTContext *cx;
|
||||
int n;
|
||||
|
||||
Reference in new issue
Block a user