Index: src/aubio.h
===================================================================
--- src/aubio.h	(revision 230101d2de1f7e3c993dc16e3ac57d3cbacdd07c)
+++ src/aubio.h	(revision 189c6ae6ed15ad2875bb0331110f681949fe2868)
@@ -183,4 +183,5 @@
 #include "temporal/c_weighting.h"
 #include "spectral/fft.h"
+#include "spectral/dct.h"
 #include "spectral/phasevoc.h"
 #include "spectral/filterbank.h"
Index: src/aubio_priv.h
===================================================================
--- src/aubio_priv.h	(revision 230101d2de1f7e3c993dc16e3ac57d3cbacdd07c)
+++ src/aubio_priv.h	(revision 189c6ae6ed15ad2875bb0331110f681949fe2868)
@@ -86,4 +86,6 @@
 #define aubio_vDSP_mmov       vDSP_mmov
 #define aubio_vDSP_vmul       vDSP_vmul
+#define aubio_vDSP_vsmul      vDSP_vsmul
+#define aubio_vDSP_vsadd      vDSP_vsadd
 #define aubio_vDSP_vfill      vDSP_vfill
 #define aubio_vDSP_meanv      vDSP_meanv
@@ -98,4 +100,6 @@
 #define aubio_vDSP_mmov       vDSP_mmovD
 #define aubio_vDSP_vmul       vDSP_vmulD
+#define aubio_vDSP_vsmul      vDSP_vsmulD
+#define aubio_vDSP_vsadd      vDSP_vsaddD
 #define aubio_vDSP_vfill      vDSP_vfillD
 #define aubio_vDSP_meanv      vDSP_meanvD
