[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 | |
---|
[1120f86] | 24 | cvec_t * new_cvec(uint_t length) { |
---|
[c21acb9] | 25 | cvec_t * s; |
---|
[767990e] | 26 | if ((sint_t)length <= 0) { |
---|
| 27 | return NULL; |
---|
| 28 | } |
---|
[c21acb9] | 29 | s = AUBIO_NEW(cvec_t); |
---|
[96fb8ad] | 30 | s->length = length/2 + 1; |
---|
[66fb3ea] | 31 | s->norm = AUBIO_ARRAY(smpl_t,s->length); |
---|
| 32 | s->phas = AUBIO_ARRAY(smpl_t,s->length); |
---|
[96fb8ad] | 33 | return s; |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | void del_cvec(cvec_t *s) { |
---|
| 37 | AUBIO_FREE(s->norm); |
---|
| 38 | AUBIO_FREE(s->phas); |
---|
| 39 | AUBIO_FREE(s); |
---|
| 40 | } |
---|
[7c206df] | 41 | |
---|
[5d10ac1] | 42 | void cvec_norm_set_sample (cvec_t *s, smpl_t data, uint_t position) { |
---|
[66fb3ea] | 43 | s->norm[position] = data; |
---|
[7c206df] | 44 | } |
---|
[5d10ac1] | 45 | |
---|
| 46 | void cvec_phas_set_sample (cvec_t *s, smpl_t data, uint_t position) { |
---|
[66fb3ea] | 47 | s->phas[position] = data; |
---|
[7c206df] | 48 | } |
---|
[5d10ac1] | 49 | |
---|
| 50 | smpl_t cvec_norm_get_sample (cvec_t *s, uint_t position) { |
---|
[66fb3ea] | 51 | return s->norm[position]; |
---|
[7c206df] | 52 | } |
---|
[5d10ac1] | 53 | |
---|
| 54 | smpl_t cvec_phas_get_sample (cvec_t *s, uint_t position) { |
---|
[66fb3ea] | 55 | return s->phas[position]; |
---|
[7c206df] | 56 | } |
---|
[5d10ac1] | 57 | |
---|
[1120f86] | 58 | smpl_t * cvec_norm_get_data (const cvec_t *s) { |
---|
[7c206df] | 59 | return s->norm; |
---|
| 60 | } |
---|
[5d10ac1] | 61 | |
---|
[1120f86] | 62 | smpl_t * cvec_phas_get_data (const cvec_t *s) { |
---|
[7c206df] | 63 | return s->phas; |
---|
| 64 | } |
---|
[d1ec8cb] | 65 | |
---|
[55b7cb4] | 66 | /* helper functions */ |
---|
| 67 | |
---|
[1120f86] | 68 | void cvec_print(const cvec_t *s) { |
---|
[66fb3ea] | 69 | uint_t j; |
---|
| 70 | AUBIO_MSG("norm: "); |
---|
| 71 | for (j=0; j< s->length; j++) { |
---|
| 72 | AUBIO_MSG(AUBIO_SMPL_FMT " ", s->norm[j]); |
---|
| 73 | } |
---|
| 74 | AUBIO_MSG("\n"); |
---|
| 75 | AUBIO_MSG("phas: "); |
---|
| 76 | for (j=0; j< s->length; j++) { |
---|
| 77 | AUBIO_MSG(AUBIO_SMPL_FMT " ", s->phas[j]); |
---|
[55b7cb4] | 78 | } |
---|
[66fb3ea] | 79 | AUBIO_MSG("\n"); |
---|
[55b7cb4] | 80 | } |
---|
| 81 | |
---|
[1120f86] | 82 | void cvec_copy(const cvec_t *s, cvec_t *t) { |
---|
[39a7b26] | 83 | if (s->length != t->length) { |
---|
| 84 | AUBIO_ERR("trying to copy %d elements to %d elements \n", |
---|
| 85 | s->length, t->length); |
---|
| 86 | return; |
---|
| 87 | } |
---|
[986131d] | 88 | #if defined(HAVE_INTEL_IPP) |
---|
| 89 | #if HAVE_AUBIO_DOUBLE |
---|
| 90 | ippsCopy_64f(s->phas, t->phas, (int)s->length); |
---|
| 91 | ippsCopy_64f(s->norm, t->norm, (int)s->length); |
---|
| 92 | #else |
---|
| 93 | ippsCopy_32f(s->phas, t->phas, (int)s->length); |
---|
| 94 | ippsCopy_32f(s->norm, t->norm, (int)s->length); |
---|
| 95 | #endif |
---|
| 96 | #elif defined(HAVE_MEMCPY_HACKS) |
---|
[39a7b26] | 97 | memcpy(t->norm, s->norm, t->length * sizeof(smpl_t)); |
---|
| 98 | memcpy(t->phas, s->phas, t->length * sizeof(smpl_t)); |
---|
[986131d] | 99 | #else |
---|
[39a7b26] | 100 | uint_t j; |
---|
| 101 | for (j=0; j< t->length; j++) { |
---|
| 102 | t->norm[j] = s->norm[j]; |
---|
| 103 | t->phas[j] = s->phas[j]; |
---|
| 104 | } |
---|
[986131d] | 105 | #endif |
---|
[39a7b26] | 106 | } |
---|
| 107 | |
---|
[986131d] | 108 | void cvec_norm_set_all(cvec_t *s, smpl_t val) { |
---|
| 109 | #if defined(HAVE_INTEL_IPP) |
---|
| 110 | #if HAVE_AUBIO_DOUBLE |
---|
| 111 | ippsSet_64f(val, s->norm, (int)s->length); |
---|
| 112 | #else |
---|
| 113 | ippsSet_32f(val, s->norm, (int)s->length); |
---|
| 114 | #endif |
---|
| 115 | #else |
---|
[66fb3ea] | 116 | uint_t j; |
---|
| 117 | for (j=0; j< s->length; j++) { |
---|
| 118 | s->norm[j] = val; |
---|
[012466b] | 119 | } |
---|
[986131d] | 120 | #endif |
---|
[012466b] | 121 | } |
---|
| 122 | |
---|
[5d10ac1] | 123 | void cvec_norm_zeros(cvec_t *s) { |
---|
[986131d] | 124 | #if defined(HAVE_INTEL_IPP) |
---|
| 125 | #if HAVE_AUBIO_DOUBLE |
---|
| 126 | ippsZero_64f(s->norm, (int)s->length); |
---|
| 127 | #else |
---|
| 128 | ippsZero_32f(s->norm, (int)s->length); |
---|
| 129 | #endif |
---|
| 130 | #elif defined(HAVE_MEMCPY_HACKS) |
---|
[39a7b26] | 131 | memset(s->norm, 0, s->length * sizeof(smpl_t)); |
---|
[986131d] | 132 | #else |
---|
[5d10ac1] | 133 | cvec_norm_set_all (s, 0.); |
---|
[986131d] | 134 | #endif |
---|
[012466b] | 135 | } |
---|
| 136 | |
---|
[5d10ac1] | 137 | void cvec_norm_ones(cvec_t *s) { |
---|
| 138 | cvec_norm_set_all (s, 1.); |
---|
[012466b] | 139 | } |
---|
| 140 | |
---|
[5d10ac1] | 141 | void cvec_phas_set_all (cvec_t *s, smpl_t val) { |
---|
[986131d] | 142 | #if defined(HAVE_INTEL_IPP) |
---|
| 143 | #if HAVE_AUBIO_DOUBLE |
---|
| 144 | ippsSet_64f(val, s->phas, (int)s->length); |
---|
| 145 | #else |
---|
| 146 | ippsSet_32f(val, s->phas, (int)s->length); |
---|
| 147 | #endif |
---|
| 148 | #else |
---|
[39a7b26] | 149 | uint_t j; |
---|
| 150 | for (j=0; j< s->length; j++) { |
---|
| 151 | s->phas[j] = val; |
---|
| 152 | } |
---|
[986131d] | 153 | #endif |
---|
[39a7b26] | 154 | } |
---|
| 155 | |
---|
[5d10ac1] | 156 | void cvec_phas_zeros(cvec_t *s) { |
---|
[986131d] | 157 | #if defined(HAVE_INTEL_IPP) |
---|
| 158 | #if HAVE_AUBIO_DOUBLE |
---|
| 159 | ippsZero_64f(s->phas, (int)s->length); |
---|
| 160 | #else |
---|
| 161 | ippsZero_32f(s->phas, (int)s->length); |
---|
| 162 | #endif |
---|
| 163 | #elif defined(HAVE_MEMCPY_HACKS) |
---|
[39a7b26] | 164 | memset(s->phas, 0, s->length * sizeof(smpl_t)); |
---|
| 165 | #else |
---|
[5d10ac1] | 166 | cvec_phas_set_all (s, 0.); |
---|
[39a7b26] | 167 | #endif |
---|
| 168 | } |
---|
| 169 | |
---|
[5d10ac1] | 170 | void cvec_phas_ones(cvec_t *s) { |
---|
| 171 | cvec_phas_set_all (s, 1.); |
---|
[39a7b26] | 172 | } |
---|
| 173 | |
---|
| 174 | void cvec_zeros(cvec_t *s) { |
---|
[5d10ac1] | 175 | cvec_norm_zeros(s); |
---|
| 176 | cvec_phas_zeros(s); |
---|
[39a7b26] | 177 | } |
---|
[2f99427] | 178 | |
---|
| 179 | void cvec_logmag(cvec_t *s, smpl_t lambda) { |
---|
[986131d] | 180 | #if defined(HAVE_INTEL_IPP) |
---|
| 181 | #if HAVE_AUBIO_DOUBLE |
---|
| 182 | ippsMulC_64f(s->norm, lambda, s->norm, (int)s->length); |
---|
| 183 | ippsAddC_64f(s->norm, 1.0, s->norm, (int)s->length); |
---|
| 184 | ippsLn_64f_A26(s->norm, s->norm, (int)s->length); |
---|
| 185 | #else |
---|
| 186 | ippsMulC_32f(s->norm, lambda, s->norm, (int)s->length); |
---|
| 187 | ippsAddC_32f(s->norm, 1.0, s->norm, (int)s->length); |
---|
| 188 | ippsLn_32f_A21(s->norm, s->norm, (int)s->length); |
---|
| 189 | #endif |
---|
| 190 | #else |
---|
| 191 | uint_t j; |
---|
| 192 | for (j=0; j< s->length; j++) { |
---|
| 193 | s->norm[j] = LOG(lambda * s->norm[j] + 1); |
---|
| 194 | } |
---|
| 195 | #endif |
---|
[2f99427] | 196 | } |
---|