diff options
| author | vovanec <vovanec@90c681e8-e032-0410-971d-27865f9a5e38> | 2007-06-23 16:48:01 +0000 |
|---|---|---|
| committer | vovanec <vovanec@90c681e8-e032-0410-971d-27865f9a5e38> | 2007-06-23 16:48:01 +0000 |
| commit | 2d622fd9bcb8da9dd3f3206e296cd6a701fc9d12 (patch) | |
| tree | f92135e6cb831e46336dfd4ade47e03ef3a19ac5 /src/logscale.cpp | |
| parent | 4b6a6720805c585c89f44fd276b3ace8670514d9 (diff) | |
| download | qmmp-2d622fd9bcb8da9dd3f3206e296cd6a701fc9d12.tar.gz qmmp-2d622fd9bcb8da9dd3f3206e296cd6a701fc9d12.tar.bz2 qmmp-2d622fd9bcb8da9dd3f3206e296cd6a701fc9d12.zip | |
moved into qmmp dir
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@12 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/logscale.cpp')
| -rw-r--r-- | src/logscale.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/logscale.cpp b/src/logscale.cpp new file mode 100644 index 000000000..921004fd9 --- /dev/null +++ b/src/logscale.cpp @@ -0,0 +1,74 @@ +// Copyright (c) 2000-2001 Brad Hughes <bhughes@trolltech.com> +// +// Use, modification and distribution is allowed without limitation, +// warranty, or liability of any kind. +// + +#include "logscale.h" + +#include <math.h> +#include <stdio.h> + + +LogScale::LogScale(int maxscale, int maxrange) + : indices(0), s(0), r(0) +{ + setMax(maxscale, maxrange); +} + + +LogScale::~LogScale() +{ + if (indices) + delete [] indices; +} + + +void LogScale::setMax(int maxscale, int maxrange) +{ + if (maxscale == 0 || maxrange == 0) + return; + + s = maxscale; + r = maxrange; + + if (indices) + delete [] indices; + + double alpha; + int i, scaled; + double domain = double(maxscale), + range = double(maxrange), + x = 1.0, + dx = 1.0, + y = 0.0, + yy = 0.0, + t = 0.0, + e4 = double(1.0E-8); + + indices = new int[maxrange]; + for (i = 0; i < maxrange; i++) + indices[i] = 0; + + // initialize log scale + while (fabs(dx) > e4) { + t = log((domain + x) / x); + y = (x * t) - range; + yy = t - (domain / (x + domain)); + dx = y / yy; + x -= dx; + } + + alpha = x; + for (i = 1; i < (int) domain; i++) { + scaled = (int) floor(0.5 + (alpha * log((double(i) + alpha) / alpha))); + if (indices[scaled - 1] < i) + indices[scaled - 1] = i; + } +} + + +int LogScale::operator[](int index) +{ + return indices[index]; +} |
