[96fb8ad] | 1 | /* |
---|
[f1eda56] | 2 | Copyright (C) 2003 Paul Brossier |
---|
[96fb8ad] | 3 | |
---|
[f1eda56] | 4 | This program is free software; you can redistribute it and/or modify |
---|
| 5 | it under the terms of the GNU General Public License as published by |
---|
| 6 | the Free Software Foundation; either version 2 of the License, or |
---|
| 7 | (at your option) any later version. |
---|
[96fb8ad] | 8 | |
---|
[f1eda56] | 9 | This program is distributed in the hope that it will be useful, |
---|
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 12 | GNU General Public License for more details. |
---|
| 13 | |
---|
| 14 | You should have received a copy of the GNU General Public License |
---|
| 15 | along with this program; if not, write to the Free Software |
---|
| 16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
[96fb8ad] | 17 | |
---|
[680137a] | 18 | */ |
---|
[96fb8ad] | 19 | |
---|
| 20 | #include "aubio_priv.h" |
---|
[6c7d49b] | 21 | #include "fvec.h" |
---|
[32d6958] | 22 | #include "utils/scale.h" |
---|
[96fb8ad] | 23 | |
---|
| 24 | struct _aubio_scale_t { |
---|
[f1eda56] | 25 | smpl_t ilow; |
---|
| 26 | smpl_t ihig; |
---|
| 27 | smpl_t olow; |
---|
| 28 | smpl_t ohig; |
---|
| 29 | |
---|
| 30 | smpl_t scaler; |
---|
| 31 | smpl_t irange; |
---|
[96fb8ad] | 32 | |
---|
[f1eda56] | 33 | /* not implemented yet : type in/out data |
---|
| 34 | bool inint; |
---|
| 35 | bool outint; |
---|
| 36 | */ |
---|
[96fb8ad] | 37 | }; |
---|
| 38 | |
---|
[f1eda56] | 39 | aubio_scale_t * new_aubio_scale (smpl_t ilow, smpl_t ihig, |
---|
| 40 | smpl_t olow, smpl_t ohig) { |
---|
| 41 | aubio_scale_t * s = AUBIO_NEW(aubio_scale_t); |
---|
| 42 | aubio_scale_set (s, ilow, ihig, olow, ohig); |
---|
| 43 | return s; |
---|
[96fb8ad] | 44 | } |
---|
| 45 | |
---|
| 46 | void del_aubio_scale(aubio_scale_t *s) { |
---|
[f1eda56] | 47 | AUBIO_FREE(s); |
---|
[96fb8ad] | 48 | } |
---|
| 49 | |
---|
[f1eda56] | 50 | void aubio_scale_set (aubio_scale_t *s, smpl_t ilow, smpl_t ihig, |
---|
| 51 | smpl_t olow, smpl_t ohig) { |
---|
| 52 | smpl_t inputrange = ihig - ilow; |
---|
| 53 | smpl_t outputrange= ohig - olow; |
---|
| 54 | s->ilow = ilow; |
---|
| 55 | s->ihig = ihig; |
---|
| 56 | s->olow = olow; |
---|
| 57 | s->ohig = ohig; |
---|
| 58 | if (inputrange == 0) { |
---|
[acf7d30] | 59 | s->scaler = 0.0; |
---|
[f1eda56] | 60 | } else { |
---|
| 61 | s->scaler = outputrange/inputrange; |
---|
| 62 | if (inputrange < 0) { |
---|
| 63 | inputrange = inputrange * -1.0f; |
---|
| 64 | } |
---|
| 65 | } |
---|
[96fb8ad] | 66 | } |
---|
| 67 | |
---|
| 68 | void aubio_scale_do (aubio_scale_t *s, fvec_t *input) |
---|
| 69 | { |
---|
[f1eda56] | 70 | uint_t i, j; |
---|
| 71 | for (i=0; i < input->channels; i++){ |
---|
| 72 | for (j=0; j < input->length; j++){ |
---|
| 73 | input->data[i][j] -= s->ilow; |
---|
| 74 | input->data[i][j] *= s->scaler; |
---|
| 75 | input->data[i][j] += s->olow; |
---|
| 76 | } |
---|
| 77 | } |
---|
[96fb8ad] | 78 | } |
---|
| 79 | |
---|