forked from thesofproject/sof
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfft_common.c
More file actions
73 lines (61 loc) · 1.38 KB
/
fft_common.c
File metadata and controls
73 lines (61 loc) · 1.38 KB
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
64
65
66
67
68
69
70
71
72
73
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2020 Intel Corporation. All rights reserved.
//
// Author: Amery Song <chao.song@intel.com>
// Keyon Jie <yang.jie@linux.intel.com>
#include <sof/audio/buffer.h>
#include <sof/audio/format.h>
#include <sof/common.h>
#include <rtos/alloc.h>
#include <sof/math/fft.h>
struct fft_plan *fft_plan_new(void *inb, void *outb, uint32_t size, int bits)
{
struct fft_plan *plan;
int lim = 1;
int len = 0;
int i;
if (!inb || !outb)
return NULL;
plan = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(struct fft_plan));
if (!plan)
return NULL;
switch (bits) {
case 16:
plan->inb16 = inb;
plan->outb16 = outb;
break;
case 32:
plan->inb32 = inb;
plan->outb32 = outb;
break;
default:
rfree(plan);
return NULL;
}
/* calculate the exponent of 2 */
while (lim < size) {
lim <<= 1;
len++;
}
plan->size = lim;
plan->len = len;
plan->bit_reverse_idx = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM,
plan->size * sizeof(uint16_t));
if (!plan->bit_reverse_idx) {
rfree(plan);
return NULL;
}
/* set up the bit reverse index */
for (i = 1; i < plan->size; ++i)
plan->bit_reverse_idx[i] = (plan->bit_reverse_idx[i >> 1] >> 1) |
((i & 1) << (len - 1));
return plan;
}
void fft_plan_free(struct fft_plan *plan)
{
if (!plan)
return;
rfree(plan->bit_reverse_idx);
rfree(plan);
}