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
|
/***************************************************************************
Functions.cpp - list of simple periodic functions
-------------------
begin : Jan 21 2001
copyright : (C) 2001 by Thomas Eschenbacher
email : Thomas Eschenbacher <thomas.eschenbacher@gmx.de>
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#include "config.h"
#include <math.h>
#include <QString>
#include <KLocalizedString>
#include "libkwave/Functions.h"
#include "libkwave/String.h"
//***************************************************************************
static double rect(double param)
{
double div = param / (2 * M_PI);
param = param - (floor(div) * (2 * M_PI));
if (param > M_PI) return -1;
return 1;
}
//***************************************************************************
static double sin2(double param)
{
double y = sin(param);
return y*y;
}
//***************************************************************************
static double sin3(double param)
{
double y = sin(param);
return y*y*y;
}
//***************************************************************************
static double saw(double param)
{
double div = param / (2 * M_PI);
param -= (floor(div) * (2 * M_PI));
param /= M_PI;
param -= 1;
return param;
}
//***************************************************************************
static double sawinv(double param)
{
double div = param / (2 * M_PI);
param -= (floor(div) * (2 * M_PI));
param = 2 * M_PI - param;
param /= M_PI;
param -= 1;
return param;
}
//***************************************************************************
static double tri(double param)
{
param += M_PI / 2;
double div = param / (2 * M_PI);
param -= (floor(div) * (2 * M_PI));
if (param > M_PI) return (((param -M_PI) / M_PI)*2)-1;
return (((M_PI -param) / M_PI)*2)-1;
}
//***************************************************************************
static double zero(double)
{
return 0.0;
}
//***************************************************************************
//***************************************************************************
//***************************************************************************
void Kwave::Functions::FunctionTypesMap::fill()
{
append(0, &sin, _("sinus"), kli18n("Sinus"));
append(1, &rect, _("rectangular"), kli18n("Rectangular"));
append(2, &saw, _("sawtooth"), kli18n("Sawtooth"));
append(3, &sawinv, _("inverse_sawtooth"), kli18n("Inverse Sawtooth"));
append(4, &tri, _("triangular"), kli18n("Triangular"));
append(5, &sin2, _("square_sinus"), kli18n("Square Sinus"));
append(6, &sin3, _("cubic_sinus"), kli18n("Cubic Sinus"));
}
//***************************************************************************
Kwave::Functions::Functions()
{
}
//***************************************************************************
Kwave::Functions::~Functions()
{
}
//***************************************************************************
QString Kwave::Functions::name(unsigned int index)
{
Q_ASSERT(index < m_functions_map.count());
if (index >= m_functions_map.count()) return _("Zero");
return m_functions_map.name(index);
}
//***************************************************************************
Kwave::Functions::periodic_function_t &Kwave::Functions::function(
unsigned int index) const
{
Kwave::Functions::periodic_function_t *f = nullptr;
Q_ASSERT(index < m_functions_map.count());
if (index < m_functions_map.count()) f = m_functions_map.data(index);
if (!f) return *(&zero);
return *f;
}
//***************************************************************************
unsigned int Kwave::Functions::count() const
{
return m_functions_map.count();
}
//***************************************************************************
//***************************************************************************
|