forked from g0orx/wdsp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcblock.c
More file actions
126 lines (107 loc) · 3.04 KB
/
Copy pathcblock.c
File metadata and controls
126 lines (107 loc) · 3.04 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
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
124
125
126
/* cblock.c
This file is part of a program that implements a Software-Defined Radio.
Copyright (C) 2013, 2016 Warren Pratt, NR0V
This program is free software; you can redistribute it 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 program 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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
The author can be reached by email at
warren@wpratt.com
*/
#include "comm.h"
void calc_cbl (CBL a)
{
a->prevIin = 0.0;
a->prevQin = 0.0;
a->prevIout = 0.0;
a->prevQout = 0.0;
a->mtau = exp(-1.0 / (a->sample_rate * a->tau));
}
CBL create_cbl
(
int run,
int buff_size,
double *in_buff,
double *out_buff,
int mode,
int sample_rate,
double tau
)
{
CBL a = (CBL) malloc0 (sizeof(cbl));
a->run = run;
a->buff_size = buff_size;
a->in_buff = in_buff;
a->out_buff = out_buff;
a->mode = mode;
a->sample_rate = (double)sample_rate;
a->tau = tau;
calc_cbl (a);
return a;
}
void destroy_cbl(CBL a)
{
_aligned_free (a);
}
void flush_cbl (CBL a)
{
a->prevIin = 0.0;
a->prevQin = 0.0;
a->prevIout = 0.0;
a->prevQout = 0.0;
}
void xcbl (CBL a)
{
if (a->run)
{
int i;
double tempI, tempQ;
for (i = 0; i < a->buff_size; i++)
{
tempI = a->in_buff[2 * i + 0];
tempQ = a->in_buff[2 * i + 1];
a->out_buff[2 * i + 0] = a->in_buff[2 * i + 0] - a->prevIin + a->mtau * a->prevIout;
a->out_buff[2 * i + 1] = a->in_buff[2 * i + 1] - a->prevQin + a->mtau * a->prevQout;
a->prevIin = tempI;
a->prevQin = tempQ;
if (fabs(a->prevIout = a->out_buff[2 * i + 0]) < 1.0e-100) a->prevIout = 0.0;
if (fabs(a->prevQout = a->out_buff[2 * i + 1]) < 1.0e-100) a->prevQout = 0.0;
}
}
else if (a->in_buff != a->out_buff)
memcpy (a->out_buff, a->in_buff, a->buff_size * sizeof (complex));
}
void setBuffers_cbl (CBL a, double* in, double* out)
{
a->in_buff = in;
a->out_buff = out;
}
void setSamplerate_cbl (CBL a, int rate)
{
a->sample_rate = rate;
calc_cbl (a);
}
void setSize_cbl (CBL a, int size)
{
a->buff_size = size;
flush_cbl (a);
}
/********************************************************************************************************
* *
* RXA Properties *
* *
********************************************************************************************************/
PORT void
SetRXACBLRun(int channel, int setit)
{
EnterCriticalSection (&ch[channel].csDSP);
rxa[channel].cbl.p->run = setit;
LeaveCriticalSection (&ch[channel].csDSP);
}