source: src/utils/scale.c @ 695a248

feature/crepe_org
Last change on this file since 695a248 was 55d1fa4, checked in by Paul Brossier <piem@piem.org>, 9 years ago

src/utils/: add const qualifiers

  • Property mode set to 100644
File size: 1.9 KB
RevLine 
[96fb8ad]1/*
[e6a78ea]2  Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
[96fb8ad]3
[e6a78ea]4  This file is part of aubio.
[96fb8ad]5
[e6a78ea]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.
[f1eda56]10
[e6a78ea]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.
15
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/>.
[96fb8ad]18
[680137a]19*/
[96fb8ad]20
21#include "aubio_priv.h"
[6c7d49b]22#include "fvec.h"
[32d6958]23#include "utils/scale.h"
[96fb8ad]24
25struct _aubio_scale_t {
[f1eda56]26  smpl_t ilow;
27  smpl_t ihig;
28  smpl_t olow;
29  smpl_t ohig;
30
31  smpl_t scaler;
32  smpl_t irange;
[96fb8ad]33
[f1eda56]34  /* not implemented yet : type in/out data
35     bool inint;
36     bool outint;
37     */
[96fb8ad]38};
39
[55d1fa4]40aubio_scale_t * new_aubio_scale (smpl_t ilow, smpl_t ihig,
[f1eda56]41    smpl_t olow, smpl_t ohig) {
42  aubio_scale_t * s = AUBIO_NEW(aubio_scale_t);
[0ce97483]43  aubio_scale_set_limits (s, ilow, ihig, olow, ohig);
[f1eda56]44  return s;
[96fb8ad]45}
46
47void del_aubio_scale(aubio_scale_t *s) {
[f1eda56]48  AUBIO_FREE(s);
[96fb8ad]49}
50
[28c162c]51uint_t aubio_scale_set_limits (aubio_scale_t *s, smpl_t ilow, smpl_t ihig,
[f1eda56]52    smpl_t olow, smpl_t ohig) {
53  smpl_t inputrange = ihig - ilow;
54  smpl_t outputrange= ohig - olow;
55  s->ilow = ilow;
56  s->ihig = ihig;
57  s->olow = olow;
58  s->ohig = ohig;
59  if (inputrange == 0) {
[acf7d30]60    s->scaler = 0.0;
[f1eda56]61  } else {
62    s->scaler = outputrange/inputrange;
63    if (inputrange < 0) {
64      inputrange = inputrange * -1.0f;
65    }
66  }
[28c162c]67  return AUBIO_OK;
[96fb8ad]68}
69
70void aubio_scale_do (aubio_scale_t *s, fvec_t *input) 
71{
[fc61225]72  uint_t j;
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;
[f1eda56]77  }
[96fb8ad]78}
79
Note: See TracBrowser for help on using the repository browser.