source: src/cvec.c @ 0d63b5f

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5
Last change on this file since 0d63b5f was f080cbf, checked in by Paul Brossier <piem@piem.org>, 7 years ago

src/cvec.c: fix indentation

  • Property mode set to 100644
File size: 3.9 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
24cvec_t * new_cvec(uint_t length) {
25  cvec_t * s;
26  if ((sint_t)length <= 0) {
27    return NULL;
28  }
29  s = AUBIO_NEW(cvec_t);
30  s->length = length/2 + 1;
31  s->norm = AUBIO_ARRAY(smpl_t,s->length);
32  s->phas = AUBIO_ARRAY(smpl_t,s->length);
33  return s;
34}
35
36void del_cvec(cvec_t *s) {
37  AUBIO_FREE(s->norm);
38  AUBIO_FREE(s->phas);
39  AUBIO_FREE(s);
40}
41
42void cvec_norm_set_sample (cvec_t *s, smpl_t data, uint_t position) {
43  s->norm[position] = data;
44}
45
46void cvec_phas_set_sample (cvec_t *s, smpl_t data, uint_t position) {
47  s->phas[position] = data;
48}
49
50smpl_t cvec_norm_get_sample (cvec_t *s, uint_t position) {
51  return s->norm[position];
52}
53
54smpl_t cvec_phas_get_sample (cvec_t *s, uint_t position) {
55  return s->phas[position];
56}
57
58smpl_t * cvec_norm_get_data (const cvec_t *s) {
59  return s->norm;
60}
61
62smpl_t * cvec_phas_get_data (const cvec_t *s) {
63  return s->phas;
64}
65
66/* helper functions */
67
68void cvec_print(const cvec_t *s) {
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]);
78  }
79  AUBIO_MSG("\n");
80}
81
82void cvec_copy(const cvec_t *s, cvec_t *t) {
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  }
88#if defined(HAVE_INTEL_IPP)
89  aubio_ippsCopy(s->phas, t->phas, (int)s->length);
90  aubio_ippsCopy(s->norm, t->norm, (int)s->length);
91#elif defined(HAVE_MEMCPY_HACKS)
92  memcpy(t->norm, s->norm, t->length * sizeof(smpl_t));
93  memcpy(t->phas, s->phas, t->length * sizeof(smpl_t));
94#else
95  uint_t j;
96  for (j=0; j< t->length; j++) {
97    t->norm[j] = s->norm[j];
98    t->phas[j] = s->phas[j];
99  }
100#endif
101}
102
103void cvec_norm_set_all(cvec_t *s, smpl_t val) {
104#if defined(HAVE_INTEL_IPP)
105  aubio_ippsSet(val, s->norm, (int)s->length);
106#else
107  uint_t j;
108  for (j=0; j< s->length; j++) {
109    s->norm[j] = val;
110  }
111#endif
112}
113
114void cvec_norm_zeros(cvec_t *s) {
115#if defined(HAVE_INTEL_IPP)
116  aubio_ippsZero(s->norm, (int)s->length);
117#elif defined(HAVE_MEMCPY_HACKS)
118  memset(s->norm, 0, s->length * sizeof(smpl_t));
119#else
120  cvec_norm_set_all (s, 0.);
121#endif
122}
123
124void cvec_norm_ones(cvec_t *s) {
125  cvec_norm_set_all (s, 1.);
126}
127
128void cvec_phas_set_all (cvec_t *s, smpl_t val) {
129#if defined(HAVE_INTEL_IPP)
130  aubio_ippsSet(val, s->phas, (int)s->length);
131#else
132  uint_t j;
133  for (j=0; j< s->length; j++) {
134    s->phas[j] = val;
135  }
136#endif
137}
138
139void cvec_phas_zeros(cvec_t *s) {
140#if defined(HAVE_INTEL_IPP)
141  aubio_ippsZero(s->phas, (int)s->length);
142#elif defined(HAVE_MEMCPY_HACKS)
143  memset(s->phas, 0, s->length * sizeof(smpl_t));
144#else
145  cvec_phas_set_all (s, 0.);
146#endif
147}
148
149void cvec_phas_ones(cvec_t *s) {
150  cvec_phas_set_all (s, 1.);
151}
152
153void cvec_zeros(cvec_t *s) {
154  cvec_norm_zeros(s);
155  cvec_phas_zeros(s);
156}
157
158void cvec_logmag(cvec_t *s, smpl_t lambda) {
159#if defined(HAVE_INTEL_IPP)
160  aubio_ippsMulC(s->norm, lambda, s->norm, (int)s->length);
161  aubio_ippsAddC(s->norm, 1.0, s->norm, (int)s->length);
162  aubio_ippsLn(s->norm, s->norm, (int)s->length);
163#else
164  uint_t j;
165  for (j=0; j< s->length; j++) {
166    s->norm[j] = LOG(lambda * s->norm[j] + 1);
167  }
168#endif
169}
Note: See TracBrowser for help on using the repository browser.