source: src/cvec.c @ 986131d

feature/autosinkfeature/constantqfeature/pitchshiftfeature/pydocstringsfeature/timestretch
Last change on this file since 986131d was 986131d, checked in by Eduard Müller <mueller.eduard@googlemail.com>, 2 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
Line 
1/*
2  Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
3
4  This file is part of aubio.
5
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.
10
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/>.
18
19*/
20
21#include "aubio_priv.h"
22#include "cvec.h"
23
24#if defined HAVE_INTEL_IPP
25#include <ippcore.h>
26#include <ippvm.h>
27#include <ipps.h>
28#endif
29
30cvec_t * new_cvec(uint_t length) {
31  cvec_t * s;
32  if ((sint_t)length <= 0) {
33    return NULL;
34  }
35  s = AUBIO_NEW(cvec_t);
36  s->length = length/2 + 1;
37  s->norm = AUBIO_ARRAY(smpl_t,s->length);
38  s->phas = AUBIO_ARRAY(smpl_t,s->length);
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}
47
48void cvec_norm_set_sample (cvec_t *s, smpl_t data, uint_t position) {
49  s->norm[position] = data;
50}
51
52void cvec_phas_set_sample (cvec_t *s, smpl_t data, uint_t position) {
53  s->phas[position] = data;
54}
55
56smpl_t cvec_norm_get_sample (cvec_t *s, uint_t position) {
57  return s->norm[position];
58}
59
60smpl_t cvec_phas_get_sample (cvec_t *s, uint_t position) {
61  return s->phas[position];
62}
63
64smpl_t * cvec_norm_get_data (const cvec_t *s) {
65  return s->norm;
66}
67
68smpl_t * cvec_phas_get_data (const cvec_t *s) {
69  return s->phas;
70}
71
72/* helper functions */
73
74void cvec_print(const cvec_t *s) {
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]);
84  }
85  AUBIO_MSG("\n");
86}
87
88void cvec_copy(const cvec_t *s, cvec_t *t) {
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  }
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)
103  memcpy(t->norm, s->norm, t->length * sizeof(smpl_t));
104  memcpy(t->phas, s->phas, t->length * sizeof(smpl_t));
105#else
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  }
111#endif
112}
113
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
122  uint_t j;
123  for (j=0; j< s->length; j++) {
124    s->norm[j] = val;
125  }
126#endif
127}
128
129void cvec_norm_zeros(cvec_t *s) {
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)
137  memset(s->norm, 0, s->length * sizeof(smpl_t));
138#else
139  cvec_norm_set_all (s, 0.);
140#endif
141}
142
143void cvec_norm_ones(cvec_t *s) {
144  cvec_norm_set_all (s, 1.);
145}
146
147void cvec_phas_set_all (cvec_t *s, smpl_t val) {
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
155  uint_t j;
156  for (j=0; j< s->length; j++) {
157    s->phas[j] = val;
158  }
159#endif
160}
161
162void cvec_phas_zeros(cvec_t *s) {
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)
170  memset(s->phas, 0, s->length * sizeof(smpl_t));
171#else
172  cvec_phas_set_all (s, 0.);
173#endif
174}
175
176void cvec_phas_ones(cvec_t *s) {
177  cvec_phas_set_all (s, 1.);
178}
179
180void cvec_zeros(cvec_t *s) {
181  cvec_norm_zeros(s);
182  cvec_phas_zeros(s);
183}
184
185void cvec_logmag(cvec_t *s, smpl_t lambda) {
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
202}
Note: See TracBrowser for help on using the repository browser.