summaryrefslogtreecommitdiffstats
path: root/libaf
diff options
context:
space:
mode:
authoruau <uau@b3059339-0415-0410-9bf9-f77b7e298cf2>2007-11-01 06:52:50 +0000
committeruau <uau@b3059339-0415-0410-9bf9-f77b7e298cf2>2007-11-01 06:52:50 +0000
commitd7f6cb23dec483f538239eb42e21c321713c976e (patch)
treea5a87950b4cdae8d0b4e9a6df202000fd4825615 /libaf
parentde034ce87fdf632b48563e5764f19d66120550a8 (diff)
downloadmpv-d7f6cb23dec483f538239eb42e21c321713c976e.tar.bz2
mpv-d7f6cb23dec483f538239eb42e21c321713c976e.tar.xz
A/V sync: take audio filter buffers into account
Substract the delay caused by filter buffering when calculating currently playing audio position. This matters for af_scaletempo which buffers significant and varying amounts of data. For other current filters the effect is normally insignificant. Instead of the old time-based filter delay field (which was ignored) this version stores the per-filter delay in units of bytes input read without corresponding output. This allows the current scaletempo behavior where other filters before and after it can see the same nominal samplerate even though the real duration of the data varies; in this case the other filters can not know the delay they're causing in terms of real time. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@24928 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libaf')
-rw-r--r--libaf/af.c3
-rw-r--r--libaf/af.h5
-rw-r--r--libaf/af_equalizer.c2
-rw-r--r--libaf/af_lavcresample.c2
-rw-r--r--libaf/af_resample.c2
-rw-r--r--libaf/af_scaletempo.c5
6 files changed, 13 insertions, 6 deletions
diff --git a/libaf/af.c b/libaf/af.c
index 32c59dbbcd..c229f9eee6 100644
--- a/libaf/af.c
+++ b/libaf/af.c
@@ -542,7 +542,7 @@ double af_calc_filter_multiplier(af_stream_t* s)
return mul;
}
-/* Calculate the total delay [ms] caused by the filters */
+/* Calculate the total delay [bytes output] caused by the filters */
double af_calc_delay(af_stream_t* s)
{
af_instance_t* af=s->first;
@@ -550,6 +550,7 @@ double af_calc_delay(af_stream_t* s)
// Iterate through all filters
while(af){
delay += af->delay;
+ delay *= af->mul;
af=af->next;
}
return delay;
diff --git a/libaf/af.h b/libaf/af.h
index 4c983cb6e4..a4dc6f9535 100644
--- a/libaf/af.h
+++ b/libaf/af.h
@@ -54,7 +54,8 @@ typedef struct af_instance_s
af_data_t* data; // configuration for outgoing data stream
struct af_instance_s* next;
struct af_instance_s* prev;
- double delay; // Delay caused by the filter [ms]
+ double delay; /* Delay caused by the filter, in units of bytes read without
+ * corresponding output */
double mul; /* length multiplier: how much does this instance change
the length of the buffer. */
}af_instance_t;
@@ -196,7 +197,7 @@ double af_calc_filter_multiplier(af_stream_t* s);
/**
* \brief Calculate the total delay caused by the filters
- * \return delay in seconds
+ * \return delay in bytes of "missing" output
*/
double af_calc_delay(af_stream_t* s);
diff --git a/libaf/af_equalizer.c b/libaf/af_equalizer.c
index 9eb09a8188..5a92090d32 100644
--- a/libaf/af_equalizer.c
+++ b/libaf/af_equalizer.c
@@ -106,7 +106,7 @@ static int control(struct af_instance_s* af, int cmd, void* arg)
bp2(s->a[k],s->b[k],F[k]/((float)af->data->rate),Q);
// Calculate how much this plugin adds to the overall time delay
- af->delay += 2000.0/((float)af->data->rate);
+ af->delay = 2 * af->data->nch * af->data->bps;
// Calculate gain factor to prevent clipping at output
for(k=0;k<AF_NCH;k++)
diff --git a/libaf/af_lavcresample.c b/libaf/af_lavcresample.c
index f44f26cabf..026646499d 100644
--- a/libaf/af_lavcresample.c
+++ b/libaf/af_lavcresample.c
@@ -48,7 +48,7 @@ static int control(struct af_instance_s* af, int cmd, void* arg)
af->data->format = AF_FORMAT_S16_NE;
af->data->bps = 2;
af->mul = (double)af->data->rate / data->rate;
- af->delay = 500*s->filter_length/(double)min(af->data->rate, data->rate);
+ af->delay = af->data->nch * s->filter_length / min(af->mul, 1); // *bps*.5
if(s->avrctx) av_resample_close(s->avrctx);
s->avrctx= av_resample_init(af->data->rate, /*in_rate*/data->rate, s->filter_length, s->phase_shift, s->linear, s->cutoff);
diff --git a/libaf/af_resample.c b/libaf/af_resample.c
index e1bed4976b..57e2d39321 100644
--- a/libaf/af_resample.c
+++ b/libaf/af_resample.c
@@ -254,7 +254,7 @@ static int control(struct af_instance_s* af, int cmd, void* arg)
}
// Set multiplier and delay
- af->delay = (double)(1000*L/2)/((double)n->rate);
+ af->delay = 0; // not set correctly, but shouldn't be too large anyway
af->mul = (double)s->up / s->dn;
return rv;
}
diff --git a/libaf/af_scaletempo.c b/libaf/af_scaletempo.c
index 4cdde2d5c0..3ed14aec68 100644
--- a/libaf/af_scaletempo.c
+++ b/libaf/af_scaletempo.c
@@ -261,6 +261,11 @@ static af_data_t* play(struct af_instance_s* af, af_data_t* data)
offset_in += fill_queue(af, data, offset_in);
}
+ // 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;
+
data->audio = af->data->audio;
data->len = pout - (int8_t *)af->data->audio;
return data;