1 | /* |
---|
2 | Copyright (C) 2003-2007 Paul Brossier <piem@piem.org> |
---|
3 | |
---|
4 | This program is free software; you can redistribute it and/or modify |
---|
5 | it under the terms of the GNU General Public License as published by |
---|
6 | the Free Software Foundation; either version 2 of the License, or |
---|
7 | (at your option) any later version. |
---|
8 | |
---|
9 | This program is distributed in the hope that it will be useful, |
---|
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | GNU General Public License for more details. |
---|
13 | |
---|
14 | You should have received a copy of the GNU General Public License |
---|
15 | along with this program; if not, write to the Free Software |
---|
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
17 | |
---|
18 | */ |
---|
19 | |
---|
20 | #include "aubio_priv.h" |
---|
21 | #include "cvec.h" |
---|
22 | |
---|
23 | cvec_t * new_cvec( uint_t length, uint_t channels) { |
---|
24 | cvec_t * s = AUBIO_NEW(cvec_t); |
---|
25 | uint_t i,j; |
---|
26 | s->channels = channels; |
---|
27 | s->length = length/2 + 1; |
---|
28 | s->norm = AUBIO_ARRAY(smpl_t*,s->channels); |
---|
29 | s->phas = AUBIO_ARRAY(smpl_t*,s->channels); |
---|
30 | for (i=0; i< s->channels; i++) { |
---|
31 | s->norm[i] = AUBIO_ARRAY(smpl_t,s->length); |
---|
32 | s->phas[i] = AUBIO_ARRAY(smpl_t,s->length); |
---|
33 | for (j=0; j< s->length; j++) { |
---|
34 | s->norm[i][j]=0.; |
---|
35 | s->phas[i][j]=0.; |
---|
36 | } |
---|
37 | } |
---|
38 | return s; |
---|
39 | } |
---|
40 | |
---|
41 | void del_cvec(cvec_t *s) { |
---|
42 | uint_t i; |
---|
43 | for (i=0; i<s->channels; i++) { |
---|
44 | AUBIO_FREE(s->norm[i]); |
---|
45 | AUBIO_FREE(s->phas[i]); |
---|
46 | } |
---|
47 | AUBIO_FREE(s->norm); |
---|
48 | AUBIO_FREE(s->phas); |
---|
49 | AUBIO_FREE(s); |
---|
50 | } |
---|
51 | |
---|
52 | void cvec_write_norm(cvec_t *s, smpl_t data, uint_t channel, uint_t position) { |
---|
53 | s->norm[channel][position] = data; |
---|
54 | } |
---|
55 | void cvec_write_phas(cvec_t *s, smpl_t data, uint_t channel, uint_t position) { |
---|
56 | s->phas[channel][position] = data; |
---|
57 | } |
---|
58 | smpl_t cvec_read_norm(cvec_t *s, uint_t channel, uint_t position) { |
---|
59 | return s->norm[channel][position]; |
---|
60 | } |
---|
61 | smpl_t cvec_read_phas(cvec_t *s, uint_t channel, uint_t position) { |
---|
62 | return s->phas[channel][position]; |
---|
63 | } |
---|
64 | void cvec_put_norm_channel(cvec_t *s, smpl_t * data, uint_t channel) { |
---|
65 | s->norm[channel] = data; |
---|
66 | } |
---|
67 | void cvec_put_phas_channel(cvec_t *s, smpl_t * data, uint_t channel) { |
---|
68 | s->phas[channel] = data; |
---|
69 | } |
---|
70 | smpl_t * cvec_get_norm_channel(cvec_t *s, uint_t channel) { |
---|
71 | return s->norm[channel]; |
---|
72 | } |
---|
73 | smpl_t * cvec_get_phas_channel(cvec_t *s, uint_t channel) { |
---|
74 | return s->phas[channel]; |
---|
75 | } |
---|
76 | smpl_t ** cvec_get_norm(cvec_t *s) { |
---|
77 | return s->norm; |
---|
78 | } |
---|
79 | smpl_t ** cvec_get_phas(cvec_t *s) { |
---|
80 | return s->phas; |
---|
81 | } |
---|
82 | |
---|