src/fvec.h: clean up fvec api
[aubio.git] / src / fvec.h
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 #ifndef _AUBIO__FVEC_H
22 #define _AUBIO__FVEC_H
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 /** \file
29
30   Vector of real-valued data
31
32   This file specifies the ::fvec_t buffer type, which is used throughout aubio
33   to store vector of real-valued ::smpl_t.
34
35   \example test-fvec.c
36
37 */
38
39 /** Buffer for real data
40
41   Vector of real-valued data
42
43   ::fvec_t is is the structure used to store vector of real-valued data, ::smpl_t .
44
45   \code
46
47   uint_t buffer_size = 1024;
48
49   // create a vector of 512 values
50   fvec_t * input = new_fvec (buffer_size);
51
52   // set some values of the vector
53   input->data[23] = 2.;
54   // ..
55
56   // compute the mean of the vector
57   mean = fvec_mean(a_vector);
58
59   // destroy the vector
60   del_fvec(a_vector);
61
62   \endcode
63
64   See `examples/` and `tests/src` directories for more examples.
65
66  */
67 typedef struct {
68   uint_t length;  /**< length of buffer */
69   smpl_t *data;   /**< data vector of length ::fvec_t.length */
70 } fvec_t;
71
72 /** fvec_t buffer creation function
73
74   \param length the length of the buffer to create
75
76 */
77 fvec_t * new_fvec(uint_t length);
78
79 /** fvec_t buffer deletion function
80
81   \param s buffer to delete as returned by new_fvec()
82
83 */
84 void del_fvec(fvec_t *s);
85
86 /** read sample value in a buffer
87
88   Note that this function is not used in the aubio library, since the same
89   result can be obtained using vec->data[position]. Its purpose is to
90   access these values from wrappers, as created by swig.
91
92   \param s vector to read from
93   \param position sample position to read from 
94
95 */
96 smpl_t fvec_get_sample(fvec_t *s, uint_t position);
97
98 /** write sample value in a buffer
99
100   Note that this function is not used in the aubio library, since the same
101   result can be obtained by assigning vec->data[position]. Its purpose
102   is to access these values from wrappers, as created by swig.
103
104   \param s vector to write to 
105   \param data value to write in s->data[position]
106   \param position sample position to write to 
107
108 */
109 void  fvec_set_sample(fvec_t *s, smpl_t data, uint_t position);
110
111 /** read data from a buffer
112
113   Note that this function is not used in the aubio library, since the same
114   result can be obtained with vec->data. Its purpose is to access these values
115   from wrappers, as created by swig.
116
117   \param s vector to read from
118
119 */
120 smpl_t * fvec_get_data(fvec_t *s);
121
122 /** print out fvec data 
123
124   \param s vector to print out 
125
126 */
127 void fvec_print(fvec_t *s);
128
129 /** set all elements to a given value
130
131   \param s vector to modify
132   \param val value to set elements to
133
134 */
135 void fvec_set_all (fvec_t *s, smpl_t val);
136
137 /** set all elements to zero 
138
139   \param s vector to modify
140
141 */
142 void fvec_zeros(fvec_t *s);
143
144 /** set all elements to ones 
145
146   \param s vector to modify
147
148 */
149 void fvec_ones(fvec_t *s);
150
151 /** revert order of vector elements
152
153   \param s vector to revert
154
155 */
156 void fvec_rev(fvec_t *s);
157
158 /** apply weight to vector
159
160   If the weight vector is longer than s, only the first elements are used. If
161   the weight vector is shorter than s, the last elements of s are not weighted.
162
163   \param s vector to weight
164   \param weight weighting coefficients
165
166 */
167 void fvec_weight(fvec_t *s, fvec_t *weight);
168
169 /** make a copy of a vector
170
171   \param s source vector
172   \param t vector to copy to
173
174 */
175 void fvec_copy(fvec_t *s, fvec_t *t);
176
177 #ifdef __cplusplus
178 }
179 #endif
180
181 #endif /* _AUBIO__FVEC_H */