Changeset 9b0ffe3 for src/effects


Ignore:
Timestamp:
Dec 7, 2018, 1:28:56 AM (6 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/cnn, feature/crepe, feature/timestretch, fix/ffmpeg5, master
Children:
60ae447
Parents:
e7d4aa0
git-author:
Paul Brossier <piem@piem.org> (03/12/17 14:19:46)
git-committer:
Paul Brossier <piem@piem.org> (12/07/18 01:28:56)
Message:

src/effects/rubberband_utils.c: add parsing of all rubberband options

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/effects/rubberband_utils.c

    re7d4aa0 r9b0ffe3  
    1414#define RubberBandOptionDetectorSoft 0x00000000
    1515#endif
     16
     17#include <stdio.h>
     18#include <stdlib.h>
     19#include <string.h>
     20#include <assert.h>
     21
     22char** aubio_split_str(char_t* input, const char_t sep) {
     23  char_t** result = 0;
     24  uint_t count = 0;
     25  char_t* in_ptr = input;
     26  char_t* last_sep = 0;
     27  char_t delim[2]; delim[0] = sep; delim[1] = 0;
     28
     29  // count number of elements
     30  while (*in_ptr) {
     31    if (sep == *in_ptr) {
     32      count++;
     33      last_sep = in_ptr;
     34    }
     35    in_ptr++;
     36  }
     37  // add space for trailing token.
     38  count += last_sep < (input + strlen(input) - 1);
     39  // add one more for terminating null string
     40  count++;
     41
     42  result = malloc(sizeof(char*) * count);
     43  if (result) {
     44    size_t idx  = 0;
     45    char* params = strtok(input, delim);
     46    while (params) {
     47      // make sure we don't got in the wild
     48      assert(idx < count);
     49      *(result + idx++) = strdup(params);
     50      params = strtok(0, delim);
     51    }
     52    assert(idx == count - 1);
     53    // add null string at the end
     54    *(result + idx) = 0;
     55  }
     56  return result;
     57}
    1658
    1759RubberBandOptions aubio_get_rubberband_opts(const char_t *mode)
     
    4486    // nothing to do
    4587  } else {
    46     // failed parsing option string
    47     return -1;
     88    // attempt to parse a list of options, separated with ','
     89    char *modecopy = strndup(mode, PATH_MAX);
     90    char **params = aubio_split_str(modecopy, ',');
     91    uint_t i;
     92    if (!params) {
     93      return -1;
     94    }
     95    for (i = 0; *(params + i); i++) {
     96      if ( strcmp(params[i], "ProcessOffline" ) == 0 )        {
     97             rboptions = RubberBandOptionProcessOffline;
     98        AUBIO_WRN("rubberband_utils: RubberBandOptionProcessOffline is not available in aubio yet\n");
     99        // TODO: add wrapper to function study(smpl_t *input, uint_t write)
     100      }
     101      else if ( strcmp(params[i], "ProcessRealTime" ) == 0 )       rboptions |= RubberBandOptionProcessRealTime;
     102      else if ( strcmp(params[i], "StretchElastic" ) == 0 )        rboptions |= RubberBandOptionStretchElastic;
     103      else if ( strcmp(params[i], "StretchPrecise" ) == 0 )        rboptions |= RubberBandOptionStretchPrecise;
     104      else if ( strcmp(params[i], "TransientsCrisp" ) == 0 )       rboptions |= RubberBandOptionTransientsCrisp;
     105      else if ( strcmp(params[i], "TransientsMixed" ) == 0 )       rboptions |= RubberBandOptionTransientsMixed;
     106      else if ( strcmp(params[i], "TransientsSmooth" ) == 0 )      rboptions |= RubberBandOptionTransientsSmooth;
     107      else if ( strcmp(params[i], "DetectorCompound" ) == 0 )      rboptions |= RubberBandOptionDetectorCompound;
     108      else if ( strcmp(params[i], "DetectorPercussive" ) == 0 )    rboptions |= RubberBandOptionDetectorPercussive;
     109      else if ( strcmp(params[i], "DetectorSoft" ) == 0 )          rboptions |= RubberBandOptionDetectorSoft;
     110      else if ( strcmp(params[i], "PhaseLaminar" ) == 0 )          rboptions |= RubberBandOptionPhaseLaminar;
     111      else if ( strcmp(params[i], "PhaseIndependent" ) == 0 )      rboptions |= RubberBandOptionPhaseIndependent;
     112      else if ( strcmp(params[i], "ThreadingAuto" ) == 0 )         rboptions |= RubberBandOptionThreadingAuto;
     113      else if ( strcmp(params[i], "ThreadingNever" ) == 0 )        rboptions |= RubberBandOptionThreadingNever;
     114      else if ( strcmp(params[i], "ThreadingAlways" ) == 0 )       rboptions |= RubberBandOptionThreadingAlways;
     115      else if ( strcmp(params[i], "WindowStandard" ) == 0 )        rboptions |= RubberBandOptionWindowStandard;
     116      else if ( strcmp(params[i], "WindowShort" ) == 0 )           rboptions |= RubberBandOptionWindowShort;
     117      else if ( strcmp(params[i], "WindowLong" ) == 0 )            rboptions |= RubberBandOptionWindowLong;
     118      else if ( strcmp(params[i], "SmoothingOff" ) == 0 )          rboptions |= RubberBandOptionSmoothingOff;
     119      else if ( strcmp(params[i], "SmoothingOn" ) == 0 )           rboptions |= RubberBandOptionSmoothingOn;
     120      else if ( strcmp(params[i], "FormantShifted" ) == 0 )        rboptions |= RubberBandOptionFormantShifted;
     121      else if ( strcmp(params[i], "FormantPreserved" ) == 0 )      rboptions |= RubberBandOptionFormantPreserved;
     122      else if ( strcmp(params[i], "PitchHighSpeed" ) == 0 )        rboptions |= RubberBandOptionPitchHighSpeed;
     123      else if ( strcmp(params[i], "PitchHighQuality" ) == 0 )      rboptions |= RubberBandOptionPitchHighQuality;
     124      else if ( strcmp(params[i], "PitchHighConsistency" ) == 0 )  rboptions |= RubberBandOptionPitchHighConsistency;
     125      else if ( strcmp(params[i], "ChannelsApart" ) == 0 )         rboptions |= RubberBandOptionChannelsApart;
     126      else if ( strcmp(params[i], "ChannelsTogether" ) == 0 )      rboptions |= RubberBandOptionChannelsTogether;
     127      else {
     128        AUBIO_WRN("rubberband_utils: did not understand option '%s', should be one of: "
     129          "StretchElastic|StretchPrecise, TransientsCrisp|TransientsMixed|TransientsSmooth, "
     130          "DetectorCompound|DetectorPercussive|DetectorSoft, PhaseLaminar|PhaseIndependent, "
     131          "ThreadingAuto|ThreadingNever|ThreadingAlways, WindowStandard|WindowLong|WindowShort, "
     132          "SmoothingOn|SmoothingOff, FormantShifted|FormantPreserved, "
     133          "PitchHighSpeed|PitchHighQuality|PitchHighConsistency, ChannelsApart|ChannelsTogether\n"
     134          , params[i]);
     135      }
     136      free(params[i]);
     137    }
     138    free(params);
     139    free(modecopy);
    48140  }
    49   // other options to include
    50   //p->rboptions |= RubberBandOptionWindowStandard;
    51   //p->rboptions |= RubberBandOptionSmoothingOff;
    52   //p->rboptions |= RubberBandOptionFormantShifted;
    53   //p->rboptions |= RubberBandOptionPitchHighConsistency;
    54141  return rboptions;
    55142}
Note: See TracChangeset for help on using the changeset viewer.