[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) { |
---|
[96fb8ad] | 25 | cvec_t * s = AUBIO_NEW(cvec_t); |
---|
| 26 | s->length = length/2 + 1; |
---|
[66fb3ea] | 27 | s->norm = AUBIO_ARRAY(smpl_t,s->length); |
---|
| 28 | s->phas = AUBIO_ARRAY(smpl_t,s->length); |
---|
[96fb8ad] | 29 | return s; |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | void del_cvec(cvec_t *s) { |
---|
| 33 | AUBIO_FREE(s->norm); |
---|
| 34 | AUBIO_FREE(s->phas); |
---|
| 35 | AUBIO_FREE(s); |
---|
| 36 | } |
---|
[7c206df] | 37 | |
---|
[66fb3ea] | 38 | void cvec_write_norm(cvec_t *s, smpl_t data, uint_t position) { |
---|
| 39 | s->norm[position] = data; |
---|
[7c206df] | 40 | } |
---|
[66fb3ea] | 41 | void cvec_write_phas(cvec_t *s, smpl_t data, uint_t position) { |
---|
| 42 | s->phas[position] = data; |
---|
[7c206df] | 43 | } |
---|
[66fb3ea] | 44 | smpl_t cvec_read_norm(cvec_t *s, uint_t position) { |
---|
| 45 | return s->norm[position]; |
---|
[7c206df] | 46 | } |
---|
[66fb3ea] | 47 | smpl_t cvec_read_phas(cvec_t *s, uint_t position) { |
---|
| 48 | return s->phas[position]; |
---|
[7c206df] | 49 | } |
---|
[66fb3ea] | 50 | smpl_t * cvec_get_norm(cvec_t *s) { |
---|
[7c206df] | 51 | return s->norm; |
---|
| 52 | } |
---|
[66fb3ea] | 53 | smpl_t * cvec_get_phas(cvec_t *s) { |
---|
[7c206df] | 54 | return s->phas; |
---|
| 55 | } |
---|
[d1ec8cb] | 56 | |
---|
[55b7cb4] | 57 | /* helper functions */ |
---|
| 58 | |
---|
| 59 | void cvec_print(cvec_t *s) { |
---|
[66fb3ea] | 60 | uint_t j; |
---|
| 61 | AUBIO_MSG("norm: "); |
---|
| 62 | for (j=0; j< s->length; j++) { |
---|
| 63 | AUBIO_MSG(AUBIO_SMPL_FMT " ", s->norm[j]); |
---|
| 64 | } |
---|
| 65 | AUBIO_MSG("\n"); |
---|
| 66 | AUBIO_MSG("phas: "); |
---|
| 67 | for (j=0; j< s->length; j++) { |
---|
| 68 | AUBIO_MSG(AUBIO_SMPL_FMT " ", s->phas[j]); |
---|
[55b7cb4] | 69 | } |
---|
[66fb3ea] | 70 | AUBIO_MSG("\n"); |
---|
[55b7cb4] | 71 | } |
---|
| 72 | |
---|
[39a7b26] | 73 | void cvec_copy(cvec_t *s, cvec_t *t) { |
---|
| 74 | if (s->length != t->length) { |
---|
| 75 | AUBIO_ERR("trying to copy %d elements to %d elements \n", |
---|
| 76 | s->length, t->length); |
---|
| 77 | return; |
---|
| 78 | } |
---|
| 79 | #if HAVE_MEMCPY_HACKS |
---|
| 80 | memcpy(t->norm, s->norm, t->length * sizeof(smpl_t)); |
---|
| 81 | memcpy(t->phas, s->phas, t->length * sizeof(smpl_t)); |
---|
| 82 | #else |
---|
| 83 | uint_t j; |
---|
| 84 | for (j=0; j< t->length; j++) { |
---|
| 85 | t->norm[j] = s->norm[j]; |
---|
| 86 | t->phas[j] = s->phas[j]; |
---|
| 87 | } |
---|
| 88 | #endif |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | void cvec_set_all_norm(cvec_t *s, smpl_t val) { |
---|
[66fb3ea] | 92 | uint_t j; |
---|
| 93 | for (j=0; j< s->length; j++) { |
---|
| 94 | s->norm[j] = val; |
---|
[012466b] | 95 | } |
---|
| 96 | } |
---|
| 97 | |
---|
[39a7b26] | 98 | void cvec_zeros_norm(cvec_t *s) { |
---|
| 99 | #if HAVE_MEMCPY_HACKS |
---|
| 100 | memset(s->norm, 0, s->length * sizeof(smpl_t)); |
---|
| 101 | #else |
---|
| 102 | cvec_set_all_norm(s, 0.); |
---|
| 103 | #endif |
---|
[012466b] | 104 | } |
---|
| 105 | |
---|
[39a7b26] | 106 | void cvec_ones_norm(cvec_t *s) { |
---|
| 107 | cvec_set_all_norm(s, 1.); |
---|
[012466b] | 108 | } |
---|
| 109 | |
---|
[39a7b26] | 110 | void cvec_set_all_phas(cvec_t *s, smpl_t val) { |
---|
| 111 | uint_t j; |
---|
| 112 | for (j=0; j< s->length; j++) { |
---|
| 113 | s->phas[j] = val; |
---|
| 114 | } |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | void cvec_zeros_phas(cvec_t *s) { |
---|
| 118 | #if HAVE_MEMCPY_HACKS |
---|
| 119 | memset(s->phas, 0, s->length * sizeof(smpl_t)); |
---|
| 120 | #else |
---|
| 121 | cvec_set_all_phas(s, 0.); |
---|
| 122 | #endif |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | void cvec_ones_phas(cvec_t *s) { |
---|
| 126 | cvec_set_all_phas(s, 1.); |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | void cvec_zeros(cvec_t *s) { |
---|
| 130 | cvec_zeros_norm(s); |
---|
| 131 | cvec_zeros_phas(s); |
---|
| 132 | } |
---|