2 Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
4 This file is part of aubio.
6 aubio is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 aubio is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with aubio. If not, see <http://www.gnu.org/licenses/>.
21 #include "aubio_priv.h"
23 #include "utils/scale.h"
25 struct _aubio_scale_t {
34 /* not implemented yet : type in/out data
40 aubio_scale_t * new_aubio_scale (smpl_t ilow, smpl_t ihig,
41 smpl_t olow, smpl_t ohig) {
42 aubio_scale_t * s = AUBIO_NEW(aubio_scale_t);
43 aubio_scale_set_limits (s, ilow, ihig, olow, ohig);
47 void del_aubio_scale(aubio_scale_t *s) {
51 uint_t aubio_scale_set_limits (aubio_scale_t *s, smpl_t ilow, smpl_t ihig,
52 smpl_t olow, smpl_t ohig) {
53 smpl_t inputrange = ihig - ilow;
54 smpl_t outputrange= ohig - olow;
59 if (inputrange == 0) {
62 s->scaler = outputrange/inputrange;
64 inputrange = inputrange * -1.0f;
70 void aubio_scale_do (aubio_scale_t *s, fvec_t *input)
73 for (j=0; j < input->length; j++){
74 input->data[j] -= s->ilow;
75 input->data[j] *= s->scaler;
76 input->data[j] += s->olow;