source: src/utils/parameter.c @ a5762cf

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5
Last change on this file since a5762cf was 33d0242, checked in by Paul Brossier <piem@piem.org>, 8 years ago

src/aubio_priv.h: move include config.h here

  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2  Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org>
3
4  This file is part of aubio.
5
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.
10
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/>.
18
19*/
20
21#include "aubio_priv.h"
22#include "parameter.h"
23
24#define AUBIO_PARAM_MAX_STEPS 2000
25#define AUBIO_PARAM_MIN_STEPS 1
26
27struct _aubio_parameter_t {
28  smpl_t current_value;
29  smpl_t target_value;
30  smpl_t increment;
31
32  smpl_t max_value;
33  smpl_t min_value;
34
35  uint_t steps;
36};
37
38aubio_parameter_t * new_aubio_parameter (smpl_t min_value, smpl_t max_value, uint_t steps )
39{
40  aubio_parameter_t * param = AUBIO_NEW(aubio_parameter_t);
41
42  param->min_value = min_value;
43  param->max_value = max_value;
44  param->steps = steps;
45
46  param->current_value = param->min_value;
47  param->target_value = param->current_value;
48  param->increment = 0.;
49
50  return param;
51}
52
53uint_t aubio_parameter_set_target_value ( aubio_parameter_t * param, smpl_t value )
54{
55  uint_t err = AUBIO_OK;
56  if (value < param->min_value ) {
57    param->target_value = param->min_value;
58    err = AUBIO_FAIL;
59  } else if ( value > param->max_value ) {
60    param->target_value = param->max_value;
61    err = AUBIO_FAIL;
62  } else {
63    param->target_value = value;
64  }
65  param->increment = ( param->target_value - param->current_value ) / param->steps;
66  return err;
67}
68
69uint_t aubio_parameter_set_current_value ( aubio_parameter_t * param, smpl_t value )
70{
71  uint_t err = AUBIO_OK;
72  if (value < param->min_value ) {
73    param->current_value = param->min_value;
74    err = AUBIO_FAIL;
75  } else if ( value > param->max_value ) {
76    param->current_value = param->max_value;
77    err = AUBIO_FAIL;
78  } else {
79    param->current_value = value;
80  }
81  param->target_value = param->current_value;
82  param->increment = 0;
83  return err;
84}
85
86smpl_t aubio_parameter_get_current_value ( const aubio_parameter_t * s )
87{
88  return s->current_value;
89}
90
91smpl_t aubio_parameter_get_next_value ( aubio_parameter_t * s )
92{
93  if ( ABS(s->current_value - s->target_value) > ABS(s->increment) ) {
94    s->current_value += s->increment;
95  } else {
96    s->current_value = s->target_value;
97  }
98  return s->current_value;
99}
100
101uint_t aubio_parameter_set_steps ( aubio_parameter_t * param, uint_t steps )
102{
103  if (steps < AUBIO_PARAM_MIN_STEPS || steps > AUBIO_PARAM_MAX_STEPS) {
104    return AUBIO_FAIL;
105  }
106  param->steps = steps;
107  param->increment = ( param->target_value - param->current_value ) / param->steps;
108  return AUBIO_OK;
109}
110
111uint_t aubio_parameter_get_steps ( const aubio_parameter_t * param )
112{
113  return param->steps;
114}
115
116uint_t aubio_parameter_set_min_value ( aubio_parameter_t * param, smpl_t min_value )
117{
118  param->min_value = min_value;
119  return AUBIO_OK;
120}
121
122smpl_t aubio_parameter_get_min_value ( const aubio_parameter_t * param )
123{
124  return param->min_value;
125}
126
127uint_t aubio_parameter_set_max_value ( aubio_parameter_t * param, smpl_t max_value )
128{
129  param->max_value = max_value;
130  return AUBIO_OK;
131}
132
133smpl_t aubio_parameter_get_max_value ( const aubio_parameter_t * param )
134{
135  return param->max_value;
136}
137
138void del_aubio_parameter ( aubio_parameter_t * param )
139{
140  AUBIO_FREE(param);
141}
Note: See TracBrowser for help on using the repository browser.