alsa: Use larger playback buffers for higher bitrates

(existing ones apply up to 48KHz, scale up linearly to 192KHz)

Change-Id: Iac32d49b8073b63a5d40fd21f41437e6051cb8de
This commit is contained in:
Solomon Peachy 2020-10-02 07:27:46 -04:00
parent 90af40e90c
commit b0e1b245b4
1 changed files with 16 additions and 4 deletions

View File

@ -81,9 +81,9 @@ static unsigned int sample_rate = 0;
static unsigned int real_sample_rate = 0;
static snd_pcm_t *handle = NULL;
static snd_pcm_sframes_t buffer_size = MIX_FRAME_SAMPLES * 32; /* ~16k */
static snd_pcm_sframes_t period_size = MIX_FRAME_SAMPLES * 4; /* ~4k */
static sample_t *frames;
static snd_pcm_sframes_t buffer_size;
static snd_pcm_sframes_t period_size;
static sample_t *frames = NULL;
static const void *pcm_data = 0;
static size_t pcm_size = 0;
@ -103,6 +103,18 @@ static int set_hwparams(snd_pcm_t *handle)
snd_pcm_hw_params_t *params;
snd_pcm_hw_params_malloc(&params);
/* Size playback buffers based on sample rate */
if (pcm_sampr > SAMPR_96) {
buffer_size = MIX_FRAME_SAMPLES * 32 * 4; /* ~64k */
period_size = MIX_FRAME_SAMPLES * 4 * 4; /* ~16k */
} else if (pcm_sampr > SAMPR_48) {
buffer_size = MIX_FRAME_SAMPLES * 32 * 2; /* ~32k */
period_size = MIX_FRAME_SAMPLES * 4 * 2; /* ~8k */
} else {
buffer_size = MIX_FRAME_SAMPLES * 32; /* ~16k */
period_size = MIX_FRAME_SAMPLES * 4; /* ~4k */
}
/* choose all parameters */
err = snd_pcm_hw_params_any(handle, params);
if (err < 0)
@ -195,7 +207,7 @@ static int set_swparams(snd_pcm_t *handle)
printf("Unable to determine current swparams for playback: %s\n", snd_strerror(err));
goto error;
}
/* start the transfer when the buffer is haalmost full */
/* start the transfer when the buffer is half full */
err = snd_pcm_sw_params_set_start_threshold(handle, swparams, buffer_size / 2);
if (err < 0)
{