| 1 |
/* |
| 2 |
rubberband-dll |
| 3 |
|
| 4 |
A consumer of the rubberband static library that simply exposes |
| 5 |
its functionality as a DLL. |
| 6 |
|
| 7 |
Copyright 2018-2019 Jonathan Gilbert |
| 8 |
|
| 9 |
Permission is hereby granted, free of charge, to any person |
| 10 |
obtaining a copy of this software and associated documentation |
| 11 |
files (the "Software"), to deal in the Software without |
| 12 |
restriction, including without limitation the rights to use, copy, |
| 13 |
modify, merge, publish, distribute, sublicense, and/or sell copies |
| 14 |
of the Software, and to permit persons to whom the Software is |
| 15 |
furnished to do so, subject to the following conditions: |
| 16 |
|
| 17 |
The above copyright notice and this permission notice shall be |
| 18 |
included in all copies or substantial portions of the Software. |
| 19 |
|
| 20 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 21 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 22 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 23 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR |
| 24 |
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 25 |
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 26 |
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 27 |
|
| 28 |
Except as contained in this notice, the name of Jonathan Gilbert |
| 29 |
shall not be used in advertising or otherwise to promote the sale, |
| 30 |
use or other dealings in this Software without prior written |
| 31 |
authorization. |
| 32 |
*/ |
| 33 |
|
| 34 |
// rubberband-dll.cpp : Defines the exported functions for the DLL application. |
| 35 |
// |
| 36 |
|
| 37 |
#include "stdafx.h" |
| 38 |
|
| 39 |
using namespace RubberBand; |
| 40 |
|
| 41 |
#define EXPORT extern "C" __declspec(dllexport) |
| 42 |
|
| 43 |
#if _WIN64 |
| 44 |
#define CONVENTION __stdcall |
| 45 |
#else |
| 46 |
#define CONVENTION __cdecl |
| 47 |
#endif |
| 48 |
|
| 49 |
#define O(rbs) reinterpret_cast<RubberBandStretcher *>(rbs) |
| 50 |
|
| 51 |
EXPORT HANDLE CONVENTION RubberBandStretcher_Create( |
| 52 |
size_t sampleRate, |
| 53 |
size_t channels, |
| 54 |
int options = RubberBandStretcher::DefaultOptions, |
| 55 |
double initialTimeRatio = 1.0, |
| 56 |
double initialPitchScale = 1.0) |
| 57 |
{ |
| 58 |
return (HANDLE)new RubberBandStretcher(sampleRate, channels, options, initialTimeRatio, initialPitchScale); |
| 59 |
} |
| 60 |
|
| 61 |
EXPORT void CONVENTION RubberBandStretcher_Delete(HANDLE *rbs) |
| 62 |
{ |
| 63 |
delete O(rbs); |
| 64 |
} |
| 65 |
|
| 66 |
EXPORT void CONVENTION RubberBandStretcher_Reset(HANDLE *rbs) |
| 67 |
{ |
| 68 |
O(rbs)->reset(); |
| 69 |
} |
| 70 |
|
| 71 |
EXPORT void CONVENTION RubberBandStretcher_SetTimeRatio(HANDLE *rbs, double ratio) |
| 72 |
{ |
| 73 |
O(rbs)->setTimeRatio(ratio); |
| 74 |
} |
| 75 |
|
| 76 |
EXPORT void CONVENTION RubberBandStretcher_SetPitchScale(HANDLE *rbs, double scale) |
| 77 |
{ |
| 78 |
O(rbs)->setPitchScale(scale); |
| 79 |
} |
| 80 |
|
| 81 |
EXPORT double CONVENTION RubberBandStretcher_GetTimeRatio(HANDLE *rbs) |
| 82 |
{ |
| 83 |
return O(rbs)->getTimeRatio(); |
| 84 |
} |
| 85 |
|
| 86 |
EXPORT double CONVENTION RubberBandStretcher_GetPitchScale(HANDLE *rbs) |
| 87 |
{ |
| 88 |
return O(rbs)->getPitchScale(); |
| 89 |
} |
| 90 |
|
| 91 |
EXPORT size_t CONVENTION RubberBandStretcher_GetLatency(HANDLE *rbs) |
| 92 |
{ |
| 93 |
return O(rbs)->getLatency(); |
| 94 |
} |
| 95 |
|
| 96 |
EXPORT void CONVENTION RubberBandStretcher_SetTransientsOption(HANDLE *rbs, int options) |
| 97 |
{ |
| 98 |
O(rbs)->setTransientsOption(options); |
| 99 |
} |
| 100 |
|
| 101 |
EXPORT void CONVENTION RubberBandStretcher_SetDetectorOption(HANDLE *rbs, int options) |
| 102 |
{ |
| 103 |
O(rbs)->setDetectorOption(options); |
| 104 |
} |
| 105 |
|
| 106 |
EXPORT void CONVENTION RubberBandStretcher_SetPhaseOption(HANDLE *rbs, int options) |
| 107 |
{ |
| 108 |
O(rbs)->setPhaseOption(options); |
| 109 |
} |
| 110 |
|
| 111 |
EXPORT void CONVENTION RubberBandStretcher_SetFormantOption(HANDLE *rbs, int options) |
| 112 |
{ |
| 113 |
O(rbs)->setFormantOption(options); |
| 114 |
} |
| 115 |
|
| 116 |
EXPORT void CONVENTION RubberBandStretcher_SetPitchOption(HANDLE *rbs, int options) |
| 117 |
{ |
| 118 |
O(rbs)->setPitchOption(options); |
| 119 |
} |
| 120 |
|
| 121 |
EXPORT void CONVENTION RubberBandStretcher_SetExpectedInputDuration(HANDLE *rbs, size_t samples) |
| 122 |
{ |
| 123 |
O(rbs)->setExpectedInputDuration(samples); |
| 124 |
} |
| 125 |
|
| 126 |
EXPORT void CONVENTION RubberBandStretcher_SetMaxProcessSize(HANDLE *rbs, size_t samples) |
| 127 |
{ |
| 128 |
O(rbs)->setMaxProcessSize(samples); |
| 129 |
} |
| 130 |
|
| 131 |
EXPORT size_t CONVENTION RubberBandStretcher_GetSamplesRequired(HANDLE *rbs) |
| 132 |
{ |
| 133 |
return O(rbs)->getSamplesRequired(); |
| 134 |
} |
| 135 |
|
| 136 |
EXPORT void CONVENTION RubberBandStretcher_SetKeyFrameMap(HANDLE *rbs, size_t *mappingData, int numberOfMappings) |
| 137 |
{ |
| 138 |
std::map<size_t, size_t> map; |
| 139 |
|
| 140 |
for (int i = 0; i < numberOfMappings; i++) |
| 141 |
map[mappingData[i + i]] = mappingData[i + i + 1]; |
| 142 |
|
| 143 |
O(rbs)->setKeyFrameMap(map); |
| 144 |
} |
| 145 |
|
| 146 |
EXPORT void CONVENTION RubberBandStretcher_Study(HANDLE *rbs, float *input_flat, size_t samples, int channels, bool final) |
| 147 |
{ |
| 148 |
std::vector<float *> input; |
| 149 |
|
| 150 |
for (int i = 0; i < channels; i++) |
| 151 |
input.push_back(&input_flat[samples * i]); |
| 152 |
|
| 153 |
O(rbs)->study(&input[0], samples, final); |
| 154 |
} |
| 155 |
|
| 156 |
EXPORT void CONVENTION RubberBandStretcher_Process(HANDLE *rbs, float *input_flat, size_t samples, int channels, bool final) |
| 157 |
{ |
| 158 |
std::vector<float *> input; |
| 159 |
|
| 160 |
for (int i = 0; i < channels; i++) |
| 161 |
input.push_back(&input_flat[samples * i]); |
| 162 |
|
| 163 |
O(rbs)->process(&input[0], samples, final); |
| 164 |
} |
| 165 |
|
| 166 |
EXPORT int CONVENTION RubberBandStretcher_Available(HANDLE *rbs) |
| 167 |
{ |
| 168 |
return O(rbs)->available(); |
| 169 |
} |
| 170 |
|
| 171 |
EXPORT size_t CONVENTION RubberBandStretcher_Retrieve(HANDLE *rbs, float *output_flat, size_t samples, int channels) |
| 172 |
{ |
| 173 |
std::vector<float *> output; |
| 174 |
|
| 175 |
for (int i = 0; i < channels; i++) |
| 176 |
output.push_back(&output_flat[samples * i]); |
| 177 |
|
| 178 |
return O(rbs)->retrieve(&output[0], samples); |
| 179 |
} |
| 180 |
|
| 181 |
EXPORT float CONVENTION RubberBandStretcher_GetFrequencyCutoff(HANDLE *rbs, int n) |
| 182 |
{ |
| 183 |
return O(rbs)->getFrequencyCutoff(n); |
| 184 |
} |
| 185 |
|
| 186 |
EXPORT void CONVENTION RubberBandStretcher_SetFrequencyCutoff(HANDLE *rbs, int n, float f) |
| 187 |
{ |
| 188 |
O(rbs)->setFrequencyCutoff(n, f); |
| 189 |
} |
| 190 |
|
| 191 |
EXPORT size_t CONVENTION RubberBandStretcher_GetInputIncrement(HANDLE *rbs) |
| 192 |
{ |
| 193 |
return O(rbs)->getInputIncrement(); |
| 194 |
} |
| 195 |
|
| 196 |
EXPORT size_t CONVENTION RubberBandStretcher_GetOutputIncrements(HANDLE *rbs, int *buffer, size_t bufferSize) |
| 197 |
{ |
| 198 |
std::vector<int> increments = O(rbs)->getOutputIncrements(); |
| 199 |
|
| 200 |
for (size_t i = 0; (i < bufferSize) && (i < increments.size()); i++) |
| 201 |
buffer[i] = increments[i]; |
| 202 |
|
| 203 |
return increments.size(); |
| 204 |
} |
| 205 |
|
| 206 |
EXPORT size_t CONVENTION RubberBandStretcher_GetPhaseResetCurve(HANDLE *rbs, float *buffer, size_t bufferSize) |
| 207 |
{ |
| 208 |
std::vector<float> curve = O(rbs)->getPhaseResetCurve(); |
| 209 |
|
| 210 |
for (size_t i = 0; (i < bufferSize) && (i < curve.size()); i++) |
| 211 |
buffer[i] = curve[i]; |
| 212 |
|
| 213 |
return curve.size(); |
| 214 |
} |
| 215 |
|
| 216 |
EXPORT size_t CONVENTION RubberBandStretcher_GetExactTimePoints(HANDLE *rbs, int *buffer, size_t bufferSize) |
| 217 |
{ |
| 218 |
std::vector<int> timePoints = O(rbs)->getExactTimePoints(); |
| 219 |
|
| 220 |
for (size_t i = 0; (i < bufferSize) && (i < timePoints.size()); i++) |
| 221 |
buffer[i] = timePoints[i]; |
| 222 |
|
| 223 |
return timePoints.size(); |
| 224 |
} |
| 225 |
|
| 226 |
EXPORT size_t CONVENTION RubberBandStretcher_GetChannelCount(HANDLE *rbs) |
| 227 |
{ |
| 228 |
return O(rbs)->getChannelCount(); |
| 229 |
} |
| 230 |
|
| 231 |
EXPORT void CONVENTION RubberBandStretcher_CalculateStretch(HANDLE *rbs) |
| 232 |
{ |
| 233 |
O(rbs)->calculateStretch(); |
| 234 |
} |
| 235 |
|
| 236 |
EXPORT void CONVENTION RubberBandStretcher_SetDebugLevel(HANDLE *rbs, int level) |
| 237 |
{ |
| 238 |
O(rbs)->setDebugLevel(level); |
| 239 |
} |
| 240 |
|
| 241 |
EXPORT void CONVENTION RubberBandStretcher_SetDefaultDebugLevel(int level) |
| 242 |
{ |
| 243 |
RubberBandStretcher::setDefaultDebugLevel(level); |
| 244 |
} |