Repository navigation
Expand file tree
/
Copy pathicomplex16.h
More file actions
84 lines (72 loc) · 2.43 KB
/
Copy pathicomplex16.h
File metadata and controls
84 lines (72 loc) · 2.43 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
74
75
76
77
78
79
80
81
82
83
84
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2020-2026 Intel Corporation.
//
// Author: Amery Song <chao.song@intel.com>
// Keyon Jie <yang.jie@linux.intel.com>
#include <sof/audio/format.h>
#include <sof/common.h>
#include <stdint.h>
#ifndef __SOF_ICOMPLEX16_H__
#define __SOF_ICOMPLEX16_H__
/* Note: the add of packed attribute to icmplex16 would significantly increase
* processing time of fft_execute_16() so it is not done. The optimized versions of
* FFT for HiFi will need a different packed data structure vs. generic C.
*
* TODO: Use with care with other than 16-bit FFT internals. Access with intrinsics
* will requires packed and aligned data. Currently there is no such usage in SOF.
*/
/**
* struct icomplex16 - Storage for a normal complex number.
* @param real The real part in Q1.15 fractional format.
* @param imag The imaginary part in Q1.15 fractional format.
*/
struct icomplex16 {
int16_t real;
int16_t imag;
};
/*
* Helpers for 16 bit FFT calculation
*/
static inline void icomplex16_add(const struct icomplex16 *in1, const struct icomplex16 *in2,
struct icomplex16 *out)
{
out->real = in1->real + in2->real;
out->imag = in1->imag + in2->imag;
}
static inline void icomplex16_sub(const struct icomplex16 *in1, const struct icomplex16 *in2,
struct icomplex16 *out)
{
out->real = in1->real - in2->real;
out->imag = in1->imag - in2->imag;
}
static inline void icomplex16_mul(const struct icomplex16 *in1, const struct icomplex16 *in2,
struct icomplex16 *out)
{
int32_t real = (int32_t)in1->real * in2->real - (int32_t)in1->imag * in2->imag;
int32_t imag = (int32_t)in1->real * in2->imag + (int32_t)in1->imag * in2->real;
out->real = Q_SHIFT_RND(real, 30, 15);
out->imag = Q_SHIFT_RND(imag, 30, 15);
}
/* complex conjugate */
static inline void icomplex16_conj(struct icomplex16 *comp)
{
comp->imag = sat_int16(-((int32_t)comp->imag));
}
/* shift a complex n bits, n > 0: left shift, n < 0: right shift */
static inline void icomplex16_shift(const struct icomplex16 *input, int16_t n,
struct icomplex16 *output)
{
int n1, n2;
if (n >= 0) {
/* need saturation handling */
output->real = sat_int16((int32_t)input->real << n);
output->imag = sat_int16((int32_t)input->imag << n);
} else {
n1 = -n;
n2 = 1 << (n1 - 1);
output->real = sat_int16(((int32_t)input->real + n2) >> n1);
output->imag = sat_int16(((int32_t)input->imag + n2) >> n1);
}
}
#endif /* __SOF_ICOMPLEX16_H__ */