--- /dev/null
+/*
+ Copyright (C) 2009 Paul Brossier <piem@aubio.org>
+
+ This file is part of aubio.
+
+ aubio is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ aubio is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with aubio. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include "aubio_priv.h"
+#include "fmat.h"
+
+fmat_t * new_fmat (uint_t length, uint_t height) {
+ fmat_t * s = AUBIO_NEW(fmat_t);
+ uint_t i,j;
+ s->height = height;
+ s->length = length;
+ s->data = AUBIO_ARRAY(smpl_t*,s->height);
+ for (i=0; i< s->height; i++) {
+ s->data[i] = AUBIO_ARRAY(smpl_t, s->length);
+ for (j=0; j< s->length; j++) {
+ s->data[i][j]=0.;
+ }
+ }
+ return s;
+}
+
+void del_fmat (fmat_t *s) {
+ uint_t i;
+ for (i=0; i<s->height; i++) {
+ AUBIO_FREE(s->data[i]);
+ }
+ AUBIO_FREE(s->data);
+ AUBIO_FREE(s);
+}
+
+void fmat_write_sample(fmat_t *s, smpl_t data, uint_t channel, uint_t position) {
+ s->data[channel][position] = data;
+}
+smpl_t fmat_read_sample(fmat_t *s, uint_t channel, uint_t position) {
+ return s->data[channel][position];
+}
+void fmat_put_channel(fmat_t *s, smpl_t * data, uint_t channel) {
+ s->data[channel] = data;
+}
+smpl_t * fmat_get_channel(fmat_t *s, uint_t channel) {
+ return s->data[channel];
+}
+
+smpl_t ** fmat_get_data(fmat_t *s) {
+ return s->data;
+}
+
+/* helper functions */
+
+void fmat_print(fmat_t *s) {
+ uint_t i,j;
+ for (i=0; i< s->height; i++) {
+ for (j=0; j< s->length; j++) {
+ AUBIO_MSG(AUBIO_SMPL_FMT " ", s->data[i][j]);
+ }
+ AUBIO_MSG("\n");
+ }
+}
+
+void fmat_set(fmat_t *s, smpl_t val) {
+ uint_t i,j;
+ for (i=0; i< s->height; i++) {
+ for (j=0; j< s->length; j++) {
+ s->data[i][j] = val;
+ }
+ }
+}
+
+void fmat_zeros(fmat_t *s) {
+ fmat_set(s, 0.);
+}
+
+void fmat_ones(fmat_t *s) {
+ fmat_set(s, 1.);
+}
+
+void fmat_rev(fmat_t *s) {
+ uint_t i,j;
+ for (i=0; i< s->height; i++) {
+ for (j=0; j< FLOOR(s->length/2); j++) {
+ ELEM_SWAP(s->data[i][j], s->data[i][s->length-1-j]);
+ }
+ }
+}
+
+void fmat_weight(fmat_t *s, fmat_t *weight) {
+ uint_t i,j;
+ uint_t length = MIN(s->length, weight->length);
+ for (i=0; i< s->height; i++) {
+ for (j=0; j< length; j++) {
+ s->data[i][j] *= weight->data[0][j];
+ }
+ }
+}
+
+void fmat_copy(fmat_t *s, fmat_t *t) {
+ uint_t i,j;
+ uint_t height = MIN(s->height, t->height);
+ uint_t length = MIN(s->length, t->length);
+ if (s->height != t->height) {
+ AUBIO_ERR("warning, trying to copy %d rows to %d rows \n",
+ s->height, t->height);
+ }
+ if (s->length != t->length) {
+ AUBIO_ERR("warning, trying to copy %d columns to %d columns\n",
+ s->length, t->length);
+ }
+ for (i=0; i< height; i++) {
+ for (j=0; j< length; j++) {
+ t->data[i][j] = s->data[i][j];
+ }
+ }
+}
+
--- /dev/null
+/*
+ Copyright (C) 2009 Paul Brossier <piem@aubio.org>
+
+ This file is part of aubio.
+
+ aubio is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ aubio is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with aubio. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#ifndef _FMAT_H
+#define _FMAT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** \file
+
+ Real buffers
+
+ This file specifies the fmat_t type, which is used in aubio to store real
+ valued arrays.
+
+*/
+
+/** Buffer for real data */
+typedef struct {
+ uint_t length; /**< length of buffer */
+ uint_t height; /**< number of channels */
+ smpl_t **data; /**< data array of size [length] * [channels] */
+} fmat_t;
+
+/** fmat_t buffer creation function
+
+ \param length the length of the buffer to create
+ \param channels the number of channels in the buffer
+
+*/
+fmat_t * new_fmat(uint_t length, uint_t channels);
+/** fmat_t buffer deletion function
+
+ \param s buffer to delete as returned by new_fmat()
+
+*/
+void del_fmat(fmat_t *s);
+/** read sample value in a buffer
+
+ Note that this function is not used in the aubio library, since the same
+ result can be obtained using vec->data[channel][position]. Its purpose is to
+ access these values from wrappers, as created by swig.
+
+ \param s vector to read from
+ \param channel channel to read from
+ \param position sample position to read from
+
+*/
+smpl_t fmat_read_sample(fmat_t *s, uint_t channel, uint_t position);
+/** write sample value in a buffer
+
+ Note that this function is not used in the aubio library, since the same
+ result can be obtained by assigning vec->data[channel][position]. Its purpose
+ is to access these values from wrappers, as created by swig.
+
+ \param s vector to write to
+ \param data value to write in s->data[channel][position]
+ \param channel channel to write to
+ \param position sample position to write to
+
+*/
+void fmat_write_sample(fmat_t *s, smpl_t data, uint_t channel, uint_t position);
+/** read channel vector from a buffer
+
+ Note that this function is not used in the aubio library, since the same
+ result can be obtained with vec->data[channel]. Its purpose is to access
+ these values from wrappers, as created by swig.
+
+ \param s vector to read from
+ \param channel channel to read from
+
+*/
+smpl_t * fmat_get_channel(fmat_t *s, uint_t channel);
+/** write channel vector into a buffer
+
+ Note that this function is not used in the aubio library, since the same
+ result can be obtained by assigning vec->data[channel]. Its purpose is to
+ access these values from wrappers, as created by swig.
+
+ \param s vector to write to
+ \param data vector of [length] values to write
+ \param channel channel to write to
+
+*/
+void fmat_put_channel(fmat_t *s, smpl_t * data, uint_t channel);
+/** read data from a buffer
+
+ Note that this function is not used in the aubio library, since the same
+ result can be obtained with vec->data. Its purpose is to access these values
+ from wrappers, as created by swig.
+
+ \param s vector to read from
+
+*/
+smpl_t ** fmat_get_data(fmat_t *s);
+
+/** print out fmat data
+
+ \param s vector to print out
+
+*/
+void fmat_print(fmat_t *s);
+
+/** set all elements to a given value
+
+ \param s vector to modify
+ \param val value to set elements to
+
+*/
+void fmat_set(fmat_t *s, smpl_t val);
+
+/** set all elements to zero
+
+ \param s vector to modify
+
+*/
+void fmat_zeros(fmat_t *s);
+
+/** set all elements to ones
+
+ \param s vector to modify
+
+*/
+void fmat_ones(fmat_t *s);
+
+/** revert order of vector elements
+
+ \param s vector to revert
+
+*/
+void fmat_rev(fmat_t *s);
+
+/** apply weight to vector
+
+ If the weight vector is longer than s, only the first elements are used. If
+ the weight vector is shorter than s, the last elements of s are not weighted.
+
+ \param s vector to weight
+ \param weight weighting coefficients
+
+*/
+void fmat_weight(fmat_t *s, fmat_t *weight);
+
+/** make a copy of a matrix
+
+ \param s source vector
+ \param t vector to copy to
+
+*/
+void fmat_copy(fmat_t *s, fmat_t *t);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _FMAT_H */
#include "aubio_priv.h"
#include "fvec.h"
-fvec_t * new_fvec( uint_t length, uint_t channels) {
+fvec_t * new_fvec( uint_t length) {
fvec_t * s = AUBIO_NEW(fvec_t);
- uint_t i,j;
- s->channels = channels;
+ uint_t j;
s->length = length;
- s->data = AUBIO_ARRAY(smpl_t*,s->channels);
- for (i=0; i< s->channels; i++) {
- s->data[i] = AUBIO_ARRAY(smpl_t, s->length);
- for (j=0; j< s->length; j++) {
- s->data[i][j]=0.;
- }
+ s->data = AUBIO_ARRAY(smpl_t, s->length);
+ for (j=0; j< s->length; j++) {
+ s->data[j]=0.;
}
return s;
}
void del_fvec(fvec_t *s) {
- uint_t i;
- for (i=0; i<s->channels; i++) {
- AUBIO_FREE(s->data[i]);
- }
AUBIO_FREE(s->data);
AUBIO_FREE(s);
}
-void fvec_write_sample(fvec_t *s, smpl_t data, uint_t channel, uint_t position) {
- s->data[channel][position] = data;
-}
-smpl_t fvec_read_sample(fvec_t *s, uint_t channel, uint_t position) {
- return s->data[channel][position];
-}
-void fvec_put_channel(fvec_t *s, smpl_t * data, uint_t channel) {
- s->data[channel] = data;
+void fvec_write_sample(fvec_t *s, smpl_t data, uint_t position) {
+ s->data[position] = data;
}
-smpl_t * fvec_get_channel(fvec_t *s, uint_t channel) {
- return s->data[channel];
+
+smpl_t fvec_read_sample(fvec_t *s, uint_t position) {
+ return s->data[position];
}
-smpl_t ** fvec_get_data(fvec_t *s) {
+smpl_t * fvec_get_data(fvec_t *s) {
return s->data;
}
/* helper functions */
void fvec_print(fvec_t *s) {
- uint_t i,j;
- for (i=0; i< s->channels; i++) {
- for (j=0; j< s->length; j++) {
- AUBIO_MSG(AUBIO_SMPL_FMT " ", s->data[i][j]);
- }
- AUBIO_MSG("\n");
+ uint_t j;
+ for (j=0; j< s->length; j++) {
+ AUBIO_MSG(AUBIO_SMPL_FMT " ", s->data[j]);
}
+ AUBIO_MSG("\n");
}
void fvec_set(fvec_t *s, smpl_t val) {
- uint_t i,j;
- for (i=0; i< s->channels; i++) {
- for (j=0; j< s->length; j++) {
- s->data[i][j] = val;
- }
+ uint_t j;
+ for (j=0; j< s->length; j++) {
+ s->data[j] = val;
}
}
}
void fvec_rev(fvec_t *s) {
- uint_t i,j;
- for (i=0; i< s->channels; i++) {
- for (j=0; j< FLOOR(s->length/2); j++) {
- ELEM_SWAP(s->data[i][j], s->data[i][s->length-1-j]);
- }
+ uint_t j;
+ for (j=0; j< FLOOR(s->length/2); j++) {
+ ELEM_SWAP(s->data[j], s->data[s->length-1-j]);
}
}
void fvec_weight(fvec_t *s, fvec_t *weight) {
- uint_t i,j;
+ uint_t j;
uint_t length = MIN(s->length, weight->length);
- for (i=0; i< s->channels; i++) {
- for (j=0; j< length; j++) {
- s->data[i][j] *= weight->data[0][j];
- }
+ for (j=0; j< length; j++) {
+ s->data[j] *= weight->data[j];
}
}
void fvec_copy(fvec_t *s, fvec_t *t) {
- uint_t i,j;
- uint_t channels = MIN(s->channels, t->channels);
+ uint_t j;
uint_t length = MIN(s->length, t->length);
- if (s->channels != t->channels) {
- AUBIO_ERR("warning, trying to copy %d channels to %d channels\n",
- s->channels, t->channels);
- }
if (s->length != t->length) {
- AUBIO_ERR("warning, trying to copy %d elements to %d elements \n",
+ AUBIO_WRN("trying to copy %d elements to %d elements \n",
s->length, t->length);
}
- for (i=0; i< channels; i++) {
- for (j=0; j< length; j++) {
- t->data[i][j] = s->data[i][j];
- }
+ for (j=0; j< length; j++) {
+ t->data[j] = s->data[j];
}
}
/** Buffer for real data */
typedef struct {
uint_t length; /**< length of buffer */
- uint_t channels; /**< number of channels */
- smpl_t **data; /**< data array of size [length] * [channels] */
+ smpl_t *data; /**< data array of size [length] */
} fvec_t;
/** fvec_t buffer creation function
\param length the length of the buffer to create
- \param channels the number of channels in the buffer
*/
-fvec_t * new_fvec(uint_t length, uint_t channels);
+fvec_t * new_fvec(uint_t length);
/** fvec_t buffer deletion function
\param s buffer to delete as returned by new_fvec()
/** read sample value in a buffer
Note that this function is not used in the aubio library, since the same
- result can be obtained using vec->data[channel][position]. Its purpose is to
+ result can be obtained using vec->data[position]. Its purpose is to
access these values from wrappers, as created by swig.
\param s vector to read from
- \param channel channel to read from
\param position sample position to read from
*/
-smpl_t fvec_read_sample(fvec_t *s, uint_t channel, uint_t position);
+smpl_t fvec_read_sample(fvec_t *s, uint_t position);
/** write sample value in a buffer
Note that this function is not used in the aubio library, since the same
- result can be obtained by assigning vec->data[channel][position]. Its purpose
+ result can be obtained by assigning vec->data[position]. Its purpose
is to access these values from wrappers, as created by swig.
\param s vector to write to
- \param data value to write in s->data[channel][position]
- \param channel channel to write to
+ \param data value to write in s->data[position]
\param position sample position to write to
*/
-void fvec_write_sample(fvec_t *s, smpl_t data, uint_t channel, uint_t position);
-/** read channel vector from a buffer
+void fvec_write_sample(fvec_t *s, smpl_t data, uint_t position);
- Note that this function is not used in the aubio library, since the same
- result can be obtained with vec->data[channel]. Its purpose is to access
- these values from wrappers, as created by swig.
-
- \param s vector to read from
- \param channel channel to read from
-
-*/
-smpl_t * fvec_get_channel(fvec_t *s, uint_t channel);
-/** write channel vector into a buffer
-
- Note that this function is not used in the aubio library, since the same
- result can be obtained by assigning vec->data[channel]. Its purpose is to
- access these values from wrappers, as created by swig.
-
- \param s vector to write to
- \param data vector of [length] values to write
- \param channel channel to write to
-
-*/
-void fvec_put_channel(fvec_t *s, smpl_t * data, uint_t channel);
/** read data from a buffer
Note that this function is not used in the aubio library, since the same
\param s vector to read from
*/
-smpl_t ** fvec_get_data(fvec_t *s);
+smpl_t * fvec_get_data(fvec_t *s);
/** print out fvec data
#include "aubio_priv.h"
#include "lvec.h"
-lvec_t * new_lvec( uint_t length, uint_t channels) {
+lvec_t * new_lvec( uint_t length) {
lvec_t * s = AUBIO_NEW(lvec_t);
- uint_t i,j;
- s->channels = channels;
+ uint_t j;
s->length = length;
- s->data = AUBIO_ARRAY(lsmp_t*,s->channels);
- for (i=0; i< s->channels; i++) {
- s->data[i] = AUBIO_ARRAY(lsmp_t, s->length);
- for (j=0; j< s->length; j++) {
- s->data[i][j]=0.;
- }
+ s->data = AUBIO_ARRAY(lsmp_t, s->length);
+ for (j=0; j< s->length; j++) {
+ s->data[j]=0.;
}
return s;
}
void del_lvec(lvec_t *s) {
- uint_t i;
- for (i=0; i<s->channels; i++) {
- AUBIO_FREE(s->data[i]);
- }
AUBIO_FREE(s->data);
AUBIO_FREE(s);
}
-void lvec_write_sample(lvec_t *s, lsmp_t data, uint_t channel, uint_t position) {
- s->data[channel][position] = data;
-}
-lsmp_t lvec_read_sample(lvec_t *s, uint_t channel, uint_t position) {
- return s->data[channel][position];
-}
-void lvec_put_channel(lvec_t *s, lsmp_t * data, uint_t channel) {
- s->data[channel] = data;
+void lvec_write_sample(lvec_t *s, lsmp_t data, uint_t position) {
+ s->data[position] = data;
}
-lsmp_t * lvec_get_channel(lvec_t *s, uint_t channel) {
- return s->data[channel];
+lsmp_t lvec_read_sample(lvec_t *s, uint_t position) {
+ return s->data[position];
}
-lsmp_t ** lvec_get_data(lvec_t *s) {
+lsmp_t * lvec_get_data(lvec_t *s) {
return s->data;
}
/* helper functions */
void lvec_print(lvec_t *s) {
- uint_t i,j;
- for (i=0; i< s->channels; i++) {
- for (j=0; j< s->length; j++) {
- AUBIO_MSG(AUBIO_LSMP_FMT " ", s->data[i][j]);
- }
- AUBIO_MSG("\n");
+ uint_t j;
+ for (j=0; j< s->length; j++) {
+ AUBIO_MSG(AUBIO_LSMP_FMT " ", s->data[j]);
}
+ AUBIO_MSG("\n");
}
void lvec_set(lvec_t *s, smpl_t val) {
- uint_t i,j;
- for (i=0; i< s->channels; i++) {
- for (j=0; j< s->length; j++) {
- s->data[i][j] = val;
- }
+ uint_t j;
+ for (j=0; j< s->length; j++) {
+ s->data[j] = val;
}
}
/** Buffer for real data in double precision */
typedef struct {
uint_t length; /**< length of buffer */
- uint_t channels; /**< number of channels */
- lsmp_t **data; /**< data array of size [length] * [channels] */
+ lsmp_t *data; /**< data array of size [length] */
} lvec_t;
/** lvec_t buffer creation function
\param length the length of the buffer to create
- \param channels the number of channels in the buffer
*/
-lvec_t * new_lvec(uint_t length, uint_t channels);
+lvec_t * new_lvec(uint_t length);
/** lvec_t buffer deletion function
\param s buffer to delete as returned by new_lvec()
/** read sample value in a buffer
Note that this function is not used in the aubio library, since the same
- result can be obtained using vec->data[channel][position]. Its purpose is to
+ result can be obtained using vec->data[position]. Its purpose is to
access these values from wrappers, as created by swig.
\param s vector to read from
- \param channel channel to read from
\param position sample position to read from
*/
-lsmp_t lvec_read_sample(lvec_t *s, uint_t channel, uint_t position);
+lsmp_t lvec_read_sample(lvec_t *s, uint_t position);
/** write sample value in a buffer
Note that this function is not used in the aubio library, since the same
- result can be obtained by assigning vec->data[channel][position]. Its purpose
+ result can be obtained by assigning vec->data[position]. Its purpose
is to access these values from wrappers, as created by swig.
\param s vector to write to
- \param data value to write in s->data[channel][position]
- \param channel channel to write to
+ \param data value to write in s->data[position]
\param position sample position to write to
*/
-void lvec_write_sample(lvec_t *s, lsmp_t data, uint_t channel, uint_t position);
-/** read channel vector from a buffer
+void lvec_write_sample(lvec_t *s, lsmp_t data, uint_t position);
- Note that this function is not used in the aubio library, since the same
- result can be obtained with vec->data[channel]. Its purpose is to access
- these values from wrappers, as created by swig.
-
- \param s vector to read from
- \param channel channel to read from
-
-*/
-lsmp_t * lvec_get_channel(lvec_t *s, uint_t channel);
-/** write channel vector into a buffer
-
- Note that this function is not used in the aubio library, since the same
- result can be obtained by assigning vec->data[channel]. Its purpose is to
- access these values from wrappers, as created by swig.
-
- \param s vector to write to
- \param data vector of [length] values to write
- \param channel channel to write to
-
-*/
-void lvec_put_channel(lvec_t *s, lsmp_t * data, uint_t channel);
/** read data from a buffer
Note that this function is not used in the aubio library, since the same
\param s vector to read from
*/
-lsmp_t ** lvec_get_data(lvec_t *s);
+lsmp_t * lvec_get_data(lvec_t *s);
/** print out lvec data