spek

Acoustic spectrum analyser
git clone http://git.hanabi.in/repos/spek.git
Log | Files | Refs | README

commit 8436464c16aeb58b29b538091af489dbea0915bf
parent 979862e2b9679b9ba222c2eae8724558b26fb53c
Author: Alexander Kojevnikov <alexander@kojevnikov.com>
Date:   Thu, 20 Sep 2012 22:06:03 -0700

MIN/MAX macros are not portable

Diffstat:
Mlib/spek-utils.h | 10++++++++++
Msrc/spek-spectrogram.cc | 12++++++------
2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/lib/spek-utils.h b/lib/spek-utils.h @@ -19,6 +19,16 @@ #ifndef SPEK_UTILS_H_ #define SPEK_UTILS_H_ +inline int spek_max(int a, int b) +{ + return a > b ? a : b; +} + +inline int spek_min(int a, int b) +{ + return a < b ? a : b; +} + // Compare version numbers, e.g. 1.9.2 < 1.10.0 int spek_vercmp(const char *a, const char *b); diff --git a/src/spek-spectrogram.cc b/src/spek-spectrogram.cc @@ -17,7 +17,6 @@ */ #include <cmath> -#include <sys/param.h> #include <wx/dcbuffer.h> @@ -25,6 +24,7 @@ extern "C" { #include <spek-audio.h> #include <spek-palette.h> #include <spek-pipeline.h> +#include <spek-utils.h> } #include "spek-audio-desc.hh" @@ -119,13 +119,13 @@ void SpekSpectrogram::on_char(wxKeyEvent& evt) bool up = evt.GetKeyCode() == WXK_UP; if (C && up) { - this->lrange = MIN(this->lrange + 1, this->urange - 1); + this->lrange = spek_min(this->lrange + 1, this->urange - 1); } else if (C && dn) { - this->lrange = MAX(this->lrange - 1, MIN_RANGE); + this->lrange = spek_max(this->lrange - 1, MIN_RANGE); } else if (CS && up) { - this->urange = MIN(this->urange + 1, MAX_RANGE); + this->urange = spek_min(this->urange + 1, MAX_RANGE); } else if (CS && dn) { - this->urange = MAX(this->urange - 1, this->lrange + 1); + this->urange = spek_max(this->urange - 1, this->lrange + 1); } else { evt.Skip(); return; @@ -166,7 +166,7 @@ void SpekSpectrogram::on_have_sample(SpekHaveSampleEvent& event) // TODO: check image size, quit if wrong. double range = log(1.0 + this->urange - this->lrange); for (int y = 0; y < bands; y++) { - double value = MIN(this->urange, MAX(this->lrange, values[y])); + double value = fmin(this->urange, fmax(this->lrange, values[y])); double level = log(1.0 + value - this->lrange) / range; uint32_t color = spek_palette_spectrum(level); this->image.SetRGB(