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
|
/*
* Copyright (C) 2002-2004 by Jonathan Naylor G4KLX
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <wx/wx.h>
#include "common/Average.h"
#include "FSK441Levels.h"
#include "FSK441Defs.h"
#include <cmath>
using namespace std;
CFSK441Levels::CFSK441Levels() :
m_audioData(NULL)
{
m_audioData = new double[FSK441_LEVEL_WIDTH];
for (int i = 0; i < FSK441_LEVEL_WIDTH; i++)
m_audioData[i] = 0.0;
}
CFSK441Levels::~CFSK441Levels()
{
delete[] m_audioData;
}
void CFSK441Levels::setAudioData(double* data, int count)
{
wxASSERT(data != NULL);
wxASSERT(count > 0);
double scale = double(FSK441_LEVEL_WIDTH) / double(FSK441_MAX_AUDIO_DATA);
fillinData(data, count, scale, m_audioData);
}
double CFSK441Levels::getAudioData(int pixel) const
{
wxASSERT(pixel >= 0 && pixel < FSK441_LEVEL_WIDTH);
return m_audioData[pixel];
}
void CFSK441Levels::fillinData(double* data, int count, double scale, double*& member)
{
int lastPixel = 0;
CAverage value;
for (int i = 0; i < count; i++) {
int pixel = int(scale * double(i));
if (pixel == lastPixel) {
value.addValue(::fabs(data[i]));
} else {
member[lastPixel] = value.getMaximum();
value.clear();
value.addValue(::fabs(data[i]));
lastPixel = pixel;
}
}
member[lastPixel] = value.getMaximum();
}
|