diff options
Diffstat (limited to 'audio/filter/af_scaletempo.c')
-rw-r--r-- | audio/filter/af_scaletempo.c | 54 |
1 files changed, 18 insertions, 36 deletions
diff --git a/audio/filter/af_scaletempo.c b/audio/filter/af_scaletempo.c index fdcfd5560f..c8560af502 100644 --- a/audio/filter/af_scaletempo.c +++ b/audio/filter/af_scaletempo.c @@ -47,11 +47,11 @@ typedef struct af_scaletempo_s // stride float scale; float speed; + int frames_stride; float frames_stride_scaled; float frames_stride_error; int bytes_per_frame; int bytes_stride; - float bytes_stride_scaled; int bytes_queue; int bytes_queued; int bytes_to_slide; @@ -84,7 +84,7 @@ typedef struct af_scaletempo_s static int fill_queue(struct af_instance *af, struct mp_audio *data, int offset) { af_scaletempo_t *s = af->priv; - int bytes_in = data->len - offset; + int bytes_in = mp_audio_psize(data) - offset; int offset_unchanged = offset; if (s->bytes_to_slide > 0) { @@ -108,7 +108,7 @@ static int fill_queue(struct af_instance *af, struct mp_audio *data, int offset) int bytes_copy = MPMIN(s->bytes_queue - s->bytes_queued, bytes_in); assert(bytes_copy >= 0); memcpy(s->buf_queue + s->bytes_queued, - (int8_t *)data->audio + offset, bytes_copy); + (int8_t *)data->planes[0] + offset, bytes_copy); s->bytes_queued += bytes_copy; offset += bytes_copy; } @@ -220,24 +220,11 @@ static struct mp_audio *play(struct af_instance *af, struct mp_audio *data) return data; } - // RESIZE_LOCAL_BUFFER - can't use macro - int max_bytes_out = ((int)(data->len / s->bytes_stride_scaled) + 1) - * s->bytes_stride; - if (max_bytes_out > af->data->len) { - mp_msg(MSGT_AFILTER, MSGL_V, "[libaf] Reallocating memory in module %s, " - "old len = %i, new len = %i\n", af->info->name, - af->data->len, max_bytes_out); - af->data->audio = realloc(af->data->audio, max_bytes_out); - if (!af->data->audio) { - mp_msg(MSGT_AFILTER, MSGL_FATAL, - "[libaf] Could not allocate memory\n"); - return NULL; - } - af->data->len = max_bytes_out; - } + mp_audio_realloc_min(af->data, + ((int)(data->samples / s->frames_stride_scaled) + 1) * s->frames_stride); int offset_in = fill_queue(af, data, 0); - int8_t *pout = af->data->audio; + int8_t *pout = af->data->planes[0]; while (s->bytes_queued >= s->bytes_queue) { int ti; float tf; @@ -269,10 +256,11 @@ static struct mp_audio *play(struct af_instance *af, struct mp_audio *data) // This filter can have a negative delay when scale > 1: // output corresponding to some length of input can be decided and written // after receiving only a part of that input. - af->delay = s->bytes_queued - s->bytes_to_slide; + af->delay = (s->bytes_queued - s->bytes_to_slide) / s->scale + / af->data->sstride / af->data->rate; - data->audio = af->data->audio; - data->len = pout - (int8_t *)af->data->audio; + data->planes[0] = af->data->planes[0]; + data->samples = (pout - (int8_t *)af->data->planes[0]) / af->data->sstride; return data; } @@ -291,6 +279,7 @@ static int control(struct af_instance *af, int cmd, void *arg) "[scaletempo] %.3f speed * %.3f scale_nominal = %.3f\n", s->speed, s->scale_nominal, s->scale); + mp_audio_force_interleaved_format(data); mp_audio_copy_config(af->data, data); if (s->scale == 1.0) { @@ -308,15 +297,14 @@ static int control(struct af_instance *af, int cmd, void *arg) } int bps = af->data->bps; - int frames_stride = srate * s->ms_stride; - s->bytes_stride = frames_stride * bps * nch; - s->bytes_stride_scaled = s->scale * s->bytes_stride; - s->frames_stride_scaled = s->scale * frames_stride; + s->frames_stride = srate * s->ms_stride; + s->bytes_stride = s->frames_stride * bps * nch; + s->frames_stride_scaled = s->scale * s->frames_stride; s->frames_stride_error = 0; - af->mul = (double)s->bytes_stride / s->bytes_stride_scaled; + af->mul = 1.0 / s->scale; af->delay = 0; - int frames_overlap = frames_stride * s->percent_overlap; + int frames_overlap = s->frames_stride * s->percent_overlap; if (frames_overlap <= 0) { s->bytes_standing = s->bytes_stride; s->samples_standing = s->bytes_standing / bps; @@ -401,8 +389,8 @@ static int control(struct af_instance *af, int cmd, void *arg) s->bytes_per_frame = bps * nch; s->num_channels = nch; - s->bytes_queue - = (s->frames_search + frames_stride + frames_overlap) * bps * nch; + s->bytes_queue = (s->frames_search + s->frames_stride + frames_overlap) + * bps * nch; s->buf_queue = realloc(s->buf_queue, s->bytes_queue + UNROLL_PADDING); if (!s->buf_queue) { mp_msg(MSGT_AFILTER, MSGL_FATAL, "[scaletempo] Out of memory\n"); @@ -456,8 +444,6 @@ static int control(struct af_instance *af, int cmd, void *arg) static void uninit(struct af_instance *af) { af_scaletempo_t *s = af->priv; - free(af->data->audio); - free(af->data); free(s->buf_queue); free(s->buf_overlap); free(s->buf_pre_corr); @@ -476,10 +462,6 @@ static int af_open(struct af_instance *af) af->control = control; af->uninit = uninit; af->play = play; - af->mul = 1; - af->data = calloc(1, sizeof(struct mp_audio)); - if (af->data == NULL) - return AF_ERROR; s->speed_tempo = !!(s->speed_opt & SCALE_TEMPO); s->speed_pitch = !!(s->speed_opt & SCALE_PITCH); |