• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/ap/gpl/minidlna/ffmpeg-2.3.4/libavfilter/

Lines Matching defs:atempo

161 AVFILTER_DEFINE_CLASS(atempo);
163 inline static AudioFragment *yae_curr_frag(ATempoContext *atempo)
165 return &atempo->frag[atempo->nfrag % 2];
168 inline static AudioFragment *yae_prev_frag(ATempoContext *atempo)
170 return &atempo->frag[(atempo->nfrag + 1) % 2];
176 static void yae_clear(ATempoContext *atempo)
178 atempo->size = 0;
179 atempo->head = 0;
180 atempo->tail = 0;
182 atempo->nfrag = 0;
183 atempo->state = YAE_LOAD_FRAGMENT;
185 atempo->position[0] = 0;
186 atempo->position[1] = 0;
188 atempo->origin[0] = 0;
189 atempo->origin[1] = 0;
191 atempo->frag[0].position[0] = 0;
192 atempo->frag[0].position[1] = 0;
193 atempo->frag[0].nsamples = 0;
195 atempo->frag[1].position[0] = 0;
196 atempo->frag[1].position[1] = 0;
197 atempo->frag[1].nsamples = 0;
202 atempo->frag[0].position[0] = -(int64_t)(atempo->window / 2);
203 atempo->frag[0].position[1] = -(int64_t)(atempo->window / 2);
205 av_frame_free(&atempo->dst_buffer);
206 atempo->dst = NULL;
207 atempo->dst_end = NULL;
209 atempo->nsamples_in = 0;
210 atempo->nsamples_out = 0;
216 static void yae_release_buffers(ATempoContext *atempo)
218 yae_clear(atempo);
220 av_freep(&atempo->frag[0].data);
221 av_freep(&atempo->frag[1].data);
222 av_freep(&atempo->frag[0].xdat);
223 av_freep(&atempo->frag[1].xdat);
225 av_freep(&atempo->buffer);
226 av_freep(&atempo->hann);
227 av_freep(&atempo->correlation);
229 av_rdft_end(atempo->real_to_complex);
230 atempo->real_to_complex = NULL;
232 av_rdft_end(atempo->complex_to_real);
233 atempo->complex_to_real = NULL;
243 yae_release_buffers(atempo); \
252 static int yae_reset(ATempoContext *atempo,
262 atempo->format = format;
263 atempo->channels = channels;
264 atempo->stride = sample_size * channels;
267 atempo->window = sample_rate / 24;
270 nlevels = av_log2(atempo->window);
272 av_assert0(pot <= atempo->window);
274 if (pot < atempo->window) {
275 atempo->window = pot * 2;
280 RE_MALLOC_OR_FAIL(atempo->frag[0].data, atempo->window * atempo->stride);
281 RE_MALLOC_OR_FAIL(atempo->frag[1].data, atempo->window * atempo->stride);
282 RE_MALLOC_OR_FAIL(atempo->frag[0].xdat, atempo->window * sizeof(FFTComplex));
283 RE_MALLOC_OR_FAIL(atempo->frag[1].xdat, atempo->window * sizeof(FFTComplex));
286 av_rdft_end(atempo->real_to_complex);
287 atempo->real_to_complex = NULL;
289 av_rdft_end(atempo->complex_to_real);
290 atempo->complex_to_real = NULL;
292 atempo->real_to_complex = av_rdft_init(nlevels + 1, DFT_R2C);
293 if (!atempo->real_to_complex) {
294 yae_release_buffers(atempo);
298 atempo->complex_to_real = av_rdft_init(nlevels + 1, IDFT_C2R);
299 if (!atempo->complex_to_real) {
300 yae_release_buffers(atempo);
304 RE_MALLOC_OR_FAIL(atempo->correlation, atempo->window * sizeof(FFTComplex));
306 atempo->ring = atempo->window * 3;
307 RE_MALLOC_OR_FAIL(atempo->buffer, atempo->ring * atempo->stride);
310 RE_MALLOC_OR_FAIL(atempo->hann, atempo->window * sizeof(float));
312 for (i = 0; i < atempo->window; i++) {
313 double t = (double)i / (double)(atempo->window - 1);
315 atempo->hann[i] = (float)h;
318 yae_clear(atempo);
325 ATempoContext *atempo = ctx->priv;
340 prev = yae_prev_frag(atempo);
341 atempo->origin[0] = prev->position[0] + atempo->window / 2;
342 atempo->origin[1] = prev->position[1] + atempo->window / 2;
343 atempo->tempo = tempo;
354 frag->nsamples * atempo->channels * sizeof(scalar_type); \
359 if (atempo->channels == 1) { \
378 for (i = 1; i < atempo->channels; i++) { \
401 static void yae_downmix(ATempoContext *atempo, AudioFragment *frag)
407 memset(frag->xdat, 0, sizeof(FFTComplex) * atempo->window);
409 if (atempo->format == AV_SAMPLE_FMT_U8) {
411 } else if (atempo->format == AV_SAMPLE_FMT_S16) {
413 } else if (atempo->format == AV_SAMPLE_FMT_S32) {
415 } else if (atempo->format == AV_SAMPLE_FMT_FLT) {
417 } else if (atempo->format == AV_SAMPLE_FMT_DBL) {
429 static int yae_load_data(ATempoContext *atempo,
436 const int read_size = stop_here - atempo->position[0];
438 if (stop_here <= atempo->position[0]) {
443 av_assert0(read_size <= atempo->ring);
445 while (atempo->position[0] < stop_here && src < src_end) {
446 int src_samples = (src_end - src) / atempo->stride;
453 nsamples = FFMIN(nsamples, atempo->ring);
454 na = FFMIN(nsamples, atempo->ring - atempo->tail);
455 nb = FFMIN(nsamples - na, atempo->ring);
458 uint8_t *a = atempo->buffer + atempo->tail * atempo->stride;
459 memcpy(a, src, na * atempo->stride);
461 src += na * atempo->stride;
462 atempo->position[0] += na;
464 atempo->size = FFMIN(atempo->size + na, atempo->ring);
465 atempo->tail = (atempo->tail + na) % atempo->ring;
466 atempo->head =
467 atempo->size < atempo->ring ?
468 atempo->tail - atempo->size :
469 atempo->tail;
473 uint8_t *b = atempo->buffer;
474 memcpy(b, src, nb * atempo->stride);
476 src += nb * atempo->stride;
477 atempo->position[0] += nb;
479 atempo->size = FFMIN(atempo->size + nb, atempo->ring);
480 atempo->tail = (atempo->tail + nb) % atempo->ring;
481 atempo->head =
482 atempo->size < atempo->ring ?
483 atempo->tail - atempo->size :
484 atempo->tail;
492 av_assert0(atempo->position[0] <= stop_here);
494 return atempo->position[0] == stop_here ? 0 : AVERROR(EAGAIN);
504 static int yae_load_frag(ATempoContext *atempo,
509 AudioFragment *frag = yae_curr_frag(atempo);
516 int64_t stop_here = frag->position[0] + atempo->window;
517 if (src_ref && yae_load_data(atempo, src_ref, src_end, stop_here) != 0) {
523 stop_here > atempo->position[0] ?
524 stop_here - atempo->position[0] : 0;
527 missing < (int64_t)atempo->window ?
528 (uint32_t)(atempo->window - missing) : 0;
534 start = atempo->position[0] - atempo->size;
542 memset(dst, 0, zeros * atempo->stride);
543 dst += zeros * atempo->stride;
551 na = (atempo->head < atempo->tail ?
552 atempo->tail - atempo->head :
553 atempo->ring - atempo->head);
555 nb = atempo->head < atempo->tail ? 0 : atempo->tail;
560 a = atempo->buffer + atempo->head * atempo->stride;
561 b = atempo->buffer;
570 memcpy(dst, a + i0 * atempo->stride, n0 * atempo->stride);
571 dst += n0 * atempo->stride;
575 memcpy(dst, b + i1 * atempo->stride, n1 * atempo->stride);
584 static void yae_advance_to_next_frag(ATempoContext *atempo)
586 const double fragment_step = atempo->tempo * (double)(atempo->window / 2);
591 atempo->nfrag++;
592 prev = yae_prev_frag(atempo);
593 frag = yae_curr_frag(atempo);
596 frag->position[1] = prev->position[1] + atempo->window / 2;
694 static int yae_adjust_position(ATempoContext *atempo)
696 const AudioFragment *prev = yae_prev_frag(atempo);
697 AudioFragment *frag = yae_curr_frag(atempo);
700 (double)(prev->position[1] - atempo->origin[1] + atempo->window / 2);
703 (double)(prev->position[0] - atempo->origin[0] + atempo->window / 2) /
704 atempo->tempo;
708 const int delta_max = atempo->window / 2;
711 atempo->window,
714 atempo->correlation,
715 atempo->complex_to_real);
742 i++, atempo->position[1]++, wa++, wb++) { \
747 for (j = 0; j < atempo->channels; \
769 static int yae_overlap_add(ATempoContext *atempo,
774 const AudioFragment *prev = yae_prev_frag(atempo);
775 const AudioFragment *frag = yae_curr_frag(atempo);
777 const int64_t start_here = FFMAX(atempo->position[1],
788 const float *wa = atempo->hann + ia;
789 const float *wb = atempo->hann + ib;
791 const uint8_t *a = prev->data + ia * atempo->stride;
792 const uint8_t *b = frag->data + ib * atempo->stride;
800 if (atempo->format == AV_SAMPLE_FMT_U8) {
802 } else if (atempo->format == AV_SAMPLE_FMT_S16) {
804 } else if (atempo->format == AV_SAMPLE_FMT_S32) {
806 } else if (atempo->format == AV_SAMPLE_FMT_FLT) {
808 } else if (atempo->format == AV_SAMPLE_FMT_DBL) {
815 return atempo->position[1] == stop_here ? 0 : AVERROR(EAGAIN);
824 yae_apply(ATempoContext *atempo,
831 if (atempo->state == YAE_LOAD_FRAGMENT) {
833 if (yae_load_frag(atempo, src_ref, src_end) != 0) {
838 yae_downmix(atempo, yae_curr_frag(atempo));
841 av_rdft_calc(atempo->real_to_complex, yae_curr_frag(atempo)->xdat);
844 if (!atempo->nfrag) {
845 yae_advance_to_next_frag(atempo);
849 atempo->state = YAE_ADJUST_POSITION;
852 if (atempo->state == YAE_ADJUST_POSITION) {
854 if (yae_adjust_position(atempo)) {
857 atempo->state = YAE_RELOAD_FRAGMENT;
859 atempo->state = YAE_OUTPUT_OVERLAP_ADD;
863 if (atempo->state == YAE_RELOAD_FRAGMENT) {
865 if (yae_load_frag(atempo, src_ref, src_end) != 0) {
870 yae_downmix(atempo, yae_curr_frag(atempo));
873 av_rdft_calc(atempo->real_to_complex, yae_curr_frag(atempo)->xdat);
875 atempo->state = YAE_OUTPUT_OVERLAP_ADD;
878 if (atempo->state == YAE_OUTPUT_OVERLAP_ADD) {
880 if (yae_overlap_add(atempo, dst_ref, dst_end) != 0) {
885 yae_advance_to_next_frag(atempo);
886 atempo->state = YAE_LOAD_FRAGMENT;
898 static int yae_flush(ATempoContext *atempo,
902 AudioFragment *frag = yae_curr_frag(atempo);
915 atempo->state = YAE_FLUSH_OUTPUT;
917 if (atempo->position[0] == frag->position[0] + frag->nsamples &&
918 atempo->position[1] == frag->position[1] + frag->nsamples) {
923 if (frag->position[0] + frag->nsamples < atempo->position[0]) {
925 yae_load_frag(atempo, NULL, NULL);
927 if (atempo->nfrag) {
929 yae_downmix(atempo, frag);
932 av_rdft_calc(atempo->real_to_complex, frag->xdat);
935 if (yae_adjust_position(atempo)) {
937 yae_load_frag(atempo, NULL, NULL);
943 overlap_end = frag->position[1] + FFMIN(atempo->window / 2,
946 while (atempo->position[1] < overlap_end) {
947 if (yae_overlap_add(atempo, dst_ref, dst_end) != 0) {
953 start_here = FFMAX(atempo->position[1], overlap_end);
958 src = frag->data + offset * atempo->stride;
961 src_size = (int)(stop_here - start_here) * atempo->stride;
968 atempo->position[1] += (nbytes / atempo->stride);
973 return atempo->position[1] == stop_here ? 0 : AVERROR(EAGAIN);
978 ATempoContext *atempo = ctx->priv;
979 atempo->format = AV_SAMPLE_FMT_NONE;
980 atempo->state = YAE_LOAD_FRAGMENT;
986 ATempoContext *atempo = ctx->priv;
987 yae_release_buffers(atempo);
1034 ATempoContext *atempo = ctx->priv;
1042 return yae_reset(atempo, format, sample_rate, channels);
1045 static int push_samples(ATempoContext *atempo,
1051 atempo->dst_buffer->sample_rate = outlink->sample_rate;
1052 atempo->dst_buffer->nb_samples = n_out;
1055 atempo->dst_buffer->pts =
1056 av_rescale_q(atempo->nsamples_out,
1060 ret = ff_filter_frame(outlink, atempo->dst_buffer);
1061 atempo->dst_buffer = NULL;
1062 atempo->dst = NULL;
1063 atempo->dst_end = NULL;
1067 atempo->nsamples_out += n_out;
1074 ATempoContext *atempo = ctx->priv;
1079 int n_out = (int)(0.5 + ((double)n_in) / atempo->tempo);
1082 const uint8_t *src_end = src + n_in * atempo->stride;
1085 if (!atempo->dst_buffer) {
1086 atempo->dst_buffer = ff_get_audio_buffer(outlink, n_out);
1087 if (!atempo->dst_buffer)
1089 av_frame_copy_props(atempo->dst_buffer, src_buffer);
1091 atempo->dst = atempo->dst_buffer->data[0];
1092 atempo->dst_end = atempo->dst + n_out * atempo->stride;
1095 yae_apply(atempo, &src, src_end, &atempo->dst, atempo->dst_end);
1097 if (atempo->dst == atempo->dst_end) {
1098 int n_samples = ((atempo->dst - atempo->dst_buffer->data[0]) /
1099 atempo->stride);
1100 ret = push_samples(atempo, outlink, n_samples);
1106 atempo->nsamples_in += n_in;
1115 ATempoContext *atempo = ctx->priv;
1122 int n_max = atempo->ring;
1127 if (!atempo->dst_buffer) {
1128 atempo->dst_buffer = ff_get_audio_buffer(outlink, n_max);
1129 if (!atempo->dst_buffer)
1132 atempo->dst = atempo->dst_buffer->data[0];
1133 atempo->dst_end = atempo->dst + n_max * atempo->stride;
1136 err = yae_flush(atempo, &atempo->dst, atempo->dst_end);
1138 n_out = ((atempo->dst - atempo->dst_buffer->data[0]) /
1139 atempo->stride);
1142 ret = push_samples(atempo, outlink, n_out);
1146 av_frame_free(&atempo->dst_buffer);
1147 atempo->dst = NULL;
1148 atempo->dst_end = NULL;
1186 .name = "atempo",