Skip to content

Commit

Permalink
Set ALSA buffer time to 100 ms to improve Pipewire playback
Browse files Browse the repository at this point in the history
Adjust text mode update time to 20 ms to allow time for refills.
  • Loading branch information
frno7 committed Jan 7, 2025
1 parent dc0d2e4 commit b499c49
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/out/alsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,13 @@ static void *alsa_open(const char *output, int frequency, bool nonblocking)
pr_fatal_error("%s: ALSA snd_pcm_hw_params_set_channels failed: %s\n",
output, snd_strerror(err));

unsigned int buffer_time = 100000; /* 100 ms */
err = snd_pcm_hw_params_set_buffer_time_near(state->pcm_handle,
state->hwparams, &buffer_time, NULL);
if (err < 0)
pr_fatal_error("%s: ALSA snd_pcm_hw_params_set_buffer_time_near failed: %s\n",
output, snd_strerror(err));

err = snd_pcm_hw_params(state->pcm_handle, state->hwparams);
if (err < 0)
pr_fatal_error("%s: ALSA snd_pcm_hw_params failed: %s\n",
Expand Down
4 changes: 3 additions & 1 deletion system/unix/text-mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "system/unix/text-mode.h"
#include "system/unix/tty.h"

#define BUFFER_UPDATE_TIME 20 /* 20 ms */

struct sample_buffer {
u64 timestamp;

Expand Down Expand Up @@ -196,7 +198,7 @@ static u64 sample_buffer_update(struct sample_buffer *sb, u64 timestamp)
sb->buffer[sb->index].left,
sb->buffer[sb->index].right,
sb->output_arg)) {
sb->timestamp = timestamp + 100;
sb->timestamp = timestamp + (BUFFER_UPDATE_TIME);
break;
}

Expand Down

0 comments on commit b499c49

Please sign in to comment.