-
Notifications
You must be signed in to change notification settings - Fork 2
/
common.cuh
101 lines (79 loc) · 3.04 KB
/
common.cuh
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
/**
* @file common.cuh
* @brief Common defines and functions
* @author John Melton, G0ORX/N6LYT
*/
/* Copyright (C)
* 2015 - John Melton, G0ORX/N6LYT
*
* Based on code by Steven Passe AD0ES and Vasiliy Gokoyev K3IT
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#include <cufft.h>
//#define TIMING
#define SOCKET_SAMPLE_RATE 61440000
#define PCIE_SAMPLE_RATE 73529412
#define DIVISOR (32767.0F)
#define P_SIZE 262145 // FIR Length
#define V_SIZE 4 // Overlap factor V = N/(P-1)
#define DFT_BLOCK_SIZE ((P_SIZE - 1) * V_SIZE) // N real samples
#define L_SIZE (DFT_BLOCK_SIZE - P_SIZE + 1) // Number of new input samples consumed per data block
#define COMPLEX_SIGNAL_SIZE (DFT_BLOCK_SIZE / 2) // N/2
#define NFACTOR (double)(COMPLEX_SIGNAL_SIZE) / ((double)V_SIZE * (samplingrate / 2))
#define D_SIZE_48K 128
#define D_SIZE_96K 64
#define D_SIZE_192K 32
#define D_SIZE_384K 16
#define BYTES_PER_FRAME 8192
#define SAMPLES_PER_FRAME (BYTES_PER_FRAME / sizeof(short))
#define FRAMES_PER_BUFFER (L_SIZE / SAMPLES_PER_FRAME)
#define IFFT_DECIMATE_MAX (samplingrate/D_SIZE_384K/2/48000)
#define IFFT_DECIMATE_MIN (samplingrate/D_SIZE_48K/2/48000)
#define RX_TD_SIZE ((COMPLEX_SIGNAL_SIZE/d_size - (P_SIZE-1)/2/d_size)/ifft_decimate_factor + 1)
#define DEVICE_RX_TD_SIZE ((COMPLEX_SIGNAL_SIZE/d_size - (P_SIZE-1)/2/d_size)/decimate + 1)
#define RX_TD_MAXSIZE ((COMPLEX_SIGNAL_SIZE/D_SIZE_384K - (P_SIZE-1)/2/D_SIZE_384K) / IFFT_DECIMATE_MIN + 1)
#define SOURCE_PCIE 0
#define SOURCE_SOCKET 1
#define SOURCE_FILE 2
extern int source;
extern int capture;
extern int samplingrate;
extern float hzperbin;
extern char interface[];
// Complex multiplication
__device__ inline cufftComplex ComplexMul(const cufftComplex a, const cufftComplex b)
{
cufftComplex c;
c.x = a.x * b.x - a.y * b.y;
c.y = a.x * b.y + a.y * b.x;
return (c);
}
// Complex scale
__device__ inline cufftComplex ComplexScale(const cufftComplex a, const float s)
{
cufftComplex c;
c.x = s * a.x;
c.y = s * a.y;
return (c);
}
__device__ inline cufftComplex ComplexAdd(const cufftComplex a, const cufftComplex b)
{
cufftComplex c;
c.x = a.x + b.x;
c.y = a.y + b.y;
return (c);
}