aubio  0.4.1
fvec.h
Go to the documentation of this file.
00001 /*
00002   Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org>
00003 
00004   This file is part of aubio.
00005 
00006   aubio is free software: you can redistribute it and/or modify
00007   it under the terms of the GNU General Public License as published by
00008   the Free Software Foundation, either version 3 of the License, or
00009   (at your option) any later version.
00010 
00011   aubio is distributed in the hope that it will be useful,
00012   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014   GNU General Public License for more details.
00015 
00016   You should have received a copy of the GNU General Public License
00017   along with aubio.  If not, see <http://www.gnu.org/licenses/>.
00018 
00019 */
00020 
00021 #ifndef _AUBIO__FVEC_H
00022 #define _AUBIO__FVEC_H
00023 
00024 #ifdef __cplusplus
00025 extern "C" {
00026 #endif
00027 
00028 /** \file
00029 
00030   Vector of real-valued data
00031 
00032   This file specifies the ::fvec_t buffer type, which is used throughout aubio
00033   to store vector of real-valued ::smpl_t.
00034 
00035   \example test-fvec.c
00036 
00037 */
00038 
00039 /** Buffer for real data
00040 
00041   Vector of real-valued data
00042 
00043   ::fvec_t is is the structure used to store vector of real-valued data, ::smpl_t .
00044 
00045   \code
00046 
00047   uint_t buffer_size = 1024;
00048 
00049   // create a vector of 512 values
00050   fvec_t * input = new_fvec (buffer_size);
00051 
00052   // set some values of the vector
00053   input->data[23] = 2.;
00054   // ..
00055 
00056   // compute the mean of the vector
00057   mean = fvec_mean(a_vector);
00058 
00059   // destroy the vector
00060   del_fvec(a_vector);
00061 
00062   \endcode
00063 
00064   See `examples/` and `tests/src` directories for more examples.
00065 
00066  */
00067 typedef struct {
00068   uint_t length;  /**< length of buffer */
00069   smpl_t *data;   /**< data vector of length ::fvec_t.length */
00070 } fvec_t;
00071 
00072 /** fvec_t buffer creation function
00073 
00074   \param length the length of the buffer to create
00075 
00076 */
00077 fvec_t * new_fvec(uint_t length);
00078 
00079 /** fvec_t buffer deletion function
00080 
00081   \param s buffer to delete as returned by new_fvec()
00082 
00083 */
00084 void del_fvec(fvec_t *s);
00085 
00086 /** read sample value in a buffer
00087 
00088   \param s vector to read from
00089   \param position sample position to read from 
00090 
00091 */
00092 smpl_t fvec_get_sample(fvec_t *s, uint_t position);
00093 
00094 /** write sample value in a buffer
00095 
00096   \param s vector to write to 
00097   \param data value to write in s->data[position]
00098   \param position sample position to write to 
00099 
00100 */
00101 void  fvec_set_sample(fvec_t *s, smpl_t data, uint_t position);
00102 
00103 /** read data from a buffer
00104 
00105   \param s vector to read from
00106 
00107 */
00108 smpl_t * fvec_get_data(fvec_t *s);
00109 
00110 /** print out fvec data 
00111 
00112   \param s vector to print out 
00113 
00114 */
00115 void fvec_print(fvec_t *s);
00116 
00117 /** set all elements to a given value
00118 
00119   \param s vector to modify
00120   \param val value to set elements to
00121 
00122 */
00123 void fvec_set_all (fvec_t *s, smpl_t val);
00124 
00125 /** set all elements to zero 
00126 
00127   \param s vector to modify
00128 
00129 */
00130 void fvec_zeros(fvec_t *s);
00131 
00132 /** set all elements to ones 
00133 
00134   \param s vector to modify
00135 
00136 */
00137 void fvec_ones(fvec_t *s);
00138 
00139 /** revert order of vector elements
00140 
00141   \param s vector to revert
00142 
00143 */
00144 void fvec_rev(fvec_t *s);
00145 
00146 /** apply weight to vector
00147 
00148   If the weight vector is longer than s, only the first elements are used. If
00149   the weight vector is shorter than s, the last elements of s are not weighted.
00150 
00151   \param s vector to weight
00152   \param weight weighting coefficients
00153 
00154 */
00155 void fvec_weight(fvec_t *s, fvec_t *weight);
00156 
00157 /** make a copy of a vector
00158 
00159   \param s source vector
00160   \param t vector to copy to
00161 
00162 */
00163 void fvec_copy(fvec_t *s, fvec_t *t);
00164 
00165 #ifdef __cplusplus
00166 }
00167 #endif
00168 
00169 #endif /* _AUBIO__FVEC_H */
 All Data Structures Files Functions Variables Typedefs Defines