source: src/cvec.h @ 39a7b26

feature/autosinkfeature/constantqfeature/pitchshiftfeature/pydocstringsfeature/timestretchpitchshiftsamplertimestretchyinfft+
Last change on this file since 39a7b26 was 39a7b26, checked in by Paul Brossier <piem@piem.org>, 6 years ago

src/cvec.h: improve cvec_t api

  • Property mode set to 100644
File size: 5.5 KB
RevLine 
[d1ec8cb]1/*
[a6db140]2  Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
[d1ec8cb]3
[a6db140]4  This file is part of aubio.
[d1ec8cb]5
[a6db140]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.
[d1ec8cb]10
[a6db140]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/>.
[d1ec8cb]18
19*/
20
21#ifndef _CVEC_H
[2382036]22#define _CVEC_H
[d1ec8cb]23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28/** \file
29
[621f1ff]30  Vector of complex-valued data
[d1ec8cb]31
[621f1ff]32  This file specifies the ::cvec_t buffer type, which is used throughout aubio
33  to store complex data. Complex values are stored in terms of ::cvec_t.phas
34  and norm, within size/2+1 long vectors of ::smpl_t.
35
36  \example test-cvec.c
[d1ec8cb]37
38*/
39
[f72364d]40/** Buffer for complex data
41
42  \code
43
44  uint_t buffer_size = 1024;
45
46  // create a complex vector of 512 values
47  cvec_t * input = new_cvec (buffer_size);
48
49  // set some values of the vector
50  input->norm[23] = 2.;
51  input->phas[23] = M_PI;
52  // ..
53
54  // compute the mean of the vector
55  mean = cvec_mean(input);
56
57  // destroy the vector
58  del_cvec (input);
59
60  \endcode
61
62 */
[78429de]63typedef struct {
[621f1ff]64  uint_t length;  /**< length of buffer = (requested length)/2 + 1 */
65  smpl_t *norm;   /**< norm array of size ::cvec_t.length */
66  smpl_t *phas;   /**< phase array of size ::cvec_t.length */
[78429de]67} cvec_t;
[d1ec8cb]68
69/** cvec_t buffer creation function
70
71  This function creates a cvec_t structure holding two arrays of size
[66fb3ea]72  [length/2+1], corresponding to the norm and phase values of the
[d1ec8cb]73  spectral frame. The length stored in the structure is the actual size of both
[621f1ff]74  arrays, not the length of the complex and symmetrical vector, specified as
[d1ec8cb]75  creation argument.
76
77  \param length the length of the buffer to create
78
79*/
[66fb3ea]80cvec_t * new_cvec(uint_t length);
[d1ec8cb]81/** cvec_t buffer deletion function
82
83  \param s buffer to delete as returned by new_cvec()
84
85*/
86void del_cvec(cvec_t *s);
87/** write norm value in a complex buffer
88
89  Note that this function is not used in the aubio library, since the same
[66fb3ea]90  result can be obtained by assigning vec->norm[position]. Its purpose
[d1ec8cb]91  is to access these values from wrappers, as created by swig.
92
[f72364d]93  \param s vector to write to
[66fb3ea]94  \param data norm value to write in s->norm[position]
[d1ec8cb]95  \param position sample position to write to
96
97*/
[66fb3ea]98void cvec_write_norm(cvec_t *s, smpl_t data, uint_t position);
[d1ec8cb]99/** write phase value in a complex buffer
100
101  Note that this function is not used in the aubio library, since the same
[66fb3ea]102  result can be obtained by assigning vec->phas[position]. Its purpose
[d1ec8cb]103  is to access these values from wrappers, as created by swig.
104
105  \param s vector to write to
[66fb3ea]106  \param data phase value to write in s->phas[position]
[d1ec8cb]107  \param position sample position to write to
108
109*/
[66fb3ea]110void cvec_write_phas(cvec_t *s, smpl_t data, uint_t position);
[d1ec8cb]111/** read norm value from a complex buffer
112
113  Note that this function is not used in the aubio library, since the same
[66fb3ea]114  result can be obtained with vec->norm[position]. Its purpose is to
[d1ec8cb]115  access these values from wrappers, as created by swig.
116
117  \param s vector to read from
118  \param position sample position to read from
119
120*/
[66fb3ea]121smpl_t cvec_read_norm(cvec_t *s, uint_t position);
[d1ec8cb]122/** read phase value from a complex buffer
123
124  Note that this function is not used in the aubio library, since the same
[66fb3ea]125  result can be obtained with vec->phas[position]. Its purpose is to
[d1ec8cb]126  access these values from wrappers, as created by swig.
127
128  \param s vector to read from
129  \param position sample position to read from
130
131*/
[66fb3ea]132smpl_t cvec_read_phas(cvec_t *s, uint_t position);
[d1ec8cb]133/** read norm data from a complex buffer
134
135  Note that this function is not used in the aubio library, since the same
136  result can be obtained with vec->norm. Its purpose is to access these values
137  from wrappers, as created by swig.
138
139  \param s vector to read from
140
141*/
[66fb3ea]142smpl_t * cvec_get_norm(cvec_t *s);
[d1ec8cb]143/** read phase data from a complex buffer
144
145  Note that this function is not used in the aubio library, since the same
146  result can be obtained with vec->phas. Its purpose is to access these values
147  from wrappers, as created by swig.
148
149  \param s vector to read from
150
151*/
[66fb3ea]152smpl_t * cvec_get_phas(cvec_t *s);
[d1ec8cb]153
[f72364d]154/** print out cvec data
[55b7cb4]155
[f72364d]156  \param s vector to print out
[55b7cb4]157
158*/
159void cvec_print(cvec_t *s);
160
[39a7b26]161/** make a copy of a vector
162
163  \param s source vector
164  \param t vector to copy to
165
166*/
167void cvec_copy(cvec_t *s, cvec_t *t);
168
169/** set all norm elements to a given value
[012466b]170
171  \param s vector to modify
172  \param val value to set elements to
173
174*/
[39a7b26]175void cvec_set_all_norm(cvec_t *s, smpl_t val);
[012466b]176
[39a7b26]177/** set all norm elements to zero
[012466b]178
179  \param s vector to modify
180
181*/
[39a7b26]182void cvec_zeros_norm(cvec_t *s);
183
184/** set all norm elements to one
185
186  \param s vector to modify
187
188*/
189void cvec_ones_norm(cvec_t *s);
[012466b]190
[39a7b26]191/** set all phase elements to a given value
[012466b]192
193  \param s vector to modify
[39a7b26]194  \param val value to set elements to
[012466b]195
196*/
[39a7b26]197void cvec_set_all_phas(cvec_t *s, smpl_t val);
198
199/** set all phase elements to zero
200
201  \param s vector to modify
202
203*/
204void cvec_zeros_phas(cvec_t *s);
205
206/** set all phase elements to one
207
208  \param s vector to modify
209
210*/
211void cvec_ones_phas(cvec_t *s);
212
213/** set all norm and phas elements to zero
214
215  \param s vector to modify
216
217*/
218void cvec_zeros(cvec_t *s);
[012466b]219
[d1ec8cb]220#ifdef __cplusplus
221}
222#endif
223
224#endif /* _CVEC_H */
225
Note: See TracBrowser for help on using the repository browser.