[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 | |
---|
[b235c0e] | 21 | #ifndef _AUBIO__FVEC_H |
---|
| 22 | #define _AUBIO__FVEC_H |
---|
[d1ec8cb] | 23 | |
---|
| 24 | #ifdef __cplusplus |
---|
| 25 | extern "C" { |
---|
| 26 | #endif |
---|
| 27 | |
---|
| 28 | /** \file |
---|
| 29 | |
---|
[f72364d] | 30 | Vector of real-valued data |
---|
[d1ec8cb] | 31 | |
---|
[f72364d] | 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 |
---|
[d1ec8cb] | 36 | |
---|
| 37 | */ |
---|
| 38 | |
---|
[f72364d] | 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 | */ |
---|
[78429de] | 67 | typedef struct { |
---|
[f72364d] | 68 | uint_t length; /**< length of buffer */ |
---|
| 69 | smpl_t *data; /**< data vector of length ::fvec_t.length */ |
---|
[78429de] | 70 | } fvec_t; |
---|
| 71 | |
---|
[d1ec8cb] | 72 | /** fvec_t buffer creation function |
---|
| 73 | |
---|
| 74 | \param length the length of the buffer to create |
---|
| 75 | |
---|
| 76 | */ |
---|
[c7860af] | 77 | fvec_t * new_fvec(uint_t length); |
---|
[c34336e] | 78 | |
---|
[d1ec8cb] | 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); |
---|
[c34336e] | 85 | |
---|
[d1ec8cb] | 86 | /** read sample value in a buffer |
---|
| 87 | |
---|
| 88 | \param s vector to read from |
---|
[0683ee2] | 89 | \param position sample position to read from |
---|
[d1ec8cb] | 90 | |
---|
| 91 | */ |
---|
[1120f86] | 92 | smpl_t fvec_get_sample(const fvec_t *s, uint_t position); |
---|
[c34336e] | 93 | |
---|
[d1ec8cb] | 94 | /** write sample value in a buffer |
---|
| 95 | |
---|
[0683ee2] | 96 | \param s vector to write to |
---|
[c7860af] | 97 | \param data value to write in s->data[position] |
---|
[0683ee2] | 98 | \param position sample position to write to |
---|
[d1ec8cb] | 99 | |
---|
| 100 | */ |
---|
[c34336e] | 101 | void fvec_set_sample(fvec_t *s, smpl_t data, uint_t position); |
---|
[d1ec8cb] | 102 | |
---|
| 103 | /** read data from a buffer |
---|
| 104 | |
---|
| 105 | \param s vector to read from |
---|
| 106 | |
---|
| 107 | */ |
---|
[1120f86] | 108 | smpl_t * fvec_get_data(const fvec_t *s); |
---|
[d1ec8cb] | 109 | |
---|
[0683ee2] | 110 | /** print out fvec data |
---|
[32f5a01] | 111 | |
---|
[0683ee2] | 112 | \param s vector to print out |
---|
[32f5a01] | 113 | |
---|
| 114 | */ |
---|
[1120f86] | 115 | void fvec_print(const fvec_t *s); |
---|
[32f5a01] | 116 | |
---|
[3b2d32c] | 117 | /** set all elements to a given value |
---|
| 118 | |
---|
| 119 | \param s vector to modify |
---|
| 120 | \param val value to set elements to |
---|
| 121 | |
---|
| 122 | */ |
---|
[c34336e] | 123 | void fvec_set_all (fvec_t *s, smpl_t val); |
---|
[3b2d32c] | 124 | |
---|
[0683ee2] | 125 | /** set all elements to zero |
---|
[3b2d32c] | 126 | |
---|
| 127 | \param s vector to modify |
---|
| 128 | |
---|
| 129 | */ |
---|
| 130 | void fvec_zeros(fvec_t *s); |
---|
| 131 | |
---|
[0683ee2] | 132 | /** set all elements to ones |
---|
[3b2d32c] | 133 | |
---|
| 134 | \param s vector to modify |
---|
| 135 | |
---|
| 136 | */ |
---|
| 137 | void fvec_ones(fvec_t *s); |
---|
| 138 | |
---|
| 139 | /** revert order of vector elements |
---|
| 140 | |
---|
| 141 | \param s vector to revert |
---|
| 142 | |
---|
| 143 | */ |
---|
| 144 | void fvec_rev(fvec_t *s); |
---|
| 145 | |
---|
| 146 | /** apply weight to vector |
---|
| 147 | |
---|
| 148 | If the weight vector is longer than s, only the first elements are used. If |
---|
| 149 | the weight vector is shorter than s, the last elements of s are not weighted. |
---|
| 150 | |
---|
| 151 | \param s vector to weight |
---|
| 152 | \param weight weighting coefficients |
---|
| 153 | |
---|
| 154 | */ |
---|
[1120f86] | 155 | void fvec_weight(fvec_t *s, const fvec_t *weight); |
---|
[3b2d32c] | 156 | |
---|
| 157 | /** make a copy of a vector |
---|
| 158 | |
---|
| 159 | \param s source vector |
---|
| 160 | \param t vector to copy to |
---|
| 161 | |
---|
| 162 | */ |
---|
[1120f86] | 163 | void fvec_copy(const fvec_t *s, fvec_t *t); |
---|
[3b2d32c] | 164 | |
---|
[7166ef8] | 165 | /** make a copy of a vector, applying weights to each element |
---|
| 166 | |
---|
| 167 | \param in input vector |
---|
| 168 | \param weight weights vector |
---|
| 169 | \param out output vector |
---|
| 170 | |
---|
| 171 | */ |
---|
[1120f86] | 172 | void fvec_weighted_copy(const fvec_t *in, const fvec_t *weight, fvec_t *out); |
---|
[7166ef8] | 173 | |
---|
[d1ec8cb] | 174 | #ifdef __cplusplus |
---|
| 175 | } |
---|
| 176 | #endif |
---|
| 177 | |
---|
[b235c0e] | 178 | #endif /* _AUBIO__FVEC_H */ |
---|