Changeset f264b17 for src/mathutils.c


Ignore:
Timestamp:
Jun 22, 2016, 1:00:10 PM (9 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
4b9443c4
Parents:
60fc05b (diff), 6769586 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into notes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mathutils.c

    r60fc05b rf264b17  
    2626#include "musicutils.h"
    2727#include "config.h"
    28 
    29 #ifdef HAVE_ACCELERATE
    30 #include <Accelerate/Accelerate.h>
    31 #endif
    3228
    3329/** Window types */
     
    167163  return tmp / (smpl_t) (s->length);
    168164#else
    169 #if !HAVE_AUBIO_DOUBLE
    170   vDSP_meanv(s->data, 1, &tmp, s->length);
    171 #else /* HAVE_AUBIO_DOUBLE */
    172   vDSP_meanvD(s->data, 1, &tmp, s->length);
    173 #endif /* HAVE_AUBIO_DOUBLE */
     165  aubio_vDSP_meanv(s->data, 1, &tmp, s->length);
    174166  return tmp;
    175167#endif /* HAVE_ACCELERATE */
     
    186178  }
    187179#else
    188 #if !HAVE_AUBIO_DOUBLE
    189   vDSP_sve(s->data, 1, &tmp, s->length);
    190 #else /* HAVE_AUBIO_DOUBLE */
    191   vDSP_sveD(s->data, 1, &tmp, s->length);
    192 #endif /* HAVE_AUBIO_DOUBLE */
     180  aubio_vDSP_sve(s->data, 1, &tmp, s->length);
    193181#endif /* HAVE_ACCELERATE */
    194182  return tmp;
     
    206194#else
    207195  smpl_t tmp = 0.;
    208 #if !HAVE_AUBIO_DOUBLE
    209   vDSP_maxv(s->data, 1, &tmp, s->length);
    210 #else
    211   vDSP_maxvD(s->data, 1, &tmp, s->length);
    212 #endif
     196  aubio_vDSP_maxv(s->data, 1, &tmp, s->length);
    213197#endif
    214198  return tmp;
     
    226210#else
    227211  smpl_t tmp = 0.;
    228 #if !HAVE_AUBIO_DOUBLE
    229   vDSP_minv(s->data, 1, &tmp, s->length);
    230 #else
    231   vDSP_minvD(s->data, 1, &tmp, s->length);
    232 #endif
     212  aubio_vDSP_minv(s->data, 1, &tmp, s->length);
    233213#endif
    234214  return tmp;
     
    248228  smpl_t tmp = 0.;
    249229  uint_t pos = 0.;
    250 #if !HAVE_AUBIO_DOUBLE
    251   vDSP_minvi(s->data, 1, &tmp, (vDSP_Length *)&pos, s->length);
    252 #else
    253   vDSP_minviD(s->data, 1, &tmp, (vDSP_Length *)&pos, s->length);
    254 #endif
     230  aubio_vDSP_minvi(s->data, 1, &tmp, (vDSP_Length *)&pos, s->length);
    255231#endif
    256232  return pos;
     
    270246  smpl_t tmp = 0.;
    271247  uint_t pos = 0.;
    272 #if !HAVE_AUBIO_DOUBLE
    273   vDSP_maxvi(s->data, 1, &tmp, (vDSP_Length *)&pos, s->length);
    274 #else
    275   vDSP_maxviD(s->data, 1, &tmp, (vDSP_Length *)&pos, s->length);
    276 #endif
     248  aubio_vDSP_maxvi(s->data, 1, &tmp, (vDSP_Length *)&pos, s->length);
    277249#endif
    278250  return pos;
     
    282254fvec_shift (fvec_t * s)
    283255{
    284   uint_t j;
    285   for (j = 0; j < s->length / 2; j++) {
    286     ELEM_SWAP (s->data[j], s->data[j + s->length / 2]);
    287   }
    288 }
    289 
    290 smpl_t
    291 aubio_level_lin (fvec_t * f)
     256  uint_t half = s->length / 2, start = half, j;
     257  // if length is odd, middle element is moved to the end
     258  if (2 * half < s->length) start ++;
     259#ifndef HAVE_ATLAS
     260  for (j = 0; j < half; j++) {
     261    ELEM_SWAP (s->data[j], s->data[j + start]);
     262  }
     263#else
     264  aubio_cblas_swap(half, s->data, 1, s->data + start, 1);
     265#endif
     266  if (start != half) {
     267    for (j = 0; j < half; j++) {
     268      ELEM_SWAP (s->data[j + start - 1], s->data[j + start]);
     269    }
     270  }
     271}
     272
     273void
     274fvec_ishift (fvec_t * s)
     275{
     276  uint_t half = s->length / 2, start = half, j;
     277  // if length is odd, middle element is moved to the beginning
     278  if (2 * half < s->length) start ++;
     279#ifndef HAVE_ATLAS
     280  for (j = 0; j < half; j++) {
     281    ELEM_SWAP (s->data[j], s->data[j + start]);
     282  }
     283#else
     284  aubio_cblas_swap(half, s->data, 1, s->data + start, 1);
     285#endif
     286  if (start != half) {
     287    for (j = 0; j < half; j++) {
     288      ELEM_SWAP (s->data[half], s->data[j]);
     289    }
     290  }
     291}
     292
     293smpl_t
     294aubio_level_lin (const fvec_t * f)
    292295{
    293296  smpl_t energy = 0.;
     297#ifndef HAVE_ATLAS
    294298  uint_t j;
    295299  for (j = 0; j < f->length; j++) {
    296300    energy += SQR (f->data[j]);
    297301  }
     302#else
     303  energy = aubio_cblas_dot(f->length, f->data, 1, f->data, 1);
     304#endif
    298305  return energy / f->length;
    299306}
     
    434441}
    435442
    436 smpl_t fvec_quadratic_peak_pos (fvec_t * x, uint_t pos) {
     443smpl_t fvec_quadratic_peak_pos (const fvec_t * x, uint_t pos) {
    437444  smpl_t s0, s1, s2; uint_t x0, x2;
     445  smpl_t half = .5, two = 2.;
    438446  if (pos == 0 || pos == x->length - 1) return pos;
    439447  x0 = (pos < 1) ? pos : pos - 1;
     
    444452  s1 = x->data[pos];
    445453  s2 = x->data[x2];
    446   return pos + 0.5 * (s0 - s2 ) / (s0 - 2.* s1 + s2);
     454  return pos + half * (s0 - s2 ) / (s0 - two * s1 + s2);
    447455}
    448456
     
    458466}
    459467
    460 uint_t fvec_peakpick(fvec_t * onset, uint_t pos) {
     468uint_t fvec_peakpick(const fvec_t * onset, uint_t pos) {
    461469  uint_t tmp=0;
    462470  tmp = (onset->data[pos] > onset->data[pos-1]
     
    545553
    546554smpl_t
    547 aubio_db_spl (fvec_t * o)
     555aubio_db_spl (const fvec_t * o)
    548556{
    549557  return 10. * LOG10 (aubio_level_lin (o));
     
    551559
    552560uint_t
    553 aubio_silence_detection (fvec_t * o, smpl_t threshold)
     561aubio_silence_detection (const fvec_t * o, smpl_t threshold)
    554562{
    555563  return (aubio_db_spl (o) < threshold);
     
    591599
    592600void
    593 aubio_autocorr (fvec_t * input, fvec_t * output)
     601aubio_autocorr (const fvec_t * input, fvec_t * output)
    594602{
    595603  uint_t i, j, length = input->length;
Note: See TracChangeset for help on using the changeset viewer.