1 #ifndef WATERFALL_GLOBAL_DATA_CPP
2 #define WATERFALL_GLOBAL_DATA_CPP
4 #include <waterfallGlobalData.h>
6 WaterfallData::WaterfallData(const double minimumFrequency,
7 const double maximumFrequency,
8 const uint64_t fftPoints,
9 const unsigned int historyExtent)
10 : QwtRasterData(QwtDoubleRect(minimumFrequency /* X START */, 0 /* Y START */,
11 maximumFrequency - minimumFrequency /* WIDTH */,
12 static_cast<double>(historyExtent)/* HEIGHT */))
14 _intensityRange = QwtDoubleInterval(-200.0, 0.0);
16 _fftPoints = fftPoints;
17 _historyLength = historyExtent;
19 _spectrumData = new double[_fftPoints * _historyLength];
24 WaterfallData::~WaterfallData()
26 delete[] _spectrumData;
29 void WaterfallData::Reset()
31 memset(_spectrumData, 0x0, _fftPoints*_historyLength*sizeof(double));
33 _numLinesToUpdate = -1;
36 void WaterfallData::Copy(const WaterfallData* rhs)
38 if((_fftPoints != rhs->GetNumFFTPoints()) ||
39 (boundingRect() != rhs->boundingRect()) ){
40 _fftPoints = rhs->GetNumFFTPoints();
41 setBoundingRect(rhs->boundingRect());
42 delete[] _spectrumData;
43 _spectrumData = new double[_fftPoints * _historyLength];
46 SetSpectrumDataBuffer(rhs->GetSpectrumDataBuffer());
47 SetNumLinesToUpdate(rhs->GetNumLinesToUpdate());
48 setRange(rhs->range());
51 void WaterfallData::ResizeData(const double startFreq,
52 const double stopFreq,
53 const uint64_t fftPoints)
55 if((fftPoints != GetNumFFTPoints()) ||
56 (boundingRect().width() != (stopFreq - startFreq)) ||
57 (boundingRect().left() != startFreq)){
59 setBoundingRect(QwtDoubleRect(startFreq, 0, stopFreq-startFreq, boundingRect().height()));
60 _fftPoints = fftPoints;
61 delete[] _spectrumData;
62 _spectrumData = new double[_fftPoints * _historyLength];
68 QwtRasterData *WaterfallData::copy() const
70 WaterfallData* returnData = new WaterfallData(boundingRect().left(),
71 boundingRect().right(),
72 _fftPoints, _historyLength);
73 returnData->Copy(this);
77 QwtDoubleInterval WaterfallData::range() const
79 return _intensityRange;
82 void WaterfallData::setRange(const QwtDoubleInterval& newRange)
84 _intensityRange = newRange;
87 double WaterfallData::value(double x, double y) const
89 double returnValue = 0.0;
91 const unsigned int intY = static_cast<unsigned int>((1.0 - (y/boundingRect().height())) *
92 static_cast<double>(_historyLength - 1));
93 const unsigned int intX = static_cast<unsigned int>((((x - boundingRect().left()) / boundingRect().width()) *
94 static_cast<double>(_fftPoints-1)) + 0.5);
96 const int location = (intY * _fftPoints) + intX;
97 if((location > -1) && (location < static_cast<int64_t>(_fftPoints * _historyLength))){
98 returnValue = _spectrumData[location];
104 uint64_t WaterfallData::GetNumFFTPoints() const
109 void WaterfallData::addFFTData(const double* fftData,
110 const uint64_t fftDataSize,
111 const int droppedFrames){
112 if(fftDataSize == _fftPoints){
113 int64_t heightOffset = _historyLength - 1 - droppedFrames;
114 uint64_t drawingDroppedFrames = droppedFrames;
116 // Any valid data rolled off the display so just fill in zeros and write new data
117 if(heightOffset < 0){
119 drawingDroppedFrames = static_cast<uint64_t>(_historyLength-1);
122 // Copy the old data over if any available
123 if(heightOffset > 0){
124 memmove( _spectrumData, &_spectrumData[(drawingDroppedFrames+1) * _fftPoints],
125 heightOffset * _fftPoints * sizeof(double)) ;
128 if(drawingDroppedFrames > 0){
129 // Fill in zeros data for dropped data
130 memset(&_spectrumData[heightOffset * _fftPoints], 0x00,
131 static_cast<int64_t>(drawingDroppedFrames) * _fftPoints * sizeof(double));
134 // add the new buffer
135 memcpy(&_spectrumData[(_historyLength - 1) * _fftPoints], fftData, _fftPoints*sizeof(double));
139 double* WaterfallData::GetSpectrumDataBuffer() const
141 return _spectrumData;
144 void WaterfallData::SetSpectrumDataBuffer(const double* newData)
146 memcpy(_spectrumData, newData, _fftPoints * _historyLength * sizeof(double));
149 int WaterfallData::GetNumLinesToUpdate() const
151 return _numLinesToUpdate;
154 void WaterfallData::SetNumLinesToUpdate(const int newNum)
156 _numLinesToUpdate = newNum;
159 void WaterfallData::IncrementNumLinesToUpdate()
164 #endif /* WATERFALL_GLOBAL_DATA_CPP */