source: src/scale.c @ e604630

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since e604630 was 680137a, checked in by Paul Brossier <piem@altern.org>, 18 years ago

update scale.[ch] docs
update scale.[ch] docs

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/*
2         Copyright (C) 2003 Paul Brossier
3
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.
8
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.
17*/
18
19#include "aubio_priv.h"
20#include "sample.h"
21#include "scale.h"
22
23struct _aubio_scale_t {
24        smpl_t ilow;
25        smpl_t ihig;
26        smpl_t olow;
27        smpl_t ohig;
28
29        smpl_t scaler;
30        smpl_t irange;
31       
32        /* not implemented yet : type in/out data
33        bool inint;
34        bool outint;
35        */
36};
37
38static aubio_scale_t * aubio_scale_malloc(void);
39static void aubio_scale_free(aubio_scale_t * s);
40
41aubio_scale_t * aubio_scale_malloc() {
42        aubio_scale_t * s = AUBIO_NEW(aubio_scale_t);
43        return s;
44}
45
46void aubio_scale_free(aubio_scale_t * s) {
47        AUBIO_FREE(s);
48}
49
50aubio_scale_t * new_aubio_scale (smpl_t ilow, smpl_t ihig, smpl_t olow, smpl_t ohig     ){
51        aubio_scale_t * s = aubio_scale_malloc();
52        aubio_scale_set (s, ilow, ihig, olow, ohig);
53        return s;       
54}
55
56void del_aubio_scale(aubio_scale_t *s) {
57        aubio_scale_free(s);
58}
59
60void aubio_scale_set (aubio_scale_t *s, smpl_t ilow, smpl_t ihig, smpl_t olow, smpl_t ohig) 
61{
62        smpl_t inputrange = ihig - ilow;
63        smpl_t outputrange= ohig - olow;
64        s->ilow = ilow;
65        s->ihig = ihig;
66        s->olow = olow;
67        s->ohig = ohig;
68        if (inputrange == 0 )
69                s->scaler = 0.0f;
70        else {
71                s->scaler = outputrange/inputrange;
72                if (inputrange < 0 )
73                        inputrange = inputrange * -1.0f;
74        }
75}
76
77void aubio_scale_do (aubio_scale_t *s, fvec_t *input) 
78{
79        uint_t i, j;
80        for (i=0; i < input->channels; i++){
81                for (j=0;  j < input->length; j++){
82                        input->data[i][j] -= s->ilow;
83                        input->data[i][j] *= s->scaler;
84                        input->data[i][j] += s->olow;
85                }
86        }
87}
88
Note: See TracBrowser for help on using the repository browser.