annotate ffmpeg/libavdevice/timefilter.h @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents 6840f77b83aa
children
rev   line source
yading@10 1 /*
yading@10 2 * Delay Locked Loop based time filter prototypes and declarations
yading@10 3 * Copyright (c) 2009 Samalyse
yading@10 4 * Copyright (c) 2009 Michael Niedermayer
yading@10 5 * Author: Olivier Guilyardi <olivier samalyse com>
yading@10 6 * Michael Niedermayer <michaelni gmx at>
yading@10 7 *
yading@10 8 * This file is part of FFmpeg.
yading@10 9 *
yading@10 10 * FFmpeg is free software; you can redistribute it and/or
yading@10 11 * modify it under the terms of the GNU Lesser General Public
yading@10 12 * License as published by the Free Software Foundation; either
yading@10 13 * version 2.1 of the License, or (at your option) any later version.
yading@10 14 *
yading@10 15 * FFmpeg is distributed in the hope that it will be useful,
yading@10 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@10 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@10 18 * Lesser General Public License for more details.
yading@10 19 *
yading@10 20 * You should have received a copy of the GNU Lesser General Public
yading@10 21 * License along with FFmpeg; if not, write to the Free Software
yading@10 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@10 23 */
yading@10 24
yading@10 25 #ifndef AVDEVICE_TIMEFILTER_H
yading@10 26 #define AVDEVICE_TIMEFILTER_H
yading@10 27
yading@10 28 /**
yading@10 29 * Opaque type representing a time filter state
yading@10 30 *
yading@10 31 * The purpose of this filter is to provide a way to compute accurate time
yading@10 32 * stamps that can be compared to wall clock time, especially when dealing
yading@10 33 * with two clocks: the system clock and a hardware device clock, such as
yading@10 34 * a soundcard.
yading@10 35 */
yading@10 36 typedef struct TimeFilter TimeFilter;
yading@10 37
yading@10 38
yading@10 39 /**
yading@10 40 * Create a new Delay Locked Loop time filter
yading@10 41 *
yading@10 42 * feedback2_factor and feedback3_factor are the factors used for the
yading@10 43 * multiplications that are respectively performed in the second and third
yading@10 44 * feedback paths of the loop.
yading@10 45 *
yading@10 46 * Unless you know what you are doing, you should set these as follow:
yading@10 47 *
yading@10 48 * o = 2 * M_PI * bandwidth * period_in_seconds
yading@10 49 * feedback2_factor = sqrt(2) * o
yading@10 50 * feedback3_factor = o * o
yading@10 51 *
yading@10 52 * Where bandwidth is up to you to choose. Smaller values will filter out more
yading@10 53 * of the jitter, but also take a longer time for the loop to settle. A good
yading@10 54 * starting point is something between 0.3 and 3 Hz.
yading@10 55 *
yading@10 56 * @param time_base period of the hardware clock in seconds
yading@10 57 * (for example 1.0/44100)
yading@10 58 * @param period expected update interval, in input units
yading@10 59 * @param brandwidth filtering bandwidth, in Hz
yading@10 60 *
yading@10 61 * For more details about these parameters and background concepts please see:
yading@10 62 * http://www.kokkinizita.net/papers/usingdll.pdf
yading@10 63 */
yading@10 64 TimeFilter * ff_timefilter_new(double clock_period, double feedback2_factor, double feedback3_factor);
yading@10 65
yading@10 66 /**
yading@10 67 * Update the filter
yading@10 68 *
yading@10 69 * This function must be called in real time, at each process cycle.
yading@10 70 *
yading@10 71 * @param period the device cycle duration in clock_periods. For example, at
yading@10 72 * 44.1kHz and a buffer size of 512 frames, period = 512 when clock_period
yading@10 73 * was 1.0/44100, or 512/44100 if clock_period was 1.
yading@10 74 *
yading@10 75 * system_time, in seconds, should be the value of the system clock time,
yading@10 76 * at (or as close as possible to) the moment the device hardware interrupt
yading@10 77 * occurred (or any other event the device clock raises at the beginning of a
yading@10 78 * cycle).
yading@10 79 *
yading@10 80 * @return the filtered time, in seconds
yading@10 81 */
yading@10 82 double ff_timefilter_update(TimeFilter *self, double system_time, double period);
yading@10 83
yading@10 84 /**
yading@10 85 * Evaluate the filter at a specified time
yading@10 86 *
yading@10 87 * @param delta difference between the requested time and the current time
yading@10 88 * (last call to ff_timefilter_update).
yading@10 89 * @return the filtered time
yading@10 90 */
yading@10 91 double ff_timefilter_eval(TimeFilter *self, double delta);
yading@10 92
yading@10 93 /**
yading@10 94 * Reset the filter
yading@10 95 *
yading@10 96 * This function should mainly be called in case of XRUN.
yading@10 97 *
yading@10 98 * Warning: after calling this, the filter is in an undetermined state until
yading@10 99 * the next call to ff_timefilter_update()
yading@10 100 */
yading@10 101 void ff_timefilter_reset(TimeFilter *);
yading@10 102
yading@10 103 /**
yading@10 104 * Free all resources associated with the filter
yading@10 105 */
yading@10 106 void ff_timefilter_destroy(TimeFilter *);
yading@10 107
yading@10 108 #endif /* AVDEVICE_TIMEFILTER_H */