mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-03 09:01:50 -05:00
alsa: increase interval between smoother updates exponentially for alsa sources, following the scheme for sinks
This commit is contained in:
parent
a0f01ddc95
commit
80c6937303
2 changed files with 21 additions and 7 deletions
|
|
@ -733,10 +733,9 @@ static void update_smoother(struct userdata *u) {
|
|||
now1 = pa_rtclock_now();
|
||||
|
||||
/* check if the time since the last update is bigger than the interval */
|
||||
if (u->last_smoother_update > 0) {
|
||||
if (u->last_smoother_update > 0)
|
||||
if (u->last_smoother_update + u->smoother_interval > now1)
|
||||
return;
|
||||
}
|
||||
|
||||
position = (int64_t) u->write_count - ((int64_t) delay * (int64_t) u->frame_size);
|
||||
|
||||
|
|
@ -745,11 +744,11 @@ static void update_smoother(struct userdata *u) {
|
|||
|
||||
now2 = pa_bytes_to_usec((uint64_t) position, &u->sink->sample_spec);
|
||||
|
||||
pa_smoother_put(u->smoother, now1, now2);
|
||||
|
||||
u->last_smoother_update = now1;
|
||||
/* exponentially increase the update interval up to the MAX limit */
|
||||
u->smoother_interval = PA_MIN (u->smoother_interval * 2, SMOOTHER_MAX_INTERVAL);
|
||||
|
||||
pa_smoother_put(u->smoother, now1, now2);
|
||||
}
|
||||
|
||||
static pa_usec_t sink_get_latency(struct userdata *u) {
|
||||
|
|
@ -927,7 +926,6 @@ static int unsuspend(struct userdata *u) {
|
|||
u->first = TRUE;
|
||||
u->since_start = 0;
|
||||
|
||||
|
||||
pa_log_info("Resumed successfully...");
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -65,6 +65,9 @@
|
|||
#define TSCHED_MIN_SLEEP_USEC (10*PA_USEC_PER_MSEC) /* 10ms */
|
||||
#define TSCHED_MIN_WAKEUP_USEC (4*PA_USEC_PER_MSEC) /* 4ms */
|
||||
|
||||
#define SMOOTHER_MIN_INTERVAL (2*PA_USEC_PER_MSEC) /* 2ms */
|
||||
#define SMOOTHER_MAX_INTERVAL (200*PA_USEC_PER_MSEC) /* 200ms */
|
||||
|
||||
#define VOLUME_ACCURACY (PA_VOLUME_NORM/100)
|
||||
|
||||
struct userdata {
|
||||
|
|
@ -108,6 +111,8 @@ struct userdata {
|
|||
|
||||
pa_smoother *smoother;
|
||||
uint64_t read_count;
|
||||
pa_usec_t smoother_interval;
|
||||
pa_usec_t last_smoother_update;
|
||||
|
||||
pa_reserve_wrapper *reserve;
|
||||
pa_hook_slot *reserve_slot;
|
||||
|
|
@ -691,15 +696,23 @@ static void update_smoother(struct userdata *u) {
|
|||
now1 = pa_timespec_load(&htstamp);
|
||||
}
|
||||
|
||||
position = u->read_count + ((uint64_t) delay * (uint64_t) u->frame_size);
|
||||
|
||||
/* Hmm, if the timestamp is 0, then it wasn't set and we take the current time */
|
||||
if (now1 <= 0)
|
||||
now1 = pa_rtclock_now();
|
||||
|
||||
/* check if the time since the last update is bigger than the interval */
|
||||
if (u->last_smoother_update > 0)
|
||||
if (u->last_smoother_update + u->smoother_interval > now1)
|
||||
return;
|
||||
|
||||
position = u->read_count + ((uint64_t) delay * (uint64_t) u->frame_size);
|
||||
now2 = pa_bytes_to_usec(position, &u->source->sample_spec);
|
||||
|
||||
pa_smoother_put(u->smoother, now1, now2);
|
||||
|
||||
u->last_smoother_update = now1;
|
||||
/* exponentially increase the update interval up to the MAX limit */
|
||||
u->smoother_interval = PA_MIN (u->smoother_interval * 2, SMOOTHER_MAX_INTERVAL);
|
||||
}
|
||||
|
||||
static pa_usec_t source_get_latency(struct userdata *u) {
|
||||
|
|
@ -862,6 +875,8 @@ static int unsuspend(struct userdata *u) {
|
|||
|
||||
u->read_count = 0;
|
||||
pa_smoother_reset(u->smoother, pa_rtclock_now(), TRUE);
|
||||
u->smoother_interval = SMOOTHER_MIN_INTERVAL;
|
||||
u->last_smoother_update = 0;
|
||||
|
||||
pa_log_info("Resumed successfully...");
|
||||
|
||||
|
|
@ -1469,6 +1484,7 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
|
|||
5,
|
||||
pa_rtclock_now(),
|
||||
FALSE);
|
||||
u->smoother_interval = SMOOTHER_MIN_INTERVAL;
|
||||
|
||||
dev_id = pa_modargs_get_value(
|
||||
ma, "device_id",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue