forked from flightaware/dump1090
-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert.c
123 lines (107 loc) · 4.15 KB
/
convert.c
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Part of dump1090, a Mode S message decoder for RTLSDR devices.
//
// convert.c: support for various IQ -> magnitude conversions
//
// Copyright (c) 2015 Oliver Jowett <[email protected]>
//
// This file is free software: you may copy, redistribute and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation, either version 2 of the License, or (at your
// option) any later version.
//
// This file is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "dump1090.h"
static void convert_uc8(void *iq_data,
uint16_t *mag_data,
unsigned nsamples,
struct converter_state *state,
double *out_mean_level,
double *out_mean_power)
{
MODES_NOTUSED(state);
const uc8_t *in = (const uc8_t *) iq_data;
if (out_mean_level && out_mean_power) {
if (STARCH_IS_ALIGNED(in) && STARCH_IS_ALIGNED(mag_data))
starch_magnitude_power_uc8_aligned(in, mag_data, nsamples, out_mean_level, out_mean_power);
else
starch_magnitude_power_uc8(in, mag_data, nsamples, out_mean_level, out_mean_power);
} else {
if (STARCH_IS_ALIGNED(in) && STARCH_IS_ALIGNED(mag_data))
starch_magnitude_uc8_aligned(in, mag_data, nsamples);
else
starch_magnitude_uc8(in, mag_data, nsamples);
}
}
static void convert_sc16(void *iq_data,
uint16_t *mag_data,
unsigned nsamples,
struct converter_state *state,
double *out_mean_level,
double *out_mean_power)
{
MODES_NOTUSED(state);
const sc16_t *in = (const sc16_t *) iq_data;
if (STARCH_IS_ALIGNED(in) && STARCH_IS_ALIGNED(mag_data))
starch_magnitude_sc16_aligned(in, mag_data, nsamples);
else
starch_magnitude_sc16(in, mag_data, nsamples);
if (out_mean_level && out_mean_power) {
if (STARCH_IS_ALIGNED(mag_data))
starch_mean_power_u16_aligned(mag_data, nsamples, out_mean_level, out_mean_power);
else
starch_mean_power_u16(mag_data, nsamples, out_mean_level, out_mean_power);
}
}
static void convert_sc16q11(void *iq_data,
uint16_t *mag_data,
unsigned nsamples,
struct converter_state *state,
double *out_mean_level,
double *out_mean_power)
{
MODES_NOTUSED(state);
const sc16_t *in = (const sc16_t *) iq_data;
if (STARCH_IS_ALIGNED(in) && STARCH_IS_ALIGNED(mag_data))
starch_magnitude_sc16q11_aligned(in, mag_data, nsamples);
else
starch_magnitude_sc16q11(in, mag_data, nsamples);
if (out_mean_level && out_mean_power) {
if (STARCH_IS_ALIGNED(mag_data))
starch_mean_power_u16_aligned(mag_data, nsamples, out_mean_level, out_mean_power);
else
starch_mean_power_u16(mag_data, nsamples, out_mean_level, out_mean_power);
}
}
iq_convert_fn init_converter(input_format_t format,
double sample_rate,
int filter_dc,
struct converter_state **out_state)
{
MODES_NOTUSED(sample_rate);
MODES_NOTUSED(out_state);
if (filter_dc) {
fprintf(stderr, "DC filtering not supported (yet)\n");
return NULL;
}
switch (format) {
case INPUT_UC8:
return convert_uc8;
case INPUT_SC16:
return convert_sc16;
case INPUT_SC16Q11:
return convert_sc16q11;
default:
fprintf(stderr, "no suitable converter for format=%u\n", (unsigned) format);
return NULL;
}
}
void cleanup_converter(struct converter_state *state)
{
MODES_NOTUSED(state);
}