mirror of
https://github.com/mpv-player/mpv
synced 2025-03-25 04:38:01 +00:00
af_scaletempo2: calculate latency by center of search block
This changes the emitted pts values from the start of the search block to the center of the search block. Change initial `output_time` accordingly. Initial `search_block_index` is irrelevant, because it's overwritten before the first iteration. Using the `output_time` removes the rounding of `search_block_index`, which also fixes the <20 microsecond gaps in timestamps between output packets. Rationale: The variance in audio position was in the range `0..search-interval`. With this change, the range is (- search-interval / 2)..(search-interval / 2)` which ensures lower maximum offset.
This commit is contained in:
parent
c0728249a1
commit
cf8b7ff0d6
@ -707,7 +707,7 @@ int mp_scaletempo2_fill_buffer(struct mp_scaletempo2 *p,
|
|||||||
p->wsola_output_started = false;
|
p->wsola_output_started = false;
|
||||||
|
|
||||||
// sync audio precisely again
|
// sync audio precisely again
|
||||||
set_output_time(p, p->target_block_index + p->search_block_center_offset);
|
set_output_time(p, p->target_block_index);
|
||||||
remove_old_input_frames(p);
|
remove_old_input_frames(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -725,7 +725,7 @@ int mp_scaletempo2_fill_buffer(struct mp_scaletempo2 *p,
|
|||||||
|
|
||||||
double mp_scaletempo2_get_latency(struct mp_scaletempo2 *p, double playback_rate)
|
double mp_scaletempo2_get_latency(struct mp_scaletempo2 *p, double playback_rate)
|
||||||
{
|
{
|
||||||
return p->input_buffer_frames - p->search_block_index
|
return p->input_buffer_frames - p->output_time
|
||||||
+ p->num_complete_frames * playback_rate;
|
+ p->num_complete_frames * playback_rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -749,7 +749,7 @@ void mp_scaletempo2_destroy(struct mp_scaletempo2 *p)
|
|||||||
void mp_scaletempo2_reset(struct mp_scaletempo2 *p)
|
void mp_scaletempo2_reset(struct mp_scaletempo2 *p)
|
||||||
{
|
{
|
||||||
p->input_buffer_frames = 0;
|
p->input_buffer_frames = 0;
|
||||||
p->output_time = p->search_block_center_offset;
|
p->output_time = 0.0;
|
||||||
p->search_block_index = 0;
|
p->search_block_index = 0;
|
||||||
p->target_block_index = 0;
|
p->target_block_index = 0;
|
||||||
// Clear the queue of decoded packets.
|
// Clear the queue of decoded packets.
|
||||||
@ -771,6 +771,7 @@ static void get_symmetric_hanning_window(int window_length, float* window)
|
|||||||
void mp_scaletempo2_init(struct mp_scaletempo2 *p, int channels, int rate)
|
void mp_scaletempo2_init(struct mp_scaletempo2 *p, int channels, int rate)
|
||||||
{
|
{
|
||||||
p->muted_partial_frame = 0;
|
p->muted_partial_frame = 0;
|
||||||
|
p->output_time = 0;
|
||||||
p->search_block_center_offset = 0;
|
p->search_block_center_offset = 0;
|
||||||
p->search_block_index = 0;
|
p->search_block_index = 0;
|
||||||
p->num_complete_frames = 0;
|
p->num_complete_frames = 0;
|
||||||
@ -813,8 +814,6 @@ void mp_scaletempo2_init(struct mp_scaletempo2 *p, int channels, int rate)
|
|||||||
sizeof(float) * p->ola_window_size * 2);
|
sizeof(float) * p->ola_window_size * 2);
|
||||||
get_symmetric_hanning_window(2 * p->ola_window_size, p->transition_window);
|
get_symmetric_hanning_window(2 * p->ola_window_size, p->transition_window);
|
||||||
|
|
||||||
p->output_time = p->search_block_center_offset;
|
|
||||||
|
|
||||||
p->wsola_output_size = p->ola_window_size + p->ola_hop_size;
|
p->wsola_output_size = p->ola_window_size + p->ola_hop_size;
|
||||||
p->wsola_output = realloc_2d(p->wsola_output, p->channels, p->wsola_output_size);
|
p->wsola_output = realloc_2d(p->wsola_output, p->channels, p->wsola_output_size);
|
||||||
// Initialize for overlap-and-add of the first block.
|
// Initialize for overlap-and-add of the first block.
|
||||||
|
@ -64,7 +64,8 @@ struct mp_scaletempo2 {
|
|||||||
double output_time;
|
double output_time;
|
||||||
// The offset of the center frame of |search_block| w.r.t. its first frame.
|
// The offset of the center frame of |search_block| w.r.t. its first frame.
|
||||||
int search_block_center_offset;
|
int search_block_center_offset;
|
||||||
// Index of the beginning of the |search_block|, in frames.
|
// Index of the beginning of the |search_block|, in frames. This may be
|
||||||
|
// negative, which is handled by |peek_audio_with_zero_prepend|.
|
||||||
int search_block_index;
|
int search_block_index;
|
||||||
// Number of Blocks to search to find the most similar one to the target
|
// Number of Blocks to search to find the most similar one to the target
|
||||||
// frame.
|
// frame.
|
||||||
|
Loading…
Reference in New Issue
Block a user