Index: src/spectral/dct.h
===================================================================
--- src/spectral/dct.h	(revision 189c6ae6ed15ad2875bb0331110f681949fe2868)
+++ src/spectral/dct.h	(revision 189c6ae6ed15ad2875bb0331110f681949fe2868)
@@ -0,0 +1,85 @@
+/*
+  Copyright (C) 2017 Paul Brossier <piem@aubio.org>
+
+  This file is part of aubio.
+
+  aubio is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  aubio is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with aubio.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+/** \file
+
+  Discrete Cosine Transform
+
+  Functions aubio_dct_do() and aubio_dct_rdo() are equivalent to MATLAB/Octave
+  dct() and idct() functions, as well as scipy.fftpack.dct(x, norm='ortho') and
+  scipy.fftpack.idct(x, norm='ortho')
+
+  \example spectral/test-dct.c
+
+*/
+
+#ifndef AUBIO_DCT_H
+#define AUBIO_DCT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** DCT object
+
+  This object computes forward and backward DCT type 2 with orthonormal
+  scaling.
+
+*/
+typedef struct _aubio_dct_t aubio_dct_t;
+
+/** create new DCT computation object
+
+  \param size length of the DCT
+
+*/
+aubio_dct_t * new_aubio_dct(uint_t size);
+
+/** compute forward DCT
+
+  \param s dct object as returned by new_aubio_dct
+  \param input input signal
+  \param output transformed input array
+
+*/
+void aubio_dct_do (aubio_dct_t *s, const fvec_t * input, fvec_t * output);
+
+/** compute backward DCT
+
+  \param s dct object as returned by new_aubio_dct
+  \param input input signal
+  \param output transformed input array
+
+*/
+void aubio_dct_rdo (aubio_dct_t *s, const fvec_t * input, fvec_t * output);
+
+
+/** delete DCT object
+
+  \param s dct object as returned by new_aubio_dct
+
+*/
+void del_aubio_dct (aubio_dct_t *s);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* AUBIO_DCT_H */
Index: src/spectral/dct_accelerate.c
===================================================================
--- src/spectral/dct_accelerate.c	(revision 189c6ae6ed15ad2875bb0331110f681949fe2868)
+++ src/spectral/dct_accelerate.c	(revision 189c6ae6ed15ad2875bb0331110f681949fe2868)
@@ -0,0 +1,99 @@
+/*
+  Copyright (C) 2017 Paul Brossier <piem@aubio.org>
+
+  This file is part of aubio.
+
+  aubio is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  aubio is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with aubio.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include "aubio_priv.h"
+#include "fvec.h"
+#include "cvec.h"
+#include "spectral/dct.h"
+
+#if defined(HAVE_ACCELERATE)
+
+#if HAVE_AUBIO_DOUBLE
+#warning "no double-precision dct with accelerate"
+#endif
+
+struct _aubio_dct_t {
+  uint_t size;
+  fvec_t *tmp;
+  vDSP_DFT_Setup setup;
+  vDSP_DFT_Setup setupInv;
+};
+
+aubio_dct_t * new_aubio_dct (uint_t size) {
+  aubio_dct_t * s = AUBIO_NEW(aubio_dct_t);
+
+  if ((sint_t)size < 16 || !aubio_is_power_of_two(size)) {
+    AUBIO_ERR("dct: can only create with sizes greater than 16 and"
+        "that are powers of two, requested %d\n", size);
+    goto beach;
+  }
+
+  s->setup = vDSP_DCT_CreateSetup(NULL, (vDSP_Length)size, vDSP_DCT_II);
+  s->setupInv = vDSP_DCT_CreateSetup(NULL, (vDSP_Length)size, vDSP_DCT_III);
+  if (s->setup == NULL || s->setupInv == NULL) {
+    goto beach;
+  }
+
+  s->size = size;
+
+  return s;
+
+beach:
+  del_aubio_dct(s);
+  return NULL;
+}
+
+void del_aubio_dct(aubio_dct_t *s) {
+  if (s->setup) vDSP_DFT_DestroySetup(s->setup);
+  if (s->setupInv) vDSP_DFT_DestroySetup(s->setupInv);
+  AUBIO_FREE(s);
+}
+
+void aubio_dct_do(aubio_dct_t *s, const fvec_t *input, fvec_t *output) {
+
+  vDSP_DCT_Execute(s->setup, (const float *)input->data, (float *)output->data);
+
+  // apply orthonormal scaling
+  output->data[0] *= SQRT(1./s->size);
+  smpl_t scaler = SQRT(2./s->size);
+
+  aubio_vDSP_vsmul(output->data + 1, 1, &scaler, output->data + 1, 1,
+      output->length - 1);
+
+}
+
+void aubio_dct_rdo(aubio_dct_t *s, const fvec_t *input, fvec_t *output) {
+
+  output->data[0] = input->data[0] / SQRT(1./s->size);
+  smpl_t scaler = 1./SQRT(2./s->size);
+
+  aubio_vDSP_vsmul(input->data + 1, 1, &scaler, output->data + 1, 1,
+      output->length - 1);
+
+  vDSP_DCT_Execute(s->setupInv, (const float *)output->data,
+      (float *)output->data);
+
+  scaler = 2./s->size;
+
+  aubio_vDSP_vsmul(output->data, 1, &scaler, output->data, 1, output->length);
+
+}
+
+#endif //defined(HAVE_ACCELERATE)
Index: src/spectral/dct_fftw.c
===================================================================
--- src/spectral/dct_fftw.c	(revision 189c6ae6ed15ad2875bb0331110f681949fe2868)
+++ src/spectral/dct_fftw.c	(revision 189c6ae6ed15ad2875bb0331110f681949fe2868)
@@ -0,0 +1,129 @@
+/*
+  Copyright (C) 2017 Paul Brossier <piem@aubio.org>
+
+  This file is part of aubio.
+
+  aubio is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  aubio is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with aubio.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include "aubio_priv.h"
+#include "fvec.h"
+#include "cvec.h"
+#include "spectral/dct.h"
+
+#ifdef HAVE_FFTW3
+
+#include <fftw3.h>
+#include <pthread.h>
+
+#ifdef HAVE_FFTW3F
+#if HAVE_AUBIO_DOUBLE
+#error "Using aubio in double precision with fftw3 in single precision"
+#endif /* HAVE_AUBIO_DOUBLE */
+#else  /* HAVE_FFTW3F */
+#if !HAVE_AUBIO_DOUBLE
+#error "Using aubio in single precision with fftw3 in double precision"
+#endif /* HAVE_AUBIO_DOUBLE */
+#endif /* HAVE_FFTW3F */
+
+#ifdef HAVE_FFTW3F
+#define fftw_malloc            fftwf_malloc
+#define fftw_free              fftwf_free
+#define fftw_execute           fftwf_execute
+#define fftw_plan_dft_r2c_1d   fftwf_plan_dft_r2c_1d
+#define fftw_plan_dft_c2r_1d   fftwf_plan_dft_c2r_1d
+#define fftw_plan_r2r_1d       fftwf_plan_r2r_1d
+#define fftw_plan              fftwf_plan
+#define fftw_destroy_plan      fftwf_destroy_plan
+#endif
+
+// defined in src/spectral/fft.c
+extern pthread_mutex_t aubio_fftw_mutex;
+
+extern void aubio_ooura_ddct(int, int, smpl_t *, int *, smpl_t *);
+
+struct _aubio_dct_t {
+  uint_t size;
+  fvec_t *in, *out;
+  smpl_t *data;
+  fftw_plan pfw, pbw;
+  smpl_t scalers[5];
+};
+
+aubio_dct_t * new_aubio_dct (uint_t size) {
+  aubio_dct_t * s = AUBIO_NEW(aubio_dct_t);
+  if (!s) {
+    goto beach;
+  }
+  s->size = size;
+  s->in = new_fvec(size);
+  s->out = new_fvec(size);
+  pthread_mutex_lock(&aubio_fftw_mutex);
+  s->data = (smpl_t *)fftw_malloc(sizeof(smpl_t) * size);
+  s->pfw = fftw_plan_r2r_1d(size, s->in->data,  s->data, FFTW_REDFT10,
+      FFTW_ESTIMATE);
+  s->pbw = fftw_plan_r2r_1d(size, s->data, s->out->data, FFTW_REDFT01,
+      FFTW_ESTIMATE);
+  pthread_mutex_unlock(&aubio_fftw_mutex);
+  s->scalers[0] = SQRT(1./(4.*s->size));
+  s->scalers[1] = SQRT(1./(2.*s->size));
+  s->scalers[2] = 1. / s->scalers[0];
+  s->scalers[3] = 1. / s->scalers[1];
+  s->scalers[4] = .5 / s->size;
+  return s;
+beach:
+  AUBIO_FREE(s);
+  return NULL;
+}
+
+void del_aubio_dct(aubio_dct_t *s) {
+  pthread_mutex_lock(&aubio_fftw_mutex);
+  fftw_destroy_plan(s->pfw);
+  fftw_destroy_plan(s->pbw);
+  fftw_free(s->data);
+  pthread_mutex_unlock(&aubio_fftw_mutex);
+  del_fvec(s->in);
+  del_fvec(s->out);
+  AUBIO_FREE(s);
+}
+
+void aubio_dct_do(aubio_dct_t *s, const fvec_t *input, fvec_t *output) {
+  uint_t i;
+  fvec_copy(input, s->in);
+  fftw_execute(s->pfw);
+  //fvec_copy(s->out, output);
+  s->data[0] *= s->scalers[0];
+  for (i = 1; i < s->size; i++) {
+    s->data[i] *= s->scalers[1];
+  }
+  memcpy(output->data, s->data, output->length * sizeof(smpl_t));
+}
+
+void aubio_dct_rdo(aubio_dct_t *s, const fvec_t *input, fvec_t *output) {
+  uint_t i;
+  memcpy(s->data, input->data, input->length * sizeof(smpl_t));
+  //s->data[0] *= .5;
+  s->data[0] *= s->scalers[2];
+  for (i = 1; i < s->size; i++) {
+    s->data[i] *= s->scalers[3];
+  }
+  fftw_execute(s->pbw);
+  for (i = 0; i < s->size; i++) {
+    s->out->data[i] *= s->scalers[4];
+  }
+  fvec_copy(s->out, output);
+}
+
+#endif //HAVE_FFTW3
Index: src/spectral/dct_ipp.c
===================================================================
--- src/spectral/dct_ipp.c	(revision 189c6ae6ed15ad2875bb0331110f681949fe2868)
+++ src/spectral/dct_ipp.c	(revision 189c6ae6ed15ad2875bb0331110f681949fe2868)
@@ -0,0 +1,144 @@
+/*
+  Copyright (C) 2017 Paul Brossier <piem@aubio.org>
+
+  This file is part of aubio.
+
+  aubio is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  aubio is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with aubio.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include "aubio_priv.h"
+#include "fvec.h"
+#include "cvec.h"
+#include "spectral/dct.h"
+
+#if defined(HAVE_INTEL_IPP)
+
+#if !HAVE_AUBIO_DOUBLE
+#define aubio_IppFloat                 Ipp32f
+#define aubio_ippsDCTFwdSpec           IppsDCTFwdSpec_32f
+#define aubio_ippsDCTInvSpec           IppsDCTInvSpec_32f
+#define aubio_ippsDCTFwdGetSize        ippsDCTFwdGetSize_32f
+#define aubio_ippsDCTInvGetSize        ippsDCTInvGetSize_32f
+#define aubio_ippsDCTFwdInit           ippsDCTFwdInit_32f
+#define aubio_ippsDCTInvInit           ippsDCTInvInit_32f
+#define aubio_ippsDCTFwd               ippsDCTFwd_32f
+#define aubio_ippsDCTInv               ippsDCTInv_32f
+#else /* HAVE_AUBIO_DOUBLE */
+#define aubio_IppFloat                 Ipp64f
+#define aubio_ippsDCTFwdSpec           IppsDCTFwdSpec_64f
+#define aubio_ippsDCTInvSpec           IppsDCTInvSpec_64f
+#define aubio_ippsDCTFwdGetSize        ippsDCTFwdGetSize_64f
+#define aubio_ippsDCTInvGetSize        ippsDCTInvGetSize_64f
+#define aubio_ippsDCTFwdInit           ippsDCTFwdInit_64f
+#define aubio_ippsDCTInvInit           ippsDCTInvInit_64f
+#define aubio_ippsDCTFwd               ippsDCTFwd_64f
+#define aubio_ippsDCTInv               ippsDCTInv_64f
+#endif
+
+struct _aubio_dct_t {
+  uint_t size;
+  Ipp8u* pSpec;
+  Ipp8u* pSpecBuffer;
+  Ipp8u* pBuffer;
+  aubio_ippsDCTFwdSpec* pFwdDCTSpec;
+  aubio_ippsDCTInvSpec* pInvDCTSpec;
+};
+
+aubio_dct_t * new_aubio_dct (uint_t size) {
+  aubio_dct_t * s = AUBIO_NEW(aubio_dct_t);
+
+  const IppHintAlgorithm qualityHint = ippAlgHintAccurate; // ippAlgHintFast;
+  int pSpecSize, pSpecBufferSize, pBufferSize;
+  IppStatus status;
+
+  if ((sint_t)size <= 1) {
+    AUBIO_ERR("dct: can only create with sizes greater than 1, requested %d\n",
+        size);
+    goto beach;
+  }
+
+  status = aubio_ippsDCTFwdGetSize(size, qualityHint, &pSpecSize,
+      &pSpecBufferSize, &pBufferSize);
+  if (status != ippStsNoErr) {
+    AUBIO_ERR("dct: failed to initialize dct. IPP error: %d\n", status);
+    goto beach;
+  }
+
+  //AUBIO_INF("dct: fwd initialized with %d %d %d\n", pSpecSize, pSpecBufferSize,
+  //    pBufferSize);
+
+  s->pSpec = ippsMalloc_8u(pSpecSize);
+  if (pSpecSize > 0) {
+    s->pSpecBuffer = ippsMalloc_8u(pSpecBufferSize);
+  } else {
+    s->pSpecBuffer = NULL;
+  }
+  s->pBuffer = ippsMalloc_8u(pBufferSize);
+
+  status = aubio_ippsDCTInvGetSize(size, qualityHint, &pSpecSize,
+      &pSpecBufferSize, &pBufferSize);
+  if (status != ippStsNoErr) {
+    AUBIO_ERR("dct: failed to initialize dct. IPP error: %d\n", status);
+    goto beach;
+  }
+
+  //AUBIO_INF("dct: inv initialized with %d %d %d\n", pSpecSize, pSpecBufferSize,
+  //    pBufferSize);
+
+  status = aubio_ippsDCTFwdInit(&(s->pFwdDCTSpec), size, qualityHint, s->pSpec,
+      s->pSpecBuffer);
+  if (status != ippStsNoErr) {
+    AUBIO_ERR("dct: failed to initialize fwd dct. IPP error: %d\n", status);
+    goto beach;
+  }
+
+  status = aubio_ippsDCTInvInit(&(s->pInvDCTSpec), size, qualityHint, s->pSpec,
+      s->pSpecBuffer);
+  if (status != ippStsNoErr) {
+    AUBIO_ERR("dct: failed to initialize inv dct. IPP error: %d\n", status);
+    goto beach;
+  }
+
+  s->size = size;
+
+  return s;
+
+beach:
+  del_aubio_dct(s);
+  return NULL;
+}
+
+void del_aubio_dct(aubio_dct_t *s) {
+  ippFree(s->pSpec);
+  ippFree(s->pSpecBuffer);
+  ippFree(s->pBuffer);
+  AUBIO_FREE(s);
+}
+
+void aubio_dct_do(aubio_dct_t *s, const fvec_t *input, fvec_t *output) {
+
+  aubio_ippsDCTFwd((const aubio_IppFloat*)input->data,
+      (aubio_IppFloat*)output->data, s->pFwdDCTSpec, s->pBuffer);
+
+}
+
+void aubio_dct_rdo(aubio_dct_t *s, const fvec_t *input, fvec_t *output) {
+
+  aubio_ippsDCTInv((const aubio_IppFloat*)input->data,
+      (aubio_IppFloat*)output->data, s->pInvDCTSpec, s->pBuffer);
+
+}
+
+#endif //defined(HAVE_INTEL_IPP)
Index: src/spectral/dct_ooura.c
===================================================================
--- src/spectral/dct_ooura.c	(revision 189c6ae6ed15ad2875bb0331110f681949fe2868)
+++ src/spectral/dct_ooura.c	(revision 189c6ae6ed15ad2875bb0331110f681949fe2868)
@@ -0,0 +1,95 @@
+/*
+  Copyright (C) 2017 Paul Brossier <piem@aubio.org>
+
+  This file is part of aubio.
+
+  aubio is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  aubio is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with aubio.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include "aubio_priv.h"
+#include "fvec.h"
+#include "cvec.h"
+#include "spectral/dct.h"
+
+#if !defined(HAVE_ACCELERATE) && !defined(HAVE_FFTW3) && !defined(HAVE_INTEL_IPP)
+
+extern void aubio_ooura_ddct(int, int, smpl_t *, int *, smpl_t *);
+
+struct _aubio_dct_t {
+  uint_t size;
+  fvec_t *input;
+  smpl_t *w;
+  int *ip;
+  smpl_t scalers[5];
+};
+
+aubio_dct_t * new_aubio_dct (uint_t size) {
+  aubio_dct_t * s = AUBIO_NEW(aubio_dct_t);
+  if (aubio_is_power_of_two(size) != 1) {
+    AUBIO_ERR("dct: can only create with sizes power of two, requested %d\n",
+        size);
+    goto beach;
+  }
+  s->size = size;
+  s->input = new_fvec(s->size);
+  s->w = AUBIO_ARRAY(smpl_t, s->size * 5 / 4);
+  s->ip = AUBIO_ARRAY(int, 3 + (1 << (int)FLOOR(LOG(s->size/2) / LOG(2))) / 2);
+  s->ip[0] = 0;
+  s->scalers[0] = 2. * SQRT(1./(4.*s->size));
+  s->scalers[1] = 2. * SQRT(1./(2.*s->size));
+  s->scalers[2] = 1. / s->scalers[0];
+  s->scalers[3] = 1. / s->scalers[1];
+  s->scalers[4] = 2. / s->size;
+  return s;
+beach:
+  AUBIO_FREE(s);
+  return NULL;
+}
+
+void del_aubio_dct(aubio_dct_t *s) {
+  del_fvec(s->input);
+  AUBIO_FREE(s->ip);
+  AUBIO_FREE(s->w);
+  AUBIO_FREE(s);
+}
+
+void aubio_dct_do(aubio_dct_t *s, const fvec_t *input, fvec_t *output) {
+  uint_t i = 0;
+  fvec_copy(input, s->input);
+  aubio_ooura_ddct(s->size, -1, s->input->data, s->ip, s->w);
+  // apply orthonormal scaling
+  s->input->data[0] *= s->scalers[0];
+  for (i = 1; i < s->input->length; i++) {
+    s->input->data[i] *= s->scalers[1];
+  }
+  fvec_copy(s->input, output);
+}
+
+void aubio_dct_rdo(aubio_dct_t *s, const fvec_t *input, fvec_t *output) {
+  uint_t i = 0;
+  fvec_copy(input, s->input);
+  s->input->data[0] *= s->scalers[2];
+  for (i = 1; i < s->input->length; i++) {
+    s->input->data[i] *= s->scalers[3];
+  }
+  s->input->data[0] *= .5;
+  aubio_ooura_ddct(s->size, 1, s->input->data, s->ip, s->w);
+  for (i = 0; i < s->input->length; i++) {
+    s->input->data[i] *= s->scalers[4];
+  }
+  fvec_copy(s->input, output);
+}
+
+#endif //!defined(HAVE_ACCELERATE) && !defined(HAVE_FFTW3)
