AUTHORS: use standard list of name/email
[aubio.git] / src / lvec.c
1 /*
2   Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
3
4   This file is part of aubio.
5
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.
10
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/>.
18
19 */
20
21 #include "aubio_priv.h"
22 #include "lvec.h"
23
24 lvec_t * new_lvec( uint_t length, uint_t channels) {
25   lvec_t * s = AUBIO_NEW(lvec_t);
26   uint_t i,j;
27   s->channels = channels;
28   s->length = length;
29   s->data = AUBIO_ARRAY(lsmp_t*,s->channels);
30   for (i=0; i< s->channels; i++) {
31     s->data[i] = AUBIO_ARRAY(lsmp_t, s->length);
32     for (j=0; j< s->length; j++) {
33       s->data[i][j]=0.;
34     }
35   }
36   return s;
37 }
38
39 void del_lvec(lvec_t *s) {
40   uint_t i;
41   for (i=0; i<s->channels; i++) {
42     AUBIO_FREE(s->data[i]);
43   }
44   AUBIO_FREE(s->data);
45   AUBIO_FREE(s);
46 }
47
48 void lvec_write_sample(lvec_t *s, lsmp_t data, uint_t channel, uint_t position) {
49   s->data[channel][position] = data;
50 }
51 lsmp_t lvec_read_sample(lvec_t *s, uint_t channel, uint_t position) {
52   return s->data[channel][position];
53 }
54 void lvec_put_channel(lvec_t *s, lsmp_t * data, uint_t channel) {
55   s->data[channel] = data;
56 }
57 lsmp_t * lvec_get_channel(lvec_t *s, uint_t channel) {
58   return s->data[channel];
59 }
60
61 lsmp_t ** lvec_get_data(lvec_t *s) {
62   return s->data;
63 }
64
65 /* helper functions */
66
67 void lvec_print(lvec_t *s) {
68   uint_t i,j;
69   for (i=0; i< s->channels; i++) {
70     for (j=0; j< s->length; j++) {
71       AUBIO_MSG(AUBIO_LSMP_FMT " ", s->data[i][j]);
72     }
73     AUBIO_MSG("\n");
74   }
75 }
76
77 void lvec_set(lvec_t *s, smpl_t val) {
78   uint_t i,j;
79   for (i=0; i< s->channels; i++) {
80     for (j=0; j< s->length; j++) {
81       s->data[i][j] = val;
82     }
83   }
84 }
85
86 void lvec_zeros(lvec_t *s) {
87   lvec_set(s, 0.);
88 }
89
90 void lvec_ones(lvec_t *s) {
91   lvec_set(s, 1.);
92 }
93