summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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)
{