yading@10: /* yading@10: * Delay Locked Loop based time filter prototypes and declarations yading@10: * Copyright (c) 2009 Samalyse yading@10: * Copyright (c) 2009 Michael Niedermayer yading@10: * Author: Olivier Guilyardi yading@10: * Michael Niedermayer yading@10: * yading@10: * This file is part of FFmpeg. yading@10: * yading@10: * FFmpeg is free software; you can redistribute it and/or yading@10: * modify it under the terms of the GNU Lesser General Public yading@10: * License as published by the Free Software Foundation; either yading@10: * version 2.1 of the License, or (at your option) any later version. yading@10: * yading@10: * FFmpeg is distributed in the hope that it will be useful, yading@10: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@10: * Lesser General Public License for more details. yading@10: * yading@10: * You should have received a copy of the GNU Lesser General Public yading@10: * License along with FFmpeg; if not, write to the Free Software yading@10: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@10: */ yading@10: yading@10: #ifndef AVDEVICE_TIMEFILTER_H yading@10: #define AVDEVICE_TIMEFILTER_H yading@10: yading@10: /** yading@10: * Opaque type representing a time filter state yading@10: * yading@10: * The purpose of this filter is to provide a way to compute accurate time yading@10: * stamps that can be compared to wall clock time, especially when dealing yading@10: * with two clocks: the system clock and a hardware device clock, such as yading@10: * a soundcard. yading@10: */ yading@10: typedef struct TimeFilter TimeFilter; yading@10: yading@10: yading@10: /** yading@10: * Create a new Delay Locked Loop time filter yading@10: * yading@10: * feedback2_factor and feedback3_factor are the factors used for the yading@10: * multiplications that are respectively performed in the second and third yading@10: * feedback paths of the loop. yading@10: * yading@10: * Unless you know what you are doing, you should set these as follow: yading@10: * yading@10: * o = 2 * M_PI * bandwidth * period_in_seconds yading@10: * feedback2_factor = sqrt(2) * o yading@10: * feedback3_factor = o * o yading@10: * yading@10: * Where bandwidth is up to you to choose. Smaller values will filter out more yading@10: * of the jitter, but also take a longer time for the loop to settle. A good yading@10: * starting point is something between 0.3 and 3 Hz. yading@10: * yading@10: * @param time_base period of the hardware clock in seconds yading@10: * (for example 1.0/44100) yading@10: * @param period expected update interval, in input units yading@10: * @param brandwidth filtering bandwidth, in Hz yading@10: * yading@10: * For more details about these parameters and background concepts please see: yading@10: * http://www.kokkinizita.net/papers/usingdll.pdf yading@10: */ yading@10: TimeFilter * ff_timefilter_new(double clock_period, double feedback2_factor, double feedback3_factor); yading@10: yading@10: /** yading@10: * Update the filter yading@10: * yading@10: * This function must be called in real time, at each process cycle. yading@10: * yading@10: * @param period the device cycle duration in clock_periods. For example, at yading@10: * 44.1kHz and a buffer size of 512 frames, period = 512 when clock_period yading@10: * was 1.0/44100, or 512/44100 if clock_period was 1. yading@10: * yading@10: * system_time, in seconds, should be the value of the system clock time, yading@10: * at (or as close as possible to) the moment the device hardware interrupt yading@10: * occurred (or any other event the device clock raises at the beginning of a yading@10: * cycle). yading@10: * yading@10: * @return the filtered time, in seconds yading@10: */ yading@10: double ff_timefilter_update(TimeFilter *self, double system_time, double period); yading@10: yading@10: /** yading@10: * Evaluate the filter at a specified time yading@10: * yading@10: * @param delta difference between the requested time and the current time yading@10: * (last call to ff_timefilter_update). yading@10: * @return the filtered time yading@10: */ yading@10: double ff_timefilter_eval(TimeFilter *self, double delta); yading@10: yading@10: /** yading@10: * Reset the filter yading@10: * yading@10: * This function should mainly be called in case of XRUN. yading@10: * yading@10: * Warning: after calling this, the filter is in an undetermined state until yading@10: * the next call to ff_timefilter_update() yading@10: */ yading@10: void ff_timefilter_reset(TimeFilter *); yading@10: yading@10: /** yading@10: * Free all resources associated with the filter yading@10: */ yading@10: void ff_timefilter_destroy(TimeFilter *); yading@10: yading@10: #endif /* AVDEVICE_TIMEFILTER_H */