mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-12-20 04:30:08 +01:00
This patch adds an alternative time smoother implementation based on the theory found at https://www.freedesktop.org/software/pulseaudio/misc/rate_estimator.odt. The functions were written to replace the current smoother functions nearly on a one-to-one basis, though there are a few differences: - The smoother_2_put() function takes a byte count instead of a sound card time as argument. This was changed because in most places a sample count was converted to a time before passing it to the smoother. - The smoother needs to know sample rate and frame size to convert byte counts to time. - A smoother_2_get_delay() function was added to directly retrieve the stream delay from the smoother. - A hack for USB devices was added which works around an issue in the alsa latency reports for USB devices. The smoother delivers much better precision than the current implementation. For results, see the document referenced above. The new functions are still unused. The following patches will convert all callers of the smoother functions so that they can use both smoother implementations, depending on a configure option. Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/55>
53 lines
2.2 KiB
C
53 lines
2.2 KiB
C
#ifndef foopulsetimesmoother2hfoo
|
|
#define foopulsetimesmoother2hfoo
|
|
|
|
/***
|
|
This file is part of PulseAudio.
|
|
|
|
PulseAudio is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU Lesser General Public License as
|
|
published by the Free Software Foundation; either version 2.1 of the
|
|
License, or (at your option) any later version.
|
|
|
|
PulseAudio is distributed in the hope that it will be useful, but
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
|
|
***/
|
|
|
|
#include <pulse/sample.h>
|
|
|
|
typedef struct pa_smoother_2 pa_smoother_2;
|
|
|
|
/* Create new smoother */
|
|
pa_smoother_2* pa_smoother_2_new(pa_usec_t window, pa_usec_t time_stamp, uint32_t frame_size, uint32_t rate);
|
|
/* Free the smoother */
|
|
void pa_smoother_2_free(pa_smoother_2* s);
|
|
/* Reset the smoother */
|
|
void pa_smoother_2_reset(pa_smoother_2 *s, pa_usec_t time_stamp);
|
|
/* Pause the smoother */
|
|
void pa_smoother_2_pause(pa_smoother_2 *s, pa_usec_t time_stamp);
|
|
/* Resume the smoother */
|
|
void pa_smoother_2_resume(pa_smoother_2 *s, pa_usec_t time_stamp);
|
|
|
|
/* Add a new data point and re-calculate time conversion factor */
|
|
void pa_smoother_2_put(pa_smoother_2 *s, pa_usec_t time_stamp, int64_t byte_count);
|
|
|
|
/* Calculate the current latency. For a source, the sign of the result must be inverted */
|
|
int64_t pa_smoother_2_get_delay(pa_smoother_2 *s, pa_usec_t time_stamp, size_t byte_count);
|
|
/* Convert system time since start to sound card time */
|
|
pa_usec_t pa_smoother_2_get(pa_smoother_2 *s, pa_usec_t time_stamp);
|
|
/* Convert a time interval from sound card time to system time */
|
|
pa_usec_t pa_smoother_2_translate(pa_smoother_2 *s, pa_usec_t time_difference);
|
|
|
|
/* Enable USB hack, only used for alsa sinks */
|
|
void pa_smoother_2_usb_hack_enable(pa_smoother_2 *s, bool enable, pa_usec_t offset);
|
|
/* Set sample rate */
|
|
void pa_smoother_2_set_rate(pa_smoother_2 *s, pa_usec_t time_stamp, uint32_t rate);
|
|
/* Set rate and frame size */
|
|
void pa_smoother_2_set_sample_spec(pa_smoother_2 *s, pa_usec_t time_stamp, pa_sample_spec *spec);
|
|
|
|
#endif
|