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) {
25 if ((sint_t)length <= 0) {
28 cvec_t * s = AUBIO_NEW(cvec_t);
29 s->length = length/2 + 1;
30 s->norm = AUBIO_ARRAY(smpl_t,s->length);
31 s->phas = AUBIO_ARRAY(smpl_t,s->length);
35 void del_cvec(cvec_t *s) {
41 void cvec_norm_set_sample (cvec_t *s, smpl_t data, uint_t position) {
42 s->norm[position] = data;
45 void cvec_phas_set_sample (cvec_t *s, smpl_t data, uint_t position) {
46 s->phas[position] = data;
49 smpl_t cvec_norm_get_sample (cvec_t *s, uint_t position) {
50 return s->norm[position];
53 smpl_t cvec_phas_get_sample (cvec_t *s, uint_t position) {
54 return s->phas[position];
57 smpl_t * cvec_norm_get_data (cvec_t *s) {
61 smpl_t * cvec_phas_get_data (cvec_t *s) {
65 /* helper functions */
67 void cvec_print(cvec_t *s) {
70 for (j=0; j< s->length; j++) {
71 AUBIO_MSG(AUBIO_SMPL_FMT " ", s->norm[j]);
75 for (j=0; j< s->length; j++) {
76 AUBIO_MSG(AUBIO_SMPL_FMT " ", s->phas[j]);
81 void cvec_copy(cvec_t *s, cvec_t *t) {
82 if (s->length != t->length) {
83 AUBIO_ERR("trying to copy %d elements to %d elements \n",
84 s->length, t->length);
88 memcpy(t->norm, s->norm, t->length * sizeof(smpl_t));
89 memcpy(t->phas, s->phas, t->length * sizeof(smpl_t));
92 for (j=0; j< t->length; j++) {
93 t->norm[j] = s->norm[j];
94 t->phas[j] = s->phas[j];
99 void cvec_norm_set_all (cvec_t *s, smpl_t val) {
101 for (j=0; j< s->length; j++) {
106 void cvec_norm_zeros(cvec_t *s) {
107 #if HAVE_MEMCPY_HACKS
108 memset(s->norm, 0, s->length * sizeof(smpl_t));
110 cvec_norm_set_all (s, 0.);
114 void cvec_norm_ones(cvec_t *s) {
115 cvec_norm_set_all (s, 1.);
118 void cvec_phas_set_all (cvec_t *s, smpl_t val) {
120 for (j=0; j< s->length; j++) {
125 void cvec_phas_zeros(cvec_t *s) {
126 #if HAVE_MEMCPY_HACKS
127 memset(s->phas, 0, s->length * sizeof(smpl_t));
129 cvec_phas_set_all (s, 0.);
133 void cvec_phas_ones(cvec_t *s) {
134 cvec_phas_set_all (s, 1.);
137 void cvec_zeros(cvec_t *s) {