summaryrefslogtreecommitdiffstats
path: root/firmware/target/hosted
diff options
context:
space:
mode:
authorSolomon Peachy <pizza@shaftnet.org>2020-10-02 07:27:46 -0400
committerSolomon Peachy <pizza@shaftnet.org>2020-10-02 09:50:38 -0400
commitb0e1b245b471f2c71d7b74ce882fbaa318e3ab91 (patch)
treef8ddb9c95cce03a0e53501f873b5363f5b0488e8 /firmware/target/hosted
parent90af40e90c13eb5d6c9d6fa05bc2d1ca64fcdd0c (diff)
downloadrockbox-b0e1b245b471f2c71d7b74ce882fbaa318e3ab91.tar.gz
rockbox-b0e1b245b471f2c71d7b74ce882fbaa318e3ab91.tar.bz2
rockbox-b0e1b245b471f2c71d7b74ce882fbaa318e3ab91.zip
alsa: Use larger playback buffers for higher bitrates
(existing ones apply up to 48KHz, scale up linearly to 192KHz) Change-Id: Iac32d49b8073b63a5d40fd21f41437e6051cb8de
Diffstat (limited to 'firmware/target/hosted')
-rw-r--r--firmware/target/hosted/pcm-alsa.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/firmware/target/hosted/pcm-alsa.c b/firmware/target/hosted/pcm-alsa.c
index f33b42429c..c7df99e23d 100644
--- a/firmware/target/hosted/pcm-alsa.c
+++ b/firmware/target/hosted/pcm-alsa.c
@@ -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)
{