source: src/cvec.c @ 986131d

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5
Last change on this file since 986131d was 986131d, checked in by Eduard Müller <mueller.eduard@googlemail.com>, 7 years ago

Intel IPP support for aubio

See emuell/aubio/ intel_ipp2 for details please

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