2 Copyright (C) 2003-2015 Paul Brossier <piem@aubio.org>
4 This file is part of aubio.
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.
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.
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/>.
30 Vector of complex-valued data, stored in polar coordinates
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 2 vectors of ::smpl_t of size (size/2+1) each.
40 /** Vector of real-valued phase and spectrum data
44 uint_t buffer_size = 1024;
46 // create a complex vector of 512 values
47 cvec_t * input = new_cvec (buffer_size);
49 // set some values of the vector
51 input->phas[23] = M_PI;
54 // compute the mean of the vector
55 mean = cvec_mean(input);
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 */
69 /** cvec_t buffer creation function
71 This function creates a cvec_t structure holding two arrays of size
72 [length/2+1], corresponding to the norm and phase values of the
73 spectral frame. The length stored in the structure is the actual size of both
74 arrays, not the length of the complex and symmetrical vector, specified as
77 \param length the length of the buffer to create
80 cvec_t * new_cvec(uint_t length);
82 /** cvec_t buffer deletion function
84 \param s buffer to delete as returned by new_cvec()
87 void del_cvec(cvec_t *s);
89 /** write norm value in a complex buffer
91 This is equivalent to:
93 s->norm[position] = val;
96 \param s vector to write to
97 \param val norm value to write in s->norm[position]
98 \param position sample position to write to
101 void cvec_norm_set_sample (cvec_t *s, smpl_t val, uint_t position);
103 /** write phase value in a complex buffer
105 This is equivalent to:
107 s->phas[position] = val;
110 \param s vector to write to
111 \param val phase value to write in s->phas[position]
112 \param position sample position to write to
115 void cvec_phas_set_sample (cvec_t *s, smpl_t val, uint_t position);
117 /** read norm value from a complex buffer
119 This is equivalent to:
121 smpl_t foo = s->norm[position];
124 \param s vector to read from
125 \param position sample position to read from
128 smpl_t cvec_norm_get_sample (cvec_t *s, uint_t position);
130 /** read phase value from a complex buffer
132 This is equivalent to:
134 smpl_t foo = s->phas[position];
137 \param s vector to read from
138 \param position sample position to read from
139 \returns the value of the sample at position
142 smpl_t cvec_phas_get_sample (cvec_t *s, uint_t position);
144 /** read norm data from a complex buffer
147 smpl_t *data = s->norm;
150 \param s vector to read from
153 smpl_t * cvec_norm_get_data (const cvec_t *s);
155 /** read phase data from a complex buffer
157 This is equivalent to:
159 smpl_t *data = s->phas;
162 \param s vector to read from
165 smpl_t * cvec_phas_get_data (const cvec_t *s);
167 /** print out cvec data
169 \param s vector to print out
172 void cvec_print(const cvec_t *s);
174 /** make a copy of a vector
176 \param s source vector
177 \param t vector to copy to
180 void cvec_copy(const cvec_t *s, cvec_t *t);
182 /** set all norm elements to a given value
184 \param s vector to modify
185 \param val value to set elements to
188 void cvec_norm_set_all (cvec_t *s, smpl_t val);
190 /** set all norm elements to zero
192 \param s vector to modify
195 void cvec_norm_zeros(cvec_t *s);
197 /** set all norm elements to one
199 \param s vector to modify
202 void cvec_norm_ones(cvec_t *s);
204 /** set all phase elements to a given value
206 \param s vector to modify
207 \param val value to set elements to
210 void cvec_phas_set_all (cvec_t *s, smpl_t val);
212 /** set all phase elements to zero
214 \param s vector to modify
217 void cvec_phas_zeros(cvec_t *s);
219 /** set all phase elements to one
221 \param s vector to modify
224 void cvec_phas_ones(cvec_t *s);
226 /** set all norm and phas elements to zero
228 \param s vector to modify
231 void cvec_zeros(cvec_t *s);
237 #endif /* AUBIO_CVEC_H */