source: src/scale.c @ 9499a546

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 9499a546 was 96fb8ad, checked in by Paul Brossier <piem@altern.org>, 20 years ago

import 0.1.7.1

  • Property mode set to 100644
File size: 2.3 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
38
39/********************************************************
40 * Object Memory Allocation
41 */
42
43static aubio_scale_t * aubio_scale_malloc(void);
44static void aubio_scale_free(aubio_scale_t * s);
45
46aubio_scale_t * aubio_scale_malloc() {
47        aubio_scale_t * s = AUBIO_NEW(aubio_scale_t);
48        return s;
49}
50
51void aubio_scale_free(aubio_scale_t * s) {
52        AUBIO_FREE(s);
53}
54
55/***
56 * Object creation/deletion calls
57 */
58aubio_scale_t * new_aubio_scale (smpl_t ilow, smpl_t ihig, smpl_t olow, smpl_t ohig     ){
59        aubio_scale_t * s = aubio_scale_malloc();
60        aubio_scale_set (s, ilow, ihig, olow, ohig);
61        return s;       
62}
63
64void del_aubio_scale(aubio_scale_t *s) {
65        aubio_scale_free(s);
66}
67
68/***
69 * set parmams
70 */
71void aubio_scale_set (aubio_scale_t *s, smpl_t ilow, smpl_t ihig, smpl_t olow, smpl_t ohig) 
72{
73        smpl_t inputrange = ihig - ilow;
74        smpl_t outputrange= ohig - olow;
75        s->ilow = ilow;
76        s->ihig = ihig;
77        s->olow = olow;
78        s->ohig = ohig;
79        if (inputrange == 0 )
80                s->scaler = 0.0f;
81        else {
82                s->scaler = outputrange/inputrange;
83                if (inputrange < 0 )
84                        inputrange = inputrange * -1.0f;
85        }
86}
87
88/***
89 * do it
90 */
91void aubio_scale_do (aubio_scale_t *s, fvec_t *input) 
92{
93        uint_t i, j;
94        for (i=0; i < input->channels; i++){
95                for (j=0;  j < input->length; j++){
96                        input->data[i][j] -= s->ilow;
97                        input->data[i][j] *= s->scaler;
98                        input->data[i][j] += s->olow;
99                }
100        }
101}
102
Note: See TracBrowser for help on using the repository browser.