source: src/effects/rubberband_utils.c @ 75d1f9b

sampler
Last change on this file since 75d1f9b was bde49c4a, checked in by Paul Brossier <piem@piem.org>, 8 years ago

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

  • Property mode set to 100644
File size: 6.7 KB
Line 
1
2
3#include "config.h"
4#include "aubio_priv.h"
5
6#ifdef HAVE_RUBBERBAND
7
8#include "rubberband/rubberband-c.h"
9
10// check rubberband is 1.8.1, warn if 1.3
11#if !((RUBBERBAND_API_MAJOR_VERSION >= 2) && \
12    (RUBBERBAND_API_MINOR_VERSION >= 5))
13#warning RubberBandOptionDetectorSoft not available, \
14 please upgrade rubberband to version 1.8.1 or higher
15#define RubberBandOptionDetectorSoft 0x00000000
16#endif
17
18#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
21#include <assert.h>
22
23char** aubio_split_str(char_t* input, const char_t sep) {
24  char_t** result = 0;
25  uint_t count = 0;
26  char_t* in_ptr = input;
27  char_t* last_sep = 0;
28  char_t delim[2]; delim[0] = sep; delim[1] = 0;
29
30  // count number of elements
31  while (*in_ptr) {
32    if (sep == *in_ptr) {
33      count++;
34      last_sep = in_ptr;
35    }
36    in_ptr++;
37  }
38  // add space for trailing token.
39  count += last_sep < (input + strlen(input) - 1);
40  // add one more for terminating null string
41  count++;
42
43  result = malloc(sizeof(char*) * count);
44  if (result) {
45    size_t idx  = 0;
46    char* params = strtok(input, delim);
47    while (params) {
48      // make sure we don't got in the wild
49      assert(idx < count);
50      *(result + idx++) = strdup(params);
51      params = strtok(0, delim);
52    }
53    assert(idx == count - 1);
54    // add null string at the end
55    *(result + idx) = 0;
56  }
57  return result;
58}
59
60RubberBandOptions aubio_get_rubberband_opts(const char_t *mode)
61{
62  RubberBandOptions rboptions = RubberBandOptionProcessRealTime;
63
64  if ( strcmp(mode,"crispness:0") == 0 ) {
65    rboptions |= RubberBandOptionTransientsSmooth;
66    rboptions |= RubberBandOptionWindowLong;
67    rboptions |= RubberBandOptionPhaseIndependent;
68  } else if ( strcmp(mode, "crispness:1") == 0 ) {
69    rboptions |= RubberBandOptionDetectorSoft;
70    rboptions |= RubberBandOptionTransientsSmooth;
71    rboptions |= RubberBandOptionWindowLong;
72    rboptions |= RubberBandOptionPhaseIndependent;
73  } else if ( strcmp(mode, "crispness:2") == 0 ) {
74    rboptions |= RubberBandOptionTransientsSmooth;
75    rboptions |= RubberBandOptionPhaseIndependent;
76  } else if ( strcmp(mode, "crispness:3") == 0 ) {
77    rboptions |= RubberBandOptionTransientsSmooth;
78  } else if ( strcmp(mode, "crispness:4") == 0 ) {
79    // same as "default"
80  } else if ( strcmp(mode, "crispness:5") == 0 ) {
81    rboptions |= RubberBandOptionTransientsCrisp;
82  } else if ( strcmp(mode, "crispness:6") == 0 ) {
83    rboptions |= RubberBandOptionTransientsCrisp;
84    rboptions |= RubberBandOptionWindowShort;
85    rboptions |= RubberBandOptionPhaseIndependent;
86  } else if ( strcmp(mode, "default") == 0 ) {
87    // nothing to do
88  } else {
89    // attempt to parse a list of options, separated with ','
90    char *modecopy = strndup(mode, PATH_MAX);
91    char **params = aubio_split_str(modecopy, ',');
92    uint_t i;
93    if (!params) {
94      return -1;
95    }
96    for (i = 0; *(params + i); i++) {
97      if ( strcmp(params[i], "ProcessOffline" ) == 0 )        {
98             rboptions = RubberBandOptionProcessOffline;
99        AUBIO_WRN("rubberband_utils: RubberBandOptionProcessOffline is not available in aubio yet\n");
100        // TODO: add wrapper to function study(smpl_t *input, uint_t write)
101      }
102      else if ( strcmp(params[i], "ProcessRealTime" ) == 0 )       rboptions |= RubberBandOptionProcessRealTime;
103      else if ( strcmp(params[i], "StretchElastic" ) == 0 )        rboptions |= RubberBandOptionStretchElastic;
104      else if ( strcmp(params[i], "StretchPrecise" ) == 0 )        rboptions |= RubberBandOptionStretchPrecise;
105      else if ( strcmp(params[i], "TransientsCrisp" ) == 0 )       rboptions |= RubberBandOptionTransientsCrisp;
106      else if ( strcmp(params[i], "TransientsMixed" ) == 0 )       rboptions |= RubberBandOptionTransientsMixed;
107      else if ( strcmp(params[i], "TransientsSmooth" ) == 0 )      rboptions |= RubberBandOptionTransientsSmooth;
108      else if ( strcmp(params[i], "DetectorCompound" ) == 0 )      rboptions |= RubberBandOptionDetectorCompound;
109      else if ( strcmp(params[i], "DetectorPercussive" ) == 0 )    rboptions |= RubberBandOptionDetectorPercussive;
110      else if ( strcmp(params[i], "DetectorSoft" ) == 0 )          rboptions |= RubberBandOptionDetectorSoft;
111      else if ( strcmp(params[i], "PhaseLaminar" ) == 0 )          rboptions |= RubberBandOptionPhaseLaminar;
112      else if ( strcmp(params[i], "PhaseIndependent" ) == 0 )      rboptions |= RubberBandOptionPhaseIndependent;
113      else if ( strcmp(params[i], "ThreadingAuto" ) == 0 )         rboptions |= RubberBandOptionThreadingAuto;
114      else if ( strcmp(params[i], "ThreadingNever" ) == 0 )        rboptions |= RubberBandOptionThreadingNever;
115      else if ( strcmp(params[i], "ThreadingAlways" ) == 0 )       rboptions |= RubberBandOptionThreadingAlways;
116      else if ( strcmp(params[i], "WindowStandard" ) == 0 )        rboptions |= RubberBandOptionWindowStandard;
117      else if ( strcmp(params[i], "WindowShort" ) == 0 )           rboptions |= RubberBandOptionWindowShort;
118      else if ( strcmp(params[i], "WindowLong" ) == 0 )            rboptions |= RubberBandOptionWindowLong;
119      else if ( strcmp(params[i], "SmoothingOff" ) == 0 )          rboptions |= RubberBandOptionSmoothingOff;
120      else if ( strcmp(params[i], "SmoothingOn" ) == 0 )           rboptions |= RubberBandOptionSmoothingOn;
121      else if ( strcmp(params[i], "FormantShifted" ) == 0 )        rboptions |= RubberBandOptionFormantShifted;
122      else if ( strcmp(params[i], "FormantPreserved" ) == 0 )      rboptions |= RubberBandOptionFormantPreserved;
123      else if ( strcmp(params[i], "PitchHighSpeed" ) == 0 )        rboptions |= RubberBandOptionPitchHighSpeed;
124      else if ( strcmp(params[i], "PitchHighQuality" ) == 0 )      rboptions |= RubberBandOptionPitchHighQuality;
125      else if ( strcmp(params[i], "PitchHighConsistency" ) == 0 )  rboptions |= RubberBandOptionPitchHighConsistency;
126      else if ( strcmp(params[i], "ChannelsApart" ) == 0 )         rboptions |= RubberBandOptionChannelsApart;
127      else if ( strcmp(params[i], "ChannelsTogether" ) == 0 )      rboptions |= RubberBandOptionChannelsTogether;
128      else {
129        AUBIO_WRN("rubberband_utils: did not understand option '%s', should be one of: "
130          "StretchElastic|StretchPrecise, TransientsCrisp|TransientsMixed|TransientsSmooth, "
131          "DetectorCompound|DetectorPercussive|DetectorSoft, PhaseLaminar|PhaseIndependent, "
132          "ThreadingAuto|ThreadingNever|ThreadingAlways, WindowStandard|WindowLong|WindowShort, "
133          "SmoothingOn|SmoothingOff, FormantShifted|FormantPreserved, "
134          "PitchHighSpeed|PitchHighQuality|PitchHighConsistency, ChannelsApart|ChannelsTogether\n"
135          , params[i]);
136      }
137      free(params[i]);
138    }
139    free(params);
140    free(modecopy);
141  }
142  return rboptions;
143}
144
145#endif
Note: See TracBrowser for help on using the repository browser.