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 "cvec.h" |
---|
23 | |
---|
24 | cvec_t * new_cvec( uint_t length, uint_t channels) { |
---|
25 | cvec_t * s = AUBIO_NEW(cvec_t); |
---|
26 | uint_t i,j; |
---|
27 | s->channels = channels; |
---|
28 | s->length = length/2 + 1; |
---|
29 | s->norm = AUBIO_ARRAY(smpl_t*,s->channels); |
---|
30 | s->phas = AUBIO_ARRAY(smpl_t*,s->channels); |
---|
31 | for (i=0; i< s->channels; i++) { |
---|
32 | s->norm[i] = AUBIO_ARRAY(smpl_t,s->length); |
---|
33 | s->phas[i] = AUBIO_ARRAY(smpl_t,s->length); |
---|
34 | for (j=0; j< s->length; j++) { |
---|
35 | s->norm[i][j]=0.; |
---|
36 | s->phas[i][j]=0.; |
---|
37 | } |
---|
38 | } |
---|
39 | return s; |
---|
40 | } |
---|
41 | |
---|
42 | void del_cvec(cvec_t *s) { |
---|
43 | uint_t i; |
---|
44 | for (i=0; i<s->channels; i++) { |
---|
45 | AUBIO_FREE(s->norm[i]); |
---|
46 | AUBIO_FREE(s->phas[i]); |
---|
47 | } |
---|
48 | AUBIO_FREE(s->norm); |
---|
49 | AUBIO_FREE(s->phas); |
---|
50 | AUBIO_FREE(s); |
---|
51 | } |
---|
52 | |
---|
53 | void cvec_write_norm(cvec_t *s, smpl_t data, uint_t channel, uint_t position) { |
---|
54 | s->norm[channel][position] = data; |
---|
55 | } |
---|
56 | void cvec_write_phas(cvec_t *s, smpl_t data, uint_t channel, uint_t position) { |
---|
57 | s->phas[channel][position] = data; |
---|
58 | } |
---|
59 | smpl_t cvec_read_norm(cvec_t *s, uint_t channel, uint_t position) { |
---|
60 | return s->norm[channel][position]; |
---|
61 | } |
---|
62 | smpl_t cvec_read_phas(cvec_t *s, uint_t channel, uint_t position) { |
---|
63 | return s->phas[channel][position]; |
---|
64 | } |
---|
65 | void cvec_put_norm_channel(cvec_t *s, smpl_t * data, uint_t channel) { |
---|
66 | s->norm[channel] = data; |
---|
67 | } |
---|
68 | void cvec_put_phas_channel(cvec_t *s, smpl_t * data, uint_t channel) { |
---|
69 | s->phas[channel] = data; |
---|
70 | } |
---|
71 | smpl_t * cvec_get_norm_channel(cvec_t *s, uint_t channel) { |
---|
72 | return s->norm[channel]; |
---|
73 | } |
---|
74 | smpl_t * cvec_get_phas_channel(cvec_t *s, uint_t channel) { |
---|
75 | return s->phas[channel]; |
---|
76 | } |
---|
77 | smpl_t ** cvec_get_norm(cvec_t *s) { |
---|
78 | return s->norm; |
---|
79 | } |
---|
80 | smpl_t ** cvec_get_phas(cvec_t *s) { |
---|
81 | return s->phas; |
---|
82 | } |
---|
83 | |
---|
84 | /* helper functions */ |
---|
85 | |
---|
86 | void cvec_print(cvec_t *s) { |
---|
87 | uint_t i,j; |
---|
88 | for (i=0; i< s->channels; i++) { |
---|
89 | AUBIO_MSG("norm: "); |
---|
90 | for (j=0; j< s->length; j++) { |
---|
91 | AUBIO_MSG(AUBIO_SMPL_FMT " ", s->norm[i][j]); |
---|
92 | } |
---|
93 | AUBIO_MSG("\n"); |
---|
94 | AUBIO_MSG("phas: "); |
---|
95 | for (j=0; j< s->length; j++) { |
---|
96 | AUBIO_MSG(AUBIO_SMPL_FMT " ", s->phas[i][j]); |
---|
97 | } |
---|
98 | AUBIO_MSG("\n"); |
---|
99 | } |
---|
100 | } |
---|
101 | |
---|