summaryrefslogtreecommitdiffstats
path: root/audio/filter/af_scaletempo.c
diff options
context:
space:
mode:
Diffstat (limited to 'audio/filter/af_scaletempo.c')
-rw-r--r--audio/filter/af_scaletempo.c52
1 files changed, 27 insertions, 25 deletions
diff --git a/audio/filter/af_scaletempo.c b/audio/filter/af_scaletempo.c
index ed1df5725e..e7b101b260 100644
--- a/audio/filter/af_scaletempo.c
+++ b/audio/filter/af_scaletempo.c
@@ -30,6 +30,7 @@
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <float.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
@@ -47,7 +48,7 @@ struct f_opts {
float scale_nominal;
float ms_stride;
float ms_search;
- float percent_overlap;
+ float factor_overlap;
#define SCALE_TEMPO 1
#define SCALE_PITCH 2
int speed_opt;
@@ -186,10 +187,10 @@ static int best_overlap_offset_s16(struct priv *s)
ps += s->samples_overlap - s->num_channels;
long i = -(s->samples_overlap - s->num_channels);
do {
- corr += ppc[i + 0] * ps[i + 0];
- corr += ppc[i + 1] * ps[i + 1];
- corr += ppc[i + 2] * ps[i + 2];
- corr += ppc[i + 3] * ps[i + 3];
+ corr += ppc[i + 0] * (int64_t)ps[i + 0];
+ corr += ppc[i + 1] * (int64_t)ps[i + 1];
+ corr += ppc[i + 2] * (int64_t)ps[i + 2];
+ corr += ppc[i + 3] * (int64_t)ps[i + 3];
i += 4;
} while (i < 0);
if (corr > best_corr) {
@@ -228,7 +229,7 @@ static void output_overlap_s16(struct priv *s, void *buf_out,
}
}
-static void process(struct mp_filter *f)
+static void af_scaletempo_process(struct mp_filter *f)
{
struct priv *s = f->priv;
@@ -399,7 +400,7 @@ static bool reinit(struct mp_filter *f)
update_speed(s, s->speed);
- int frames_overlap = s->frames_stride * s->opts->percent_overlap;
+ int frames_overlap = s->frames_stride * s->opts->factor_overlap;
if (frames_overlap <= 0) {
s->bytes_standing = s->bytes_stride;
s->samples_standing = s->bytes_standing / bps;
@@ -510,7 +511,7 @@ static bool reinit(struct mp_filter *f)
return true;
}
-static bool command(struct mp_filter *f, struct mp_filter_command *cmd)
+static bool af_scaletempo_command(struct mp_filter *f, struct mp_filter_command *cmd)
{
struct priv *s = f->priv;
@@ -529,7 +530,7 @@ static bool command(struct mp_filter *f, struct mp_filter_command *cmd)
return false;
}
-static void reset(struct mp_filter *f)
+static void af_scaletempo_reset(struct mp_filter *f)
{
struct priv *s = f->priv;
@@ -537,11 +538,12 @@ static void reset(struct mp_filter *f)
s->bytes_queued = 0;
s->bytes_to_slide = 0;
s->frames_stride_error = 0;
- memset(s->buf_overlap, 0, s->bytes_overlap);
+ if (s->buf_overlap && s->bytes_overlap)
+ memset(s->buf_overlap, 0, s->bytes_overlap);
TA_FREEP(&s->in);
}
-static void destroy(struct mp_filter *f)
+static void af_scaletempo_destroy(struct mp_filter *f)
{
struct priv *s = f->priv;
free(s->buf_queue);
@@ -556,10 +558,10 @@ static void destroy(struct mp_filter *f)
static const struct mp_filter_info af_scaletempo_filter = {
.name = "scaletempo",
.priv_size = sizeof(struct priv),
- .process = process,
- .command = command,
- .reset = reset,
- .destroy = destroy,
+ .process = af_scaletempo_process,
+ .command = af_scaletempo_command,
+ .reset = af_scaletempo_reset,
+ .destroy = af_scaletempo_destroy,
};
static struct mp_filter *af_scaletempo_create(struct mp_filter *parent,
@@ -602,21 +604,21 @@ const struct mp_user_filter_entry af_scaletempo = {
.priv_size = sizeof(OPT_BASE_STRUCT),
.priv_defaults = &(const OPT_BASE_STRUCT) {
.ms_stride = 60,
- .percent_overlap = .20,
+ .factor_overlap = .20,
.ms_search = 14,
.speed_opt = SCALE_TEMPO,
.scale_nominal = 1.0,
},
.options = (const struct m_option[]) {
- OPT_FLOAT("scale", scale_nominal, M_OPT_MIN, .min = 0.01),
- OPT_FLOAT("stride", ms_stride, M_OPT_MIN, .min = 0.01),
- OPT_FLOAT("overlap", percent_overlap, M_OPT_RANGE, .min = 0, .max = 1),
- OPT_FLOAT("search", ms_search, M_OPT_MIN, .min = 0),
- OPT_CHOICE("speed", speed_opt, 0,
- ({"pitch", SCALE_PITCH},
- {"tempo", SCALE_TEMPO},
- {"none", 0},
- {"both", SCALE_TEMPO | SCALE_PITCH})),
+ {"scale", OPT_FLOAT(scale_nominal), M_RANGE(0.01, DBL_MAX)},
+ {"stride", OPT_FLOAT(ms_stride), M_RANGE(0.01, DBL_MAX)},
+ {"overlap", OPT_FLOAT(factor_overlap), M_RANGE(0, 1)},
+ {"search", OPT_FLOAT(ms_search), M_RANGE(0, DBL_MAX)},
+ {"speed", OPT_CHOICE(speed_opt,
+ {"pitch", SCALE_PITCH},
+ {"tempo", SCALE_TEMPO},
+ {"none", 0},
+ {"both", SCALE_TEMPO | SCALE_PITCH})},
{0}
},
},