2 Copyright (C) 2003-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 cvec_t * new_cvec(uint_t length) {
26 if ((sint_t)length <= 0) {
29 s = AUBIO_NEW(cvec_t);
30 s->length = length/2 + 1;
31 s->norm = AUBIO_ARRAY(smpl_t,s->length);
32 s->phas = AUBIO_ARRAY(smpl_t,s->length);
36 void del_cvec(cvec_t *s) {
42 void cvec_norm_set_sample (cvec_t *s, smpl_t data, uint_t position) {
43 s->norm[position] = data;
46 void cvec_phas_set_sample (cvec_t *s, smpl_t data, uint_t position) {
47 s->phas[position] = data;
50 smpl_t cvec_norm_get_sample (cvec_t *s, uint_t position) {
51 return s->norm[position];
54 smpl_t cvec_phas_get_sample (cvec_t *s, uint_t position) {
55 return s->phas[position];
58 smpl_t * cvec_norm_get_data (const cvec_t *s) {
62 smpl_t * cvec_phas_get_data (const cvec_t *s) {
66 /* helper functions */
68 void cvec_print(const cvec_t *s) {
71 for (j=0; j< s->length; j++) {
72 AUBIO_MSG(AUBIO_SMPL_FMT " ", s->norm[j]);
76 for (j=0; j< s->length; j++) {
77 AUBIO_MSG(AUBIO_SMPL_FMT " ", s->phas[j]);
82 void cvec_copy(const cvec_t *s, cvec_t *t) {
83 if (s->length != t->length) {
84 AUBIO_ERR("trying to copy %d elements to %d elements \n",
85 s->length, t->length);
88 #ifdef HAVE_MEMCPY_HACKS
89 memcpy(t->norm, s->norm, t->length * sizeof(smpl_t));
90 memcpy(t->phas, s->phas, t->length * sizeof(smpl_t));
91 #else /* HAVE_MEMCPY_HACKS */
93 for (j=0; j< t->length; j++) {
94 t->norm[j] = s->norm[j];
95 t->phas[j] = s->phas[j];
97 #endif /* HAVE_MEMCPY_HACKS */
100 void cvec_norm_set_all (cvec_t *s, smpl_t val) {
102 for (j=0; j< s->length; j++) {
107 void cvec_norm_zeros(cvec_t *s) {
108 #ifdef HAVE_MEMCPY_HACKS
109 memset(s->norm, 0, s->length * sizeof(smpl_t));
110 #else /* HAVE_MEMCPY_HACKS */
111 cvec_norm_set_all (s, 0.);
112 #endif /* HAVE_MEMCPY_HACKS */
115 void cvec_norm_ones(cvec_t *s) {
116 cvec_norm_set_all (s, 1.);
119 void cvec_phas_set_all (cvec_t *s, smpl_t val) {
121 for (j=0; j< s->length; j++) {
126 void cvec_phas_zeros(cvec_t *s) {
127 #ifdef HAVE_MEMCPY_HACKS
128 memset(s->phas, 0, s->length * sizeof(smpl_t));
130 cvec_phas_set_all (s, 0.);
134 void cvec_phas_ones(cvec_t *s) {
135 cvec_phas_set_all (s, 1.);
138 void cvec_zeros(cvec_t *s) {
143 void cvec_logmag(cvec_t *s, smpl_t lambda) {
145 for (j=0; j< s->length; j++) {
146 s->norm[j] = LOG(lambda * s->norm[j] + 1);