source: src/effects/rubberband_utils.c @ 9b0ffe3

feature/timestretch
Last change on this file since 9b0ffe3 was 9b0ffe3, checked in by Paul Brossier <piem@piem.org>, 12 months ago

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

  • Property mode set to 100644
File size: 6.6 KB
Line 
1
2
3#include "aubio_priv.h"
4
5#ifdef HAVE_RUBBERBAND
6
7#include "rubberband/rubberband-c.h"
8
9// check rubberband is 1.8.1, warn if 1.3
10#if !((RUBBERBAND_API_MAJOR_VERSION >= 2) && \
11    (RUBBERBAND_API_MINOR_VERSION >= 5))
12#warning RubberBandOptionDetectorSoft not available, \
13 please upgrade rubberband to version 1.8.1 or higher
14#define RubberBandOptionDetectorSoft 0x00000000
15#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}
58
59RubberBandOptions aubio_get_rubberband_opts(const char_t *mode)
60{
61  RubberBandOptions rboptions = RubberBandOptionProcessRealTime;
62
63  if ( strcmp(mode,"crispness:0") == 0 ) {
64    rboptions |= RubberBandOptionTransientsSmooth;
65    rboptions |= RubberBandOptionWindowLong;
66    rboptions |= RubberBandOptionPhaseIndependent;
67  } else if ( strcmp(mode, "crispness:1") == 0 ) {
68    rboptions |= RubberBandOptionDetectorSoft;
69    rboptions |= RubberBandOptionTransientsSmooth;
70    rboptions |= RubberBandOptionWindowLong;
71    rboptions |= RubberBandOptionPhaseIndependent;
72  } else if ( strcmp(mode, "crispness:2") == 0 ) {
73    rboptions |= RubberBandOptionTransientsSmooth;
74    rboptions |= RubberBandOptionPhaseIndependent;
75  } else if ( strcmp(mode, "crispness:3") == 0 ) {
76    rboptions |= RubberBandOptionTransientsSmooth;
77  } else if ( strcmp(mode, "crispness:4") == 0 ) {
78    // same as "default"
79  } else if ( strcmp(mode, "crispness:5") == 0 ) {
80    rboptions |= RubberBandOptionTransientsCrisp;
81  } else if ( strcmp(mode, "crispness:6") == 0 ) {
82    rboptions |= RubberBandOptionTransientsCrisp;
83    rboptions |= RubberBandOptionWindowShort;
84    rboptions |= RubberBandOptionPhaseIndependent;
85  } else if ( strcmp(mode, "default") == 0 ) {
86    // nothing to do
87  } else {
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);
140  }
141  return rboptions;
142}
143
144#endif
Note: See TracBrowser for help on using the repository browser.