[d1ec8cb] | 1 | /* |
---|
[0683ee2] | 2 | Copyright (C) 2003-2015 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 | |
---|
[6f42c16] | 21 | #ifndef AUBIO_CVEC_H |
---|
| 22 | #define AUBIO_CVEC_H |
---|
[d1ec8cb] | 23 | |
---|
| 24 | #ifdef __cplusplus |
---|
| 25 | extern "C" { |
---|
| 26 | #endif |
---|
| 27 | |
---|
| 28 | /** \file |
---|
| 29 | |
---|
[5d10ac1] | 30 | Vector of complex-valued data, stored in polar coordinates |
---|
[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 |
---|
[5d10ac1] | 34 | and norm, within 2 vectors of ::smpl_t of size (size/2+1) each. |
---|
[621f1ff] | 35 | |
---|
| 36 | \example test-cvec.c |
---|
[d1ec8cb] | 37 | |
---|
| 38 | */ |
---|
| 39 | |
---|
[5d10ac1] | 40 | /** Vector of real-valued phase and spectrum data |
---|
[f72364d] | 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] | 63 | typedef 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] | 80 | cvec_t * new_cvec(uint_t length); |
---|
[5d10ac1] | 81 | |
---|
[d1ec8cb] | 82 | /** cvec_t buffer deletion function |
---|
| 83 | |
---|
| 84 | \param s buffer to delete as returned by new_cvec() |
---|
| 85 | |
---|
| 86 | */ |
---|
| 87 | void del_cvec(cvec_t *s); |
---|
[5d10ac1] | 88 | |
---|
[d1ec8cb] | 89 | /** write norm value in a complex buffer |
---|
| 90 | |
---|
[5d10ac1] | 91 | This is equivalent to: |
---|
| 92 | \code |
---|
| 93 | s->norm[position] = val; |
---|
| 94 | \endcode |
---|
[d1ec8cb] | 95 | |
---|
[f72364d] | 96 | \param s vector to write to |
---|
[5d10ac1] | 97 | \param val norm value to write in s->norm[position] |
---|
[d1ec8cb] | 98 | \param position sample position to write to |
---|
| 99 | |
---|
| 100 | */ |
---|
[5d10ac1] | 101 | void cvec_norm_set_sample (cvec_t *s, smpl_t val, uint_t position); |
---|
| 102 | |
---|
[d1ec8cb] | 103 | /** write phase value in a complex buffer |
---|
| 104 | |
---|
[5d10ac1] | 105 | This is equivalent to: |
---|
| 106 | \code |
---|
| 107 | s->phas[position] = val; |
---|
| 108 | \endcode |
---|
[d1ec8cb] | 109 | |
---|
| 110 | \param s vector to write to |
---|
[5d10ac1] | 111 | \param val phase value to write in s->phas[position] |
---|
[d1ec8cb] | 112 | \param position sample position to write to |
---|
| 113 | |
---|
| 114 | */ |
---|
[5d10ac1] | 115 | void cvec_phas_set_sample (cvec_t *s, smpl_t val, uint_t position); |
---|
| 116 | |
---|
[d1ec8cb] | 117 | /** read norm value from a complex buffer |
---|
| 118 | |
---|
[5d10ac1] | 119 | This is equivalent to: |
---|
| 120 | \code |
---|
| 121 | smpl_t foo = s->norm[position]; |
---|
| 122 | \endcode |
---|
[d1ec8cb] | 123 | |
---|
| 124 | \param s vector to read from |
---|
| 125 | \param position sample position to read from |
---|
| 126 | |
---|
| 127 | */ |
---|
[5d10ac1] | 128 | smpl_t cvec_norm_get_sample (cvec_t *s, uint_t position); |
---|
| 129 | |
---|
[d1ec8cb] | 130 | /** read phase value from a complex buffer |
---|
| 131 | |
---|
[5d10ac1] | 132 | This is equivalent to: |
---|
| 133 | \code |
---|
| 134 | smpl_t foo = s->phas[position]; |
---|
| 135 | \endcode |
---|
[d1ec8cb] | 136 | |
---|
| 137 | \param s vector to read from |
---|
| 138 | \param position sample position to read from |
---|
[5d10ac1] | 139 | \returns the value of the sample at position |
---|
[d1ec8cb] | 140 | |
---|
| 141 | */ |
---|
[5d10ac1] | 142 | smpl_t cvec_phas_get_sample (cvec_t *s, uint_t position); |
---|
| 143 | |
---|
[d1ec8cb] | 144 | /** read norm data from a complex buffer |
---|
| 145 | |
---|
[5d10ac1] | 146 | \code |
---|
| 147 | smpl_t *data = s->norm; |
---|
| 148 | \endcode |
---|
[d1ec8cb] | 149 | |
---|
| 150 | \param s vector to read from |
---|
| 151 | |
---|
| 152 | */ |
---|
[1120f86] | 153 | smpl_t * cvec_norm_get_data (const cvec_t *s); |
---|
[5d10ac1] | 154 | |
---|
[d1ec8cb] | 155 | /** read phase data from a complex buffer |
---|
| 156 | |
---|
[5d10ac1] | 157 | This is equivalent to: |
---|
| 158 | \code |
---|
| 159 | smpl_t *data = s->phas; |
---|
| 160 | \endcode |
---|
[d1ec8cb] | 161 | |
---|
| 162 | \param s vector to read from |
---|
| 163 | |
---|
| 164 | */ |
---|
[1120f86] | 165 | smpl_t * cvec_phas_get_data (const cvec_t *s); |
---|
[d1ec8cb] | 166 | |
---|
[f72364d] | 167 | /** print out cvec data |
---|
[55b7cb4] | 168 | |
---|
[f72364d] | 169 | \param s vector to print out |
---|
[55b7cb4] | 170 | |
---|
| 171 | */ |
---|
[1120f86] | 172 | void cvec_print(const cvec_t *s); |
---|
[55b7cb4] | 173 | |
---|
[39a7b26] | 174 | /** make a copy of a vector |
---|
| 175 | |
---|
| 176 | \param s source vector |
---|
| 177 | \param t vector to copy to |
---|
| 178 | |
---|
| 179 | */ |
---|
[1120f86] | 180 | void cvec_copy(const cvec_t *s, cvec_t *t); |
---|
[39a7b26] | 181 | |
---|
| 182 | /** set all norm elements to a given value |
---|
[012466b] | 183 | |
---|
| 184 | \param s vector to modify |
---|
| 185 | \param val value to set elements to |
---|
| 186 | |
---|
| 187 | */ |
---|
[5d10ac1] | 188 | void cvec_norm_set_all (cvec_t *s, smpl_t val); |
---|
[012466b] | 189 | |
---|
[39a7b26] | 190 | /** set all norm elements to zero |
---|
[012466b] | 191 | |
---|
| 192 | \param s vector to modify |
---|
| 193 | |
---|
| 194 | */ |
---|
[5d10ac1] | 195 | void cvec_norm_zeros(cvec_t *s); |
---|
[39a7b26] | 196 | |
---|
| 197 | /** set all norm elements to one |
---|
| 198 | |
---|
| 199 | \param s vector to modify |
---|
| 200 | |
---|
| 201 | */ |
---|
[5d10ac1] | 202 | void cvec_norm_ones(cvec_t *s); |
---|
[012466b] | 203 | |
---|
[39a7b26] | 204 | /** set all phase elements to a given value |
---|
[012466b] | 205 | |
---|
| 206 | \param s vector to modify |
---|
[39a7b26] | 207 | \param val value to set elements to |
---|
[012466b] | 208 | |
---|
| 209 | */ |
---|
[5d10ac1] | 210 | void cvec_phas_set_all (cvec_t *s, smpl_t val); |
---|
[39a7b26] | 211 | |
---|
| 212 | /** set all phase elements to zero |
---|
| 213 | |
---|
| 214 | \param s vector to modify |
---|
| 215 | |
---|
| 216 | */ |
---|
[5d10ac1] | 217 | void cvec_phas_zeros(cvec_t *s); |
---|
[39a7b26] | 218 | |
---|
| 219 | /** set all phase elements to one |
---|
| 220 | |
---|
| 221 | \param s vector to modify |
---|
| 222 | |
---|
| 223 | */ |
---|
[5d10ac1] | 224 | void cvec_phas_ones(cvec_t *s); |
---|
[39a7b26] | 225 | |
---|
| 226 | /** set all norm and phas elements to zero |
---|
| 227 | |
---|
| 228 | \param s vector to modify |
---|
| 229 | |
---|
| 230 | */ |
---|
| 231 | void cvec_zeros(cvec_t *s); |
---|
[012466b] | 232 | |
---|
[d1ec8cb] | 233 | #ifdef __cplusplus |
---|
| 234 | } |
---|
| 235 | #endif |
---|
| 236 | |
---|
[6f42c16] | 237 | #endif /* AUBIO_CVEC_H */ |
---|