19 #include <rubberband/rubberband-c.h>
45 #define OFFSET(x) offsetof(RubberBandContext, x)
46 #define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
47 #define AT AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
52 {
"transients",
"set transients",
OFFSET(transients),
AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX,
A, .unit =
"transients" },
53 {
"crisp", 0, 0,
AV_OPT_TYPE_CONST, {.i64=RubberBandOptionTransientsCrisp}, 0, 0,
A, .unit =
"transients" },
54 {
"mixed", 0, 0,
AV_OPT_TYPE_CONST, {.i64=RubberBandOptionTransientsMixed}, 0, 0,
A, .unit =
"transients" },
55 {
"smooth", 0, 0,
AV_OPT_TYPE_CONST, {.i64=RubberBandOptionTransientsSmooth}, 0, 0,
A, .unit =
"transients" },
56 {
"detector",
"set detector",
OFFSET(detector),
AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX,
A, .unit =
"detector" },
57 {
"compound", 0, 0,
AV_OPT_TYPE_CONST, {.i64=RubberBandOptionDetectorCompound}, 0, 0,
A, .unit =
"detector" },
58 {
"percussive", 0, 0,
AV_OPT_TYPE_CONST, {.i64=RubberBandOptionDetectorPercussive}, 0, 0,
A, .unit =
"detector" },
59 {
"soft", 0, 0,
AV_OPT_TYPE_CONST, {.i64=RubberBandOptionDetectorSoft}, 0, 0,
A, .unit =
"detector" },
61 {
"laminar", 0, 0,
AV_OPT_TYPE_CONST, {.i64=RubberBandOptionPhaseLaminar}, 0, 0,
A, .unit =
"phase" },
62 {
"independent", 0, 0,
AV_OPT_TYPE_CONST, {.i64=RubberBandOptionPhaseIndependent}, 0, 0,
A, .unit =
"phase" },
64 {
"standard", 0, 0,
AV_OPT_TYPE_CONST, {.i64=RubberBandOptionWindowStandard}, 0, 0,
A, .unit =
"window" },
65 {
"short", 0, 0,
AV_OPT_TYPE_CONST, {.i64=RubberBandOptionWindowShort}, 0, 0,
A, .unit =
"window" },
66 {
"long", 0, 0,
AV_OPT_TYPE_CONST, {.i64=RubberBandOptionWindowLong}, 0, 0,
A, .unit =
"window" },
67 {
"smoothing",
"set smoothing",
OFFSET(smoothing),
AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX,
A, .unit =
"smoothing" },
68 {
"off", 0, 0,
AV_OPT_TYPE_CONST, {.i64=RubberBandOptionSmoothingOff}, 0, 0,
A, .unit =
"smoothing" },
69 {
"on", 0, 0,
AV_OPT_TYPE_CONST, {.i64=RubberBandOptionSmoothingOn}, 0, 0,
A, .unit =
"smoothing" },
70 {
"formant",
"set formant",
OFFSET(formant),
AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX,
A, .unit =
"formant" },
71 {
"shifted", 0, 0,
AV_OPT_TYPE_CONST, {.i64=RubberBandOptionFormantShifted}, 0, 0,
A, .unit =
"formant" },
72 {
"preserved", 0, 0,
AV_OPT_TYPE_CONST, {.i64=RubberBandOptionFormantPreserved}, 0, 0,
A, .unit =
"formant" },
73 {
"pitchq",
"set pitch quality",
OFFSET(opitch),
AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX,
A, .unit =
"pitch" },
74 {
"quality", 0, 0,
AV_OPT_TYPE_CONST, {.i64=RubberBandOptionPitchHighQuality}, 0, 0,
A, .unit =
"pitch" },
75 {
"speed", 0, 0,
AV_OPT_TYPE_CONST, {.i64=RubberBandOptionPitchHighSpeed}, 0, 0,
A, .unit =
"pitch" },
76 {
"consistency", 0, 0,
AV_OPT_TYPE_CONST, {.i64=RubberBandOptionPitchHighConsistency}, 0, 0,
A, .unit =
"pitch" },
78 {
"apart", 0, 0,
AV_OPT_TYPE_CONST, {.i64=RubberBandOptionChannelsApart}, 0, 0,
A, .unit =
"channels" },
79 {
"together", 0, 0,
AV_OPT_TYPE_CONST, {.i64=RubberBandOptionChannelsTogether}, 0, 0,
A, .unit =
"channels" },
90 rubberband_delete(
s->rbs);
99 int ret = 0, nb_samples;
102 s->first_pts = in->
pts;
107 nb_samples = rubberband_available(
s->rbs);
108 if (nb_samples > 0) {
117 s->last_pts =
out->pts;
118 nb_samples = rubberband_retrieve(
s->rbs, (
float *
const *)
out->extended_data, nb_samples);
119 out->nb_samples = nb_samples;
121 s->nb_samples_out += nb_samples;
127 return ret < 0 ?
ret : nb_samples;
134 int opts =
s->transients|
s->detector|
s->phase|
s->window|
135 s->smoothing|
s->formant|
s->opitch|
s->channels|
136 RubberBandOptionProcessRealTime;
139 rubberband_delete(
s->rbs);
140 s->rbs = rubberband_new(
inlink->sample_rate,
inlink->ch_layout.nb_channels,
opts, 1. /
s->tempo,
s->pitch);
144 s->nb_samples = rubberband_get_samples_required(
s->rbs);
185 char *res,
int res_len,
int flags)
194 rubberband_set_time_ratio(
s->rbs, 1. /
s->tempo);
195 rubberband_set_pitch_scale(
s->rbs,
s->pitch);
196 s->nb_samples = rubberband_get_samples_required(
s->rbs);
210 .
name =
"rubberband",
213 .priv_class = &rubberband_class,