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
|
#include "v17dem.h"
#define INITIAL_BAUD_RATE 2400
#define INITIAL_CARRIER_FREQ 1800
#define SAMPLE_RATE 8000
#define SAMPLES_MAX (SAMPLES_RATE*5) /* -> 5s buffer */
struct v17dem_state {
int baud_rate;
int carrier_freq;
struct resample_state qam_resample, xam_resample, yam_resample;
struct qbuf am_qbuf, xam_qbuf, yam_qbuf, xsymbols_qbuf, ysymbols_qbuf;
};
static int v17_7k2_symbol_decode(float x, float y) {
int row, col, i;
static const int v17_7k2_table[] = {
3, 10, 5, 0,
6, 15, 12, 9,
13, 8, 11, 2,
4, 1, 14, 7
};
col = (int) ((x+.6)/.4 +.5);
if (col < 0) col = 0;
if (col > 3) col = 3;
row = (int) ((y+.6)/.4 +.5);
if (row < 0) row = 0;
if (row > 3) row = 3;
i = col*4+row;
assert(i >= 0 && i <= 15);
return v17_7k2_table[i];
}
void v17dem_init(struct v17dem_state *s) {
assert(s);
memset(s, 0, sizeof(struct v17dem_state));
s->baud_rate = INITIAL_BAUD_RATE;
s->carrier_freq = INITIAL_CARRIER_FREQ;
resample_init(&s->qam_resample);
resample_init(&s->xam_resample);
resample_init(&s->yam_resample);
qbuf_init(&s->am_qbuf, sizeof(float) * SAMPLES_MAX);
qbuf_init(&s->xam_qbuf, sizeof(float) * SAMPLES_MAX/2);
qbuf_init(&s->yam_qbuf, sizeof(float) * SAMPLES_MAX/2);
qbuf_init(&s->xsymbols_qbuf, sizeof(float) * SAMPLES_MAX/2);
qbuf_init(&s->ysymbols_qbuf, sizeof(float) * SAMPLES_MAX/2);
}
void v17dem_done(struct v17dem_state *s) {
assert(s);
resample_done(&s->qam_resample);
resample_done(&s->xam_resample);
resample_done(&s->yam_resample);
qbuf_done(&s->am_qbuf);
qbuf_done(&s->xam_qbuf);
qbuf_done(&s->yam_qbuf);
qbuf_done(&s->xsymbols_qbuf);
qbuf_done(&s->ysymbols_qbuf);
}
static int v17_decode(struct qbuf
int v17dem_run(struct v17dem_state *s, struct qbuf *sample_qbuf, struct qbuf *byte_qbuf){
assert(s && sample_qbuf && byte_qbuf);
resample_get(s->qam_resample, sample_qbuf, s->am_qbuf, SAMPLE_RATE, s->carrier_freq*4);
qbuf_float_split(s->am_qbuf, s->xam_qbuf, s->yam_qbuf);
resample_get(s->xam_resample, s->xam_qbuf, s->xsymbols_qbuf);
resample_get(s->yam_resample, s->yam_qbuf, s->ysymbols_qbuf);
v17_decode(s->xsymbols_qbuf, s->ysymbols_qbuf, byte_qbuf),
}
|