Changeset 633400d for src/mathutils.c


Ignore:
Timestamp:
Dec 5, 2018, 10:34:39 PM (5 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/cnn, feature/crepe, feature/pitchshift, feature/timestretch, fix/ffmpeg5, master
Children:
283a619a
Parents:
5b46bc3 (diff), f19db54 (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 feature/pitchshift

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mathutils.c

    r5b46bc3 r633400d  
    2525#include "mathutils.h"
    2626#include "musicutils.h"
    27 #include "config.h"
    2827
    2928/** Window types */
    3029typedef enum
    3130{
     31  aubio_win_ones,
    3232  aubio_win_rectangle,
    3333  aubio_win_hamming,
     
    6565      AUBIO_ERR ("window type can not be null.\n");
    6666      return 1;
    67   } else if (strcmp (window_type, "rectangle") == 0)
     67  } else if (strcmp (window_type, "ones") == 0)
     68      wintype = aubio_win_ones;
     69  else if (strcmp (window_type, "rectangle") == 0)
    6870      wintype = aubio_win_rectangle;
    6971  else if (strcmp (window_type, "hamming") == 0)
     
    9092  }
    9193  switch(wintype) {
     94    case aubio_win_ones:
     95      fvec_ones(win);
     96      break;
    9297    case aubio_win_rectangle:
    93       for (i=0;i<size;i++)
    94         w[i] = 0.5;
     98      fvec_set_all(win, .5);
    9599      break;
    96100    case aubio_win_hamming:
     
    156160{
    157161  smpl_t tmp = 0.0;
    158 #ifndef HAVE_ACCELERATE
     162#if defined(HAVE_INTEL_IPP)
     163  aubio_ippsMean(s->data, (int)s->length, &tmp);
     164  return tmp;
     165#elif defined(HAVE_ACCELERATE)
     166  aubio_vDSP_meanv(s->data, 1, &tmp, s->length);
     167  return tmp;
     168#else
    159169  uint_t j;
    160170  for (j = 0; j < s->length; j++) {
    161171    tmp += s->data[j];
    162172  }
    163   return tmp / (smpl_t) (s->length);
    164 #else
    165   aubio_vDSP_meanv(s->data, 1, &tmp, s->length);
    166   return tmp;
    167 #endif /* HAVE_ACCELERATE */
     173  return tmp / (smpl_t)(s->length);
     174#endif
    168175}
    169176
     
    172179{
    173180  smpl_t tmp = 0.0;
    174 #ifndef HAVE_ACCELERATE
     181#if defined(HAVE_INTEL_IPP)
     182  aubio_ippsSum(s->data, (int)s->length, &tmp);
     183#elif defined(HAVE_ACCELERATE)
     184  aubio_vDSP_sve(s->data, 1, &tmp, s->length);
     185#else
    175186  uint_t j;
    176187  for (j = 0; j < s->length; j++) {
    177188    tmp += s->data[j];
    178189  }
    179 #else
    180   aubio_vDSP_sve(s->data, 1, &tmp, s->length);
    181 #endif /* HAVE_ACCELERATE */
     190#endif
    182191  return tmp;
    183192}
     
    186195fvec_max (fvec_t * s)
    187196{
    188 #ifndef HAVE_ACCELERATE
    189   uint_t j;
    190   smpl_t tmp = 0.0;
    191   for (j = 0; j < s->length; j++) {
     197#if defined(HAVE_INTEL_IPP)
     198  smpl_t tmp = 0.;
     199  aubio_ippsMax( s->data, (int)s->length, &tmp);
     200#elif defined(HAVE_ACCELERATE)
     201  smpl_t tmp = 0.;
     202  aubio_vDSP_maxv( s->data, 1, &tmp, s->length );
     203#else
     204  uint_t j;
     205  smpl_t tmp = s->data[0];
     206  for (j = 1; j < s->length; j++) {
    192207    tmp = (tmp > s->data[j]) ? tmp : s->data[j];
    193208  }
    194 #else
     209#endif
     210  return tmp;
     211}
     212
     213smpl_t
     214fvec_min (fvec_t * s)
     215{
     216#if defined(HAVE_INTEL_IPP)
    195217  smpl_t tmp = 0.;
    196   aubio_vDSP_maxv(s->data, 1, &tmp, s->length);
    197 #endif
    198   return tmp;
    199 }
    200 
    201 smpl_t
    202 fvec_min (fvec_t * s)
    203 {
    204 #ifndef HAVE_ACCELERATE
    205   uint_t j;
    206   smpl_t tmp = s->data[0];
    207   for (j = 0; j < s->length; j++) {
    208     tmp = (tmp < s->data[j]) ? tmp : s->data[j];
    209   }
    210 #else
     218  aubio_ippsMin(s->data, (int)s->length, &tmp);
     219#elif defined(HAVE_ACCELERATE)
    211220  smpl_t tmp = 0.;
    212221  aubio_vDSP_minv(s->data, 1, &tmp, s->length);
     222#else
     223  uint_t j;
     224  smpl_t tmp = s->data[0];
     225  for (j = 1; j < s->length; j++) {
     226    tmp = (tmp < s->data[j]) ? tmp : s->data[j];
     227  }
    213228#endif
    214229  return tmp;
     
    227242#else
    228243  smpl_t tmp = 0.;
    229   uint_t pos = 0.;
    230   aubio_vDSP_minvi(s->data, 1, &tmp, (vDSP_Length *)&pos, s->length);
    231 #endif
    232   return pos;
     244  vDSP_Length pos = 0;
     245  aubio_vDSP_minvi(s->data, 1, &tmp, &pos, s->length);
     246#endif
     247  return (uint_t)pos;
    233248}
    234249
     
    245260#else
    246261  smpl_t tmp = 0.;
    247   uint_t pos = 0.;
    248   aubio_vDSP_maxvi(s->data, 1, &tmp, (vDSP_Length *)&pos, s->length);
    249 #endif
    250   return pos;
     262  vDSP_Length pos = 0;
     263  aubio_vDSP_maxvi(s->data, 1, &tmp, &pos, s->length);
     264#endif
     265  return (uint_t)pos;
    251266}
    252267
     
    257272  // if length is odd, middle element is moved to the end
    258273  if (2 * half < s->length) start ++;
    259 #ifndef HAVE_ATLAS
     274#ifndef HAVE_BLAS
    260275  for (j = 0; j < half; j++) {
    261276    ELEM_SWAP (s->data[j], s->data[j + start]);
     
    277292  // if length is odd, middle element is moved to the beginning
    278293  if (2 * half < s->length) start ++;
    279 #ifndef HAVE_ATLAS
     294#ifndef HAVE_BLAS
    280295  for (j = 0; j < half; j++) {
    281296    ELEM_SWAP (s->data[j], s->data[j + start]);
     
    291306}
    292307
     308void fvec_push(fvec_t *in, smpl_t new_elem) {
     309  uint_t i;
     310  for (i = 0; i < in->length - 1; i++) {
     311    in->data[i] = in->data[i + 1];
     312  }
     313  in->data[in->length - 1] = new_elem;
     314}
     315
     316void fvec_clamp(fvec_t *in, smpl_t absmax) {
     317  uint_t i;
     318  for (i = 0; i < in->length; i++) {
     319    if (in->data[i] > 0 && in->data[i] > ABS(absmax)) {
     320      in->data[i] = absmax;
     321    } else if (in->data[i] < 0 && in->data[i] < -ABS(absmax)) {
     322      in->data[i] = -absmax;
     323    }
     324  }
     325}
     326
    293327smpl_t
    294328aubio_level_lin (const fvec_t * f)
    295329{
    296330  smpl_t energy = 0.;
    297 #ifndef HAVE_ATLAS
     331#ifndef HAVE_BLAS
    298332  uint_t j;
    299333  for (j = 0; j < f->length; j++) {
     
    351385  for (j = 0; j < o->length; j++) {
    352386    o->data[j] += val;
     387  }
     388}
     389
     390void
     391fvec_mul (fvec_t *o, smpl_t val)
     392{
     393  uint_t j;
     394  for (j = 0; j < o->length; j++) {
     395    o->data[j] *= val;
    353396  }
    354397}
     
    489532  /* log(freq/A-2)/log(2) */
    490533  midi = freq / 6.875;
    491   midi = LOG (midi) / 0.69314718055995;
     534  midi = LOG (midi) / 0.6931471805599453;
    492535  midi *= 12;
    493536  midi -= 3;
     
    501544  if (midi > 140.) return 0.; // avoid infs
    502545  freq = (midi + 3.) / 12.;
    503   freq = EXP (freq * 0.69314718055995);
     546  freq = EXP (freq * 0.6931471805599453);
    504547  freq *= 6.875;
    505548  return freq;
     
    550593  while (i < a) i <<= 1;
    551594  return i;
     595}
     596
     597uint_t
     598aubio_power_of_two_order (uint_t a)
     599{
     600  int order = 0;
     601  int temp = aubio_next_power_of_two(a);
     602  while (temp >>= 1) {
     603    ++order;
     604  }
     605  return order;
    552606}
    553607
Note: See TracChangeset for help on using the changeset viewer.