[96fb8ad] | 1 | /* |
---|
[a6db140] | 2 | Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org> |
---|
[96fb8ad] | 3 | |
---|
[a6db140] | 4 | This file is part of aubio. |
---|
[96fb8ad] | 5 | |
---|
[a6db140] | 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. |
---|
[96fb8ad] | 10 | |
---|
[a6db140] | 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/>. |
---|
[96fb8ad] | 18 | |
---|
| 19 | */ |
---|
| 20 | |
---|
| 21 | #include "aubio_priv.h" |
---|
[d1ec8cb] | 22 | #include "cvec.h" |
---|
[96fb8ad] | 23 | |
---|
[66fb3ea] | 24 | cvec_t * new_cvec( uint_t length) { |
---|
[767990e] | 25 | if ((sint_t)length <= 0) { |
---|
| 26 | return NULL; |
---|
| 27 | } |
---|
[96fb8ad] | 28 | cvec_t * s = AUBIO_NEW(cvec_t); |
---|
| 29 | s->length = length/2 + 1; |
---|
[66fb3ea] | 30 | s->norm = AUBIO_ARRAY(smpl_t,s->length); |
---|
| 31 | s->phas = AUBIO_ARRAY(smpl_t,s->length); |
---|
[96fb8ad] | 32 | return s; |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | void del_cvec(cvec_t *s) { |
---|
| 36 | AUBIO_FREE(s->norm); |
---|
| 37 | AUBIO_FREE(s->phas); |
---|
| 38 | AUBIO_FREE(s); |
---|
| 39 | } |
---|
[7c206df] | 40 | |
---|
[5d10ac1] | 41 | void cvec_norm_set_sample (cvec_t *s, smpl_t data, uint_t position) { |
---|
[66fb3ea] | 42 | s->norm[position] = data; |
---|
[7c206df] | 43 | } |
---|
[5d10ac1] | 44 | |
---|
| 45 | void cvec_phas_set_sample (cvec_t *s, smpl_t data, uint_t position) { |
---|
[66fb3ea] | 46 | s->phas[position] = data; |
---|
[7c206df] | 47 | } |
---|
[5d10ac1] | 48 | |
---|
| 49 | smpl_t cvec_norm_get_sample (cvec_t *s, uint_t position) { |
---|
[66fb3ea] | 50 | return s->norm[position]; |
---|
[7c206df] | 51 | } |
---|
[5d10ac1] | 52 | |
---|
| 53 | smpl_t cvec_phas_get_sample (cvec_t *s, uint_t position) { |
---|
[66fb3ea] | 54 | return s->phas[position]; |
---|
[7c206df] | 55 | } |
---|
[5d10ac1] | 56 | |
---|
| 57 | smpl_t * cvec_norm_get_data (cvec_t *s) { |
---|
[7c206df] | 58 | return s->norm; |
---|
| 59 | } |
---|
[5d10ac1] | 60 | |
---|
| 61 | smpl_t * cvec_phas_get_data (cvec_t *s) { |
---|
[7c206df] | 62 | return s->phas; |
---|
| 63 | } |
---|
[d1ec8cb] | 64 | |
---|
[55b7cb4] | 65 | /* helper functions */ |
---|
| 66 | |
---|
| 67 | void cvec_print(cvec_t *s) { |
---|
[66fb3ea] | 68 | uint_t j; |
---|
| 69 | AUBIO_MSG("norm: "); |
---|
| 70 | for (j=0; j< s->length; j++) { |
---|
| 71 | AUBIO_MSG(AUBIO_SMPL_FMT " ", s->norm[j]); |
---|
| 72 | } |
---|
| 73 | AUBIO_MSG("\n"); |
---|
| 74 | AUBIO_MSG("phas: "); |
---|
| 75 | for (j=0; j< s->length; j++) { |
---|
| 76 | AUBIO_MSG(AUBIO_SMPL_FMT " ", s->phas[j]); |
---|
[55b7cb4] | 77 | } |
---|
[66fb3ea] | 78 | AUBIO_MSG("\n"); |
---|
[55b7cb4] | 79 | } |
---|
| 80 | |
---|
[39a7b26] | 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); |
---|
| 85 | return; |
---|
| 86 | } |
---|
| 87 | #if HAVE_MEMCPY_HACKS |
---|
| 88 | memcpy(t->norm, s->norm, t->length * sizeof(smpl_t)); |
---|
| 89 | memcpy(t->phas, s->phas, t->length * sizeof(smpl_t)); |
---|
| 90 | #else |
---|
| 91 | uint_t j; |
---|
| 92 | for (j=0; j< t->length; j++) { |
---|
| 93 | t->norm[j] = s->norm[j]; |
---|
| 94 | t->phas[j] = s->phas[j]; |
---|
| 95 | } |
---|
| 96 | #endif |
---|
| 97 | } |
---|
| 98 | |
---|
[5d10ac1] | 99 | void cvec_norm_set_all (cvec_t *s, smpl_t val) { |
---|
[66fb3ea] | 100 | uint_t j; |
---|
| 101 | for (j=0; j< s->length; j++) { |
---|
| 102 | s->norm[j] = val; |
---|
[012466b] | 103 | } |
---|
| 104 | } |
---|
| 105 | |
---|
[5d10ac1] | 106 | void cvec_norm_zeros(cvec_t *s) { |
---|
[39a7b26] | 107 | #if HAVE_MEMCPY_HACKS |
---|
| 108 | memset(s->norm, 0, s->length * sizeof(smpl_t)); |
---|
| 109 | #else |
---|
[5d10ac1] | 110 | cvec_norm_set_all (s, 0.); |
---|
[39a7b26] | 111 | #endif |
---|
[012466b] | 112 | } |
---|
| 113 | |
---|
[5d10ac1] | 114 | void cvec_norm_ones(cvec_t *s) { |
---|
| 115 | cvec_norm_set_all (s, 1.); |
---|
[012466b] | 116 | } |
---|
| 117 | |
---|
[5d10ac1] | 118 | void cvec_phas_set_all (cvec_t *s, smpl_t val) { |
---|
[39a7b26] | 119 | uint_t j; |
---|
| 120 | for (j=0; j< s->length; j++) { |
---|
| 121 | s->phas[j] = val; |
---|
| 122 | } |
---|
| 123 | } |
---|
| 124 | |
---|
[5d10ac1] | 125 | void cvec_phas_zeros(cvec_t *s) { |
---|
[39a7b26] | 126 | #if HAVE_MEMCPY_HACKS |
---|
| 127 | memset(s->phas, 0, s->length * sizeof(smpl_t)); |
---|
| 128 | #else |
---|
[5d10ac1] | 129 | cvec_phas_set_all (s, 0.); |
---|
[39a7b26] | 130 | #endif |
---|
| 131 | } |
---|
| 132 | |
---|
[5d10ac1] | 133 | void cvec_phas_ones(cvec_t *s) { |
---|
| 134 | cvec_phas_set_all (s, 1.); |
---|
[39a7b26] | 135 | } |
---|
| 136 | |
---|
| 137 | void cvec_zeros(cvec_t *s) { |
---|
[5d10ac1] | 138 | cvec_norm_zeros(s); |
---|
| 139 | cvec_phas_zeros(s); |
---|
[39a7b26] | 140 | } |
---|