Changeset b2f41be


Ignore:
Timestamp:
Dec 7, 2018, 6:03:19 PM (5 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/cnn, feature/crepe, feature/timestretch, fix/ffmpeg5, master
Children:
ff87a67
Parents:
97a5ac08
Message:

[effects] clean up aubio_split_str, fix issues in aubio_get_rubberband_opts

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/effects/rubberband_utils.c

    r97a5ac08 rb2f41be  
    2020#include <assert.h>
    2121
    22 char** aubio_split_str(char_t* input, const char_t sep) {
     22char_t** aubio_split_str(const char_t* str, const char_t sep) {
    2323  char_t** result = 0;
    2424  uint_t count = 0;
     25  char_t input[PATH_MAX];
    2526  char_t* in_ptr = input;
    2627  char_t* last_sep = 0;
    2728  char_t delim[2]; delim[0] = sep; delim[1] = 0;
     29
     30  strncpy(input, str, PATH_MAX);
     31  input[PATH_MAX - 1] = '\0';
    2832
    2933  // count number of elements
     
    3741  // add space for trailing token.
    3842  count += last_sep < (input + strlen(input) - 1);
    39   // add one more for terminating null string
    4043  count++;
    4144
    42   result = malloc(sizeof(char*) * count);
     45  result = AUBIO_ARRAY(char_t*, count);
    4346  if (result) {
    44     size_t idx  = 0;
    45     char* params = strtok(input, delim);
     47    uint_t idx  = 0;
     48    char_t* params = strtok(input, delim);
    4649    while (params) {
    4750      // make sure we don't got in the wild
     
    8790  } else {
    8891    // 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;
     92    char_t **params = aubio_split_str(mode, ':');
     93    uint_t i = 0;
     94    if (!params || !params[0]) {
     95      // memory failure occurred or empty string was passed
     96      AUBIO_ERR("rubberband_utils: failed parsing options\n");
     97      rboptions = -1;
    9498    }
    95     for (i = 0; *(params + i); i++) {
     99    while (*(params + i) != NULL) {
    96100      if ( strcmp(params[i], "ProcessOffline" ) == 0 )        {
    97101             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)
     102        // TODO: add wrapper to rb study(smpl_t *input, uint_t write)
     103        AUBIO_ERR("rubberband_utils: RubberBandOptionProcessOffline is not available\n");
     104        rboptions = -1;
    100105      }
    101106      else if ( strcmp(params[i], "ProcessRealTime" ) == 0 )       rboptions |= RubberBandOptionProcessRealTime;
     
    133138          "PitchHighSpeed|PitchHighQuality|PitchHighConsistency, ChannelsApart|ChannelsTogether\n"
    134139          , params[i]);
    135         return -1;
     140        rboptions = -1;
    136141      }
    137       free(params[i]);
     142      AUBIO_FREE(params[i]);
     143      i++;
    138144    }
    139     free(params);
    140     free(modecopy);
     145    AUBIO_FREE(params);
    141146  }
    142147  return rboptions;
Note: See TracChangeset for help on using the changeset viewer.