2 Copyright (C) 2009 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/>.
21 #include "aubio_priv.h"
24 fmat_t * new_fmat (uint_t length, uint_t height) {
25 if ((sint_t)length <= 0 || (sint_t)height <= 0 ) {
28 fmat_t * s = AUBIO_NEW(fmat_t);
32 s->data = AUBIO_ARRAY(smpl_t*,s->height);
33 for (i=0; i< s->height; i++) {
34 s->data[i] = AUBIO_ARRAY(smpl_t, s->length);
35 for (j=0; j< s->length; j++) {
42 void del_fmat (fmat_t *s) {
44 for (i=0; i<s->height; i++) {
45 AUBIO_FREE(s->data[i]);
51 void fmat_set_sample(fmat_t *s, smpl_t data, uint_t channel, uint_t position) {
52 s->data[channel][position] = data;
55 smpl_t fmat_get_sample(fmat_t *s, uint_t channel, uint_t position) {
56 return s->data[channel][position];
59 void fmat_get_channel(fmat_t *s, uint_t channel, fvec_t *output) {
60 output->data = s->data[channel];
61 output->length = s->length;
65 smpl_t * fmat_get_channel_data(fmat_t *s, uint_t channel) {
66 return s->data[channel];
69 smpl_t ** fmat_get_data(fmat_t *s) {
73 /* helper functions */
75 void fmat_print(fmat_t *s) {
77 for (i=0; i< s->height; i++) {
78 for (j=0; j< s->length; j++) {
79 AUBIO_MSG(AUBIO_SMPL_FMT " ", s->data[i][j]);
85 void fmat_set(fmat_t *s, smpl_t val) {
87 for (i=0; i< s->height; i++) {
88 for (j=0; j< s->length; j++) {
94 void fmat_zeros(fmat_t *s) {
97 for (i=0; i< s->height; i++) {
98 memset(s->data[i], 0, s->length * sizeof(smpl_t));
105 void fmat_ones(fmat_t *s) {
109 void fmat_rev(fmat_t *s) {
111 for (i=0; i< s->height; i++) {
112 for (j=0; j< FLOOR(s->length/2); j++) {
113 ELEM_SWAP(s->data[i][j], s->data[i][s->length-1-j]);
118 void fmat_weight(fmat_t *s, fmat_t *weight) {
120 uint_t length = MIN(s->length, weight->length);
121 for (i=0; i< s->height; i++) {
122 for (j=0; j< length; j++) {
123 s->data[i][j] *= weight->data[0][j];
128 void fmat_copy(fmat_t *s, fmat_t *t) {
129 if (s->height != t->height) {
130 AUBIO_ERR("trying to copy %d rows to %d rows \n",
131 s->height, t->height);
134 if (s->length != t->length) {
135 AUBIO_ERR("trying to copy %d columns to %d columns\n",
136 s->length, t->length);
139 #if HAVE_MEMCPY_HACKS
141 for (i=0; i< s->height; i++) {
142 memcpy(t->data[i], s->data[i], t->length * sizeof(smpl_t));
146 for (i=0; i< t->height; i++) {
147 for (j=0; j< t->length; j++) {
148 t->data[i][j] = s->data[i][j];