-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDelay.cpp
64 lines (56 loc) · 1.88 KB
/
Delay.cpp
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
// Delay.cpp: implementation of the CDelay class.
// ( also performs Hilbert Real to complex I/Q 3KHz filtering )
#include "Delay.h"
#include "FilterTables.h"
namespace PathSim {
void Hilbert::init()
{
memset(m_hilbert_queue, 0, sizeof(m_hilbert_queue));
m_hilbert_ptr = HILBPFIR_LENGTH - 1;
}
// Hilbert 3KHz BP filters. Real input and complex I/Q output
// This FIR bandwidth limits the real input as well as creates a
// complex I/Q output signal for the rest of the processing chain.
void Hilbert::filter_block(const double* pIn, cmplx* pOut)
{
for (int i = 0; i < BLOCKSIZE; ++ i) {
m_hilbert_queue[m_hilbert_ptr].set(pIn[i], pIn[i]); //place real values in circular Queue
const cmplx* Firptr = m_hilbert_queue;
const double* IKptr = IHilbertBPFirCoef+HILBPFIR_LENGTH-m_hilbert_ptr;
const double* QKptr = QHilbertBPFirCoef+HILBPFIR_LENGTH-m_hilbert_ptr;
cmplx acc{0., 0.};
for (int j = 0; j < HILBPFIR_LENGTH; ++ j, ++ Firptr)
acc += (*Firptr) * (*IKptr++);
pOut[i] = acc;
if (-- m_hilbert_ptr < 0)
m_hilbert_ptr = HILBPFIR_LENGTH - 1;
}
}
void Delay::init()
{
memset(m_delay_line, 0, sizeof(m_delay_line));
m_in_ptr = BUFSIZE - 1;
m_out_ptrs.clear();
}
void Delay::add_delay(double time_ms)
{
m_out_ptrs.emplace_back(int(BUFSIZE - int(8.0 * time_ms) - 1));
}
// Uses pointers to create variable delays
void Delay::delay_block(const std::vector<cmplx> &inbuf, std::vector<std::vector<cmplx>*> &out_buffers)
{
for (int i = 0; i < BLOCKSIZE; ++ i) {
// Copy new data from inbuf into delay buffer
m_delay_line[m_in_ptr ++] = inbuf[i];
if (m_in_ptr >= BUFSIZE)
m_in_ptr = 0;
// Delay to the output buffers.
for (int j = 0; j < m_out_ptrs.size(); ++ j) {
int& ptr = m_out_ptrs[j];
(*out_buffers[j])[i] = m_delay_line[ptr ++];
if (ptr >= BUFSIZE)
ptr = 0;
}
}
}
} // namespace PathSim