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 fmat_t * s = AUBIO_NEW(fmat_t);
29 s->data = AUBIO_ARRAY(smpl_t*,s->height);
30 for (i=0; i< s->height; i++) {
31 s->data[i] = AUBIO_ARRAY(smpl_t, s->length);
32 for (j=0; j< s->length; j++) {
39 void del_fmat (fmat_t *s) {
41 for (i=0; i<s->height; i++) {
42 AUBIO_FREE(s->data[i]);
48 void fmat_write_sample(fmat_t *s, smpl_t data, uint_t channel, uint_t position) {
49 s->data[channel][position] = data;
51 smpl_t fmat_read_sample(fmat_t *s, uint_t channel, uint_t position) {
52 return s->data[channel][position];
54 void fmat_put_channel(fmat_t *s, smpl_t * data, uint_t channel) {
55 s->data[channel] = data;
57 smpl_t * fmat_get_channel(fmat_t *s, uint_t channel) {
58 return s->data[channel];
61 smpl_t ** fmat_get_data(fmat_t *s) {
65 /* helper functions */
67 void fmat_print(fmat_t *s) {
69 for (i=0; i< s->height; i++) {
70 for (j=0; j< s->length; j++) {
71 AUBIO_MSG(AUBIO_SMPL_FMT " ", s->data[i][j]);
77 void fmat_set(fmat_t *s, smpl_t val) {
79 for (i=0; i< s->height; i++) {
80 for (j=0; j< s->length; j++) {
86 void fmat_zeros(fmat_t *s) {
90 void fmat_ones(fmat_t *s) {
94 void fmat_rev(fmat_t *s) {
96 for (i=0; i< s->height; i++) {
97 for (j=0; j< FLOOR(s->length/2); j++) {
98 ELEM_SWAP(s->data[i][j], s->data[i][s->length-1-j]);
103 void fmat_weight(fmat_t *s, fmat_t *weight) {
105 uint_t length = MIN(s->length, weight->length);
106 for (i=0; i< s->height; i++) {
107 for (j=0; j< length; j++) {
108 s->data[i][j] *= weight->data[0][j];
113 void fmat_copy(fmat_t *s, fmat_t *t) {
115 uint_t height = MIN(s->height, t->height);
116 uint_t length = MIN(s->length, t->length);
117 if (s->height != t->height) {
118 AUBIO_ERR("warning, trying to copy %d rows to %d rows \n",
119 s->height, t->height);
121 if (s->length != t->length) {
122 AUBIO_ERR("warning, trying to copy %d columns to %d columns\n",
123 s->length, t->length);
125 for (i=0; i< height; i++) {
126 for (j=0; j< length; j++) {
127 t->data[i][j] = s->data[i][j];