-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpectrumDisplay.cpp
More file actions
178 lines (146 loc) · 6.07 KB
/
Copy pathSpectrumDisplay.cpp
File metadata and controls
178 lines (146 loc) · 6.07 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
* Copyright (c) 2010-2016 Stephane Poirier
*
* stephane.poirier@oifii.org
*
* Stephane Poirier
* 3532 rue Ste-Famille, #3
* Montreal, QC, H2X 2L1
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "SpectrumDisplay.h"
//Constructor which allows a user specified window array.
SpectrumDisplay :: SpectrumDisplay(long N_In, long M_In, SAMPLE* windowIn, char* axisTypeIn, float displayMinXIn, float displayWidthXIn, float displayMinYIn, float displayHeightYIn, SAMPLE minFreqDisplayedIn, SAMPLE maxFreqDisplayedIn, SAMPLE dataYValueLimitLowIn, SAMPLE dataYValueLimitHighIn) : WindowedFftHandler(N_In, M_In, windowIn), LineDisplayHandler2D( displayMinXIn, displayWidthXIn, displayMinYIn, displayHeightYIn, minFreqDisplayedIn, maxFreqDisplayedIn, dataYValueLimitLowIn, dataYValueLimitHighIn, false, true, ( M_In / 2))
{
axisType = new char[16];
//Initialize local arrays
realValuedInputBuffer = new SAMPLE[N_In];
magnitudeValues = new SAMPLE[M/2];
xAxisValues = new SAMPLE[M/2];
//Set the displayHandler's data pointers now that these arrays have been initialized
setDataXValuesPointer((const SAMPLE*) xAxisValues);
setDataYValuesPointer((const SAMPLE*) magnitudeValues);
//Fill xAxisValues with desired scale such that magnitude values correspond to linear or log spacing on the x axis.
if( strcmp(axisType, "log") || strcmp(axisType, "Log") )
{
axisType = "Log";
makeXAxisDisplayLog();
}
else if( strcmp(axisType, "linear") || strcmp(axisType, "Linear") )
{
axisType = "Linear";
makeXAxisDisplayLinear();
}
else
{
std::cout << "Invalid axisType specified!! axisType will be set to \"INVALID\"" << std::endl;
axisType = "INVALID";
}
//Make the display array for the X axis, since it is static
makeStaticDisplayArray( 0 );
}
//Constructor which specifies window by name.
SpectrumDisplay :: SpectrumDisplay(long N_In, long M_In, char* windowNameIn, char* axisTypeIn, float displayMinXIn, float displayWidthXIn, float displayMinYIn, float displayHeightYIn, SAMPLE minFreqDisplayedIn, SAMPLE maxFreqDisplayedIn, SAMPLE dataYValueLimitLowIn, SAMPLE dataYValueLimitHighIn) : WindowedFftHandler(N_In, M_In, windowNameIn), LineDisplayHandler2D( displayMinXIn, displayWidthXIn, displayMinYIn, displayHeightYIn, minFreqDisplayedIn, maxFreqDisplayedIn, dataYValueLimitLowIn, dataYValueLimitHighIn, false, true, ( M_In / 2))
{
axisType = new char[16];
axisType = axisTypeIn;
//Initialize local arrays
realValuedInputBuffer = new SAMPLE[N];
magnitudeValues = new SAMPLE[M/2];
xAxisValues = new SAMPLE[M/2];
//Set the displayHandler's data pointers now that these arrays have been initialized
setDataXValuesPointer((const SAMPLE*) xAxisValues);
setDataYValuesPointer((const SAMPLE*) magnitudeValues);
//Fill xAxisValues with desired scale such that magnitude values correspond to linear or log spacing on the x axis.
if( strcmp(axisTypeIn, "log") == 0 || strcmp(axisTypeIn, "Log") == 0 )
{
axisType = "Log";
makeXAxisDisplayLog();
}
else if( strcmp(axisTypeIn, "linear") == 0 || strcmp(axisTypeIn, "Linear") == 0 )
{
axisType = "Linear";
makeXAxisDisplayLinear();
}
else
{
std::cout << "Invalid axisType specified!! axisType will be set to \"INVALID\"" << std::endl;
axisType = "INVALID";
}
//Make the display array for the X axis, since it is static
makeStaticDisplayArray( 0 );
}
SpectrumDisplay :: ~SpectrumDisplay()
{
delete []realValuedInputBuffer;
delete []magnitudeValues;
delete []xAxisValues;
delete []axisType;
}
void SpectrumDisplay :: generateDisplayFromBuffer()
{
findUnitaryFftMagnitudesdB( realValuedInputBuffer, magnitudeValues );
refreshDisplayValues();
}
void SpectrumDisplay :: setM(long M_In)
{
this->WindowedFftHandler::setM(M_In); //set in WindowedFftHandler. Will assert that M_In is valid
//Then take care of extra SpectrumDisplay stuff ---------------------
delete []magnitudeValues;
delete []xAxisValues;
magnitudeValues = new SAMPLE[M/2];
xAxisValues = new SAMPLE[M/2];
//Regenerate xAxisValues
if( strcmp(axisType, "Log") == 0 )
makeXAxisDisplayLog();
else if( strcmp(axisType, "Linear") == 0 )
makeXAxisDisplayLinear();
//Reset LineDisplayHandler2D's data pointers now that arrays have been re-initialized
setDataXValuesPointer((const SAMPLE*) xAxisValues);
setDataYValuesPointer((const SAMPLE*) magnitudeValues);
//set new M in LineDisplayHandler2D now that SpectrumDisplay local arrays have been re-initialized and LineDisplayHandler2D's data pointers have been updated
changeLengthOfDataBuffers(M_In);
//Object is now ready for a call to generateDisplayFromBuffer. displayValues still need to be set for "updating" dimensions.
}
void SpectrumDisplay :: setAxisType(char* axisTypeIn)
{
if( strcmp(axisTypeIn, "log") == 0 || strcmp(axisTypeIn, "Log") == 0)
{
axisType = "Log";
makeXAxisDisplayLog();
}
else if( strcmp(axisTypeIn, "linear") == 0 || strcmp(axisTypeIn, "Linear") == 0)
{
axisType = "Linear";
makeXAxisDisplayLinear();
}
else
std::cout << "Invalid axisType specified!! axisType will not be changed." << std::endl;
//Recalculate display points for new X axis
makeStaticDisplayArray( 0 );
}
void SpectrumDisplay :: makeXAxisDisplayLog()
{
xAxisValues[0] = 0.0;
for(int binNum = 1; binNum < M/2; binNum++)
// xAxisValues[binNum] = log10( binNum * (SRATE / (2.0 * getM())) );
xAxisValues[binNum] = pow( binNum * (SRATE / (2.0 * getM())) , 0.3);
}
void SpectrumDisplay :: makeXAxisDisplayLinear()
{
for(int binNum = 0; binNum < M/2; binNum++)
xAxisValues[binNum] = binNum * ((double)SRATE / getM());
}