forked from wpats/scanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrequencyTable.cpp
97 lines (86 loc) · 2.4 KB
/
frequencyTable.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
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
#include <vector>
#include <stdio.h>
#include <cstdint>
#include <math.h>
#include <cassert>
#include "frequencyTable.h"
FrequencyTable::FrequencyTable(uint32_t sampleRate,
double startFrequency,
double stopFrequency,
double useBandWidth,
double dcIgnoreWidth)
: m_frequencyIndex(0),
m_iterationCount(0)
{
double f1 = startFrequency + useBandWidth/2 * sampleRate;
double step = useBandWidth;
if (dcIgnoreWidth > 0) {
step = (useBandWidth - dcIgnoreWidth)/2;
}
double frequency;
uint32_t count = 0;
if (stopFrequency == 0.0) {
count = 1;
} else {
for (; (frequency = f1 + count * step * double(sampleRate)) < stopFrequency; count++) {
}
assert(count == ceil((stopFrequency - f1)/(step * sampleRate)));
}
this->m_table.resize(count);
for (uint32_t i = 0; i < count; i++) {
double frequency = f1 + i * step * double(sampleRate);
printf("Frequency %d: %.0f\n", i, frequency);
this->m_table.at(i) = FrequencyInfo{frequency, nullptr};
}
}
double FrequencyTable::GetNextFrequency(void ** pinfo)
{
this->m_frequencyIndex++;
if (this->m_frequencyIndex >= this->m_table.size()) {
this->m_frequencyIndex = 0;
this->m_iterationCount++;
}
return this->GetCurrentFrequency(pinfo);
}
double FrequencyTable::GetCurrentFrequency(void ** pinfo)
{
FrequencyInfo & finfo = this->m_table[this->m_frequencyIndex];
if (pinfo != nullptr) {
*pinfo = finfo.m_info;
}
return finfo.m_frequency;
}
double FrequencyTable::GetStartFrequency()
{
FrequencyInfo & finfo = this->m_table.front();
return finfo.m_frequency;
}
double FrequencyTable::GetStopFrequency()
{
FrequencyInfo & finfo = this->m_table.back();
return finfo.m_frequency;
}
uint32_t FrequencyTable::GetFrequencyCount()
{
return this->m_table.size();
}
double FrequencyTable::GetFrequencyFromIndex(uint32_t index)
{
assert(index < this->m_table.size());
FrequencyInfo & finfo = this->m_table[index];
return finfo.m_frequency;
}
void FrequencyTable::SetFrequencyInfoForIndex(uint32_t index, void * info)
{
assert(index < this->m_table.size());
FrequencyInfo & finfo = this->m_table[index];
finfo.m_info = info;
}
uint32_t FrequencyTable::GetIterationCount()
{
return this->m_iterationCount;
}
bool FrequencyTable::GetIsScanStart()
{
return this->m_frequencyIndex == 0;
}