mirror of
https://github.com/mpv-player/mpv
synced 2025-01-01 04:36:24 +01:00
Adding function for calculating the delay caused by the filters
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@7666 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
f767a62a42
commit
3e3a4733fb
13
libaf/af.c
13
libaf/af.c
@ -487,6 +487,19 @@ int af_calc_insize_constrained(af_stream_t* s, int len,
|
||||
return in;
|
||||
}
|
||||
|
||||
/* Calculate the total delay [ms] caused by the filters */
|
||||
double af_calc_delay(af_stream_t* s)
|
||||
{
|
||||
af_instance_t* af=s->first;
|
||||
register double delay = 0.0;
|
||||
// Iterate through all filters
|
||||
while(af){
|
||||
delay += af->delay;
|
||||
af=af->next;
|
||||
}
|
||||
return delay;
|
||||
}
|
||||
|
||||
/* Helper function called by the macro with the same name this
|
||||
function should not be called directly */
|
||||
inline int af_resize_local_buffer(af_instance_t* af, af_data_t* data)
|
||||
|
@ -48,6 +48,7 @@ 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]
|
||||
frac_t mul; /* length multiplier: how much does this instance change
|
||||
the length of the buffer. */
|
||||
}af_instance_t;
|
||||
@ -180,6 +181,8 @@ int af_inputlen(af_stream_t* s, int len);
|
||||
int af_calc_insize_constrained(af_stream_t* s, int len,
|
||||
int max_outsize,int max_insize);
|
||||
|
||||
/* Calculate the total delay caused by the filters */
|
||||
double af_calc_delay(af_stream_t* s);
|
||||
|
||||
// Helper functions and macros used inside the audio filters
|
||||
|
||||
|
@ -41,11 +41,13 @@ static int control(struct af_instance_s* af, int cmd, void* arg)
|
||||
mp_msg(MSGT_AFILTER,MSGL_ERR,"Error setting delay length in af_delay. Delay must be between 0s and 30s\n");
|
||||
s->len=0;
|
||||
s->tlen=0.0;
|
||||
af->delay=0.0;
|
||||
return AF_ERROR;
|
||||
}
|
||||
|
||||
// Set new len and allocate new buffer
|
||||
s->tlen = *((float*)arg);
|
||||
af->delay = s->tlen * 1000.0;
|
||||
s->len = af->data->rate*af->data->bps*af->data->nch*(int)s->tlen;
|
||||
s->buf = malloc(s->len);
|
||||
mp_msg(MSGT_AFILTER,MSGL_DBG2,"[delay] Delaying audio output by %0.2fs\n",s->tlen);
|
||||
|
@ -258,7 +258,8 @@ static int control(struct af_instance_s* af, int cmd, void* arg)
|
||||
mp_msg(MSGT_AFILTER,MSGL_V,"[resample] New filter designed up: %i down: %i\n", s->up, s->dn);
|
||||
}
|
||||
|
||||
// Set multiplier
|
||||
// Set multiplier and delay
|
||||
af->delay = (double)(1000*L/2)/((double)n->rate);
|
||||
af->mul.n = s->up;
|
||||
af->mul.d = s->dn;
|
||||
return rv;
|
||||
|
Loading…
Reference in New Issue
Block a user