source: src/spectral/dct_ipp.c @ 2e5c52e

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

src/spectral/dct_ipp.c: add ipp dct

  • Property mode set to 100644
File size: 4.7 KB
Line 
1/*
2  Copyright (C) 2017 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 "fvec.h"
23#include "cvec.h"
24#include "spectral/dct.h"
25
26#if defined(HAVE_INTEL_IPP)
27
28#if !HAVE_AUBIO_DOUBLE
29#define aubio_IppFloat                 Ipp32f
30#define aubio_ippsDCTFwdSpec           IppsDCTFwdSpec_32f
31#define aubio_ippsDCTInvSpec           IppsDCTInvSpec_32f
32#define aubio_ippsDCTFwdGetSize        ippsDCTFwdGetSize_32f
33#define aubio_ippsDCTInvGetSize        ippsDCTInvGetSize_32f
34#define aubio_ippsDCTFwdInit           ippsDCTFwdInit_32f
35#define aubio_ippsDCTInvInit           ippsDCTInvInit_32f
36#define aubio_ippsDCTFwd               ippsDCTFwd_32f
37#define aubio_ippsDCTInv               ippsDCTInv_32f
38#else /* HAVE_AUBIO_DOUBLE */
39#define aubio_IppFloat                 Ipp64f
40#define aubio_ippsDCTFwdSpec           IppsDCTFwdSpec_64f
41#define aubio_ippsDCTInvSpec           IppsDCTInvSpec_64f
42#define aubio_ippsDCTFwdGetSize        ippsDCTFwdGetSize_64f
43#define aubio_ippsDCTInvGetSize        ippsDCTInvGetSize_64f
44#define aubio_ippsDCTFwdInit           ippsDCTFwdInit_64f
45#define aubio_ippsDCTInvInit           ippsDCTInvInit_64f
46#define aubio_ippsDCTFwd               ippsDCTFwd_64f
47#define aubio_ippsDCTInv               ippsDCTInv_64f
48#endif
49
50struct _aubio_dct_t {
51  uint_t size;
52  Ipp8u* pSpec;
53  Ipp8u* pSpecBuffer;
54  Ipp8u* pBuffer;
55  Ipp8u* pSpecInv;
56  Ipp8u* pSpecBufferInv;
57  Ipp8u* pBufferInv;
58  aubio_ippsDCTFwdSpec* pFwdDCTSpec;
59  aubio_ippsDCTInvSpec* pInvDCTSpec;
60};
61
62aubio_dct_t * new_aubio_dct (uint_t size) {
63  aubio_dct_t * s = AUBIO_NEW(aubio_dct_t);
64
65  const IppHintAlgorithm qualityHint = ippAlgHintAccurate; // ippAlgHintFast;
66  int pSpecSize, pSpecBufferSize, pBufferSize;
67  IppStatus status;
68
69  if ((sint_t)size <= 1) {
70    AUBIO_ERR("dct: can only create with sizes greater than 1, requested %d\n",
71        size);
72    goto beach;
73  }
74
75  status = aubio_ippsDCTFwdGetSize(size, qualityHint, &pSpecSize,
76      &pSpecBufferSize, &pBufferSize);
77  if (status != ippStsNoErr) {
78    AUBIO_ERR("dct: failed to initialize dct. IPP error: %d\n", status);
79    goto beach;
80  }
81
82  //AUBIO_INF("dct: fwd initialized with %d %d %d\n", pSpecSize, pSpecBufferSize,
83  //    pBufferSize);
84
85  s->pSpec = ippsMalloc_8u(pSpecSize);
86  if (pSpecSize > 0) {
87    s->pSpecBuffer = ippsMalloc_8u(pSpecBufferSize);
88  } else {
89    s->pSpecBuffer = NULL;
90  }
91  s->pBuffer = ippsMalloc_8u(pBufferSize);
92
93  status = aubio_ippsDCTInvGetSize(size, qualityHint, &pSpecSize,
94      &pSpecBufferSize, &pBufferSize);
95  if (status != ippStsNoErr) {
96    AUBIO_ERR("dct: failed to initialize dct. IPP error: %d\n", status);
97    goto beach;
98  }
99
100  //AUBIO_INF("dct: inv initialized with %d %d %d\n", pSpecSize, pSpecBufferSize,
101  //    pBufferSize);
102
103  s->pSpecInv = ippsMalloc_8u(pSpecSize);
104  if (pSpecSize > 0) {
105    s->pSpecBufferInv = ippsMalloc_8u(pSpecBufferSize);
106  } else {
107    s->pSpecBufferInv = NULL;
108  }
109  s->pBufferInv = ippsMalloc_8u(pBufferSize);
110
111  status = aubio_ippsDCTFwdInit(&(s->pFwdDCTSpec), size, qualityHint, s->pSpec,
112      s->pSpecBuffer);
113  if (status != ippStsNoErr) {
114    AUBIO_ERR("dct: failed to initialize fwd dct. IPP error: %d\n", status);
115    goto beach;
116  }
117
118  status = aubio_ippsDCTInvInit(&(s->pInvDCTSpec), size, qualityHint,
119      s->pSpecInv, s->pSpecBufferInv);
120  if (status != ippStsNoErr) {
121    AUBIO_ERR("dct: failed to initialize inv dct. IPP error: %d\n", status);
122    goto beach;
123  }
124
125  s->size = size;
126
127  return s;
128
129beach:
130  del_aubio_dct(s);
131  return NULL;
132}
133
134void del_aubio_dct(aubio_dct_t *s) {
135  ippFree(s->pSpec);
136  ippFree(s->pSpecBuffer);
137  ippFree(s->pBuffer);
138  ippFree(s->pSpecInv);
139  ippFree(s->pSpecBufferInv);
140  ippFree(s->pBufferInv);
141  AUBIO_FREE(s);
142}
143
144void aubio_dct_do(aubio_dct_t *s, const fvec_t *input, fvec_t *output) {
145
146  aubio_ippsDCTFwd((const aubio_IppFloat*)input->data,
147      (aubio_IppFloat*)output->data, s->pFwdDCTSpec, s->pBuffer);
148
149}
150
151void aubio_dct_rdo(aubio_dct_t *s, const fvec_t *input, fvec_t *output) {
152
153  aubio_ippsDCTInv((const aubio_IppFloat*)input->data,
154      (aubio_IppFloat*)output->data, s->pInvDCTSpec, s->pBuffer);
155
156}
157
158#endif //defined(HAVE_INTEL_IPP)
Note: See TracBrowser for help on using the repository browser.