summaryrefslogtreecommitdiff
path: root/firmware/target
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target')
-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;
81static unsigned int real_sample_rate = 0; 81static unsigned int real_sample_rate = 0;
82 82
83static snd_pcm_t *handle = NULL; 83static snd_pcm_t *handle = NULL;
84static snd_pcm_sframes_t buffer_size = MIX_FRAME_SAMPLES * 32; /* ~16k */ 84static snd_pcm_sframes_t buffer_size;
85static snd_pcm_sframes_t period_size = MIX_FRAME_SAMPLES * 4; /* ~4k */ 85static snd_pcm_sframes_t period_size;
86static sample_t *frames; 86static sample_t *frames = NULL;
87 87
88static const void *pcm_data = 0; 88static const void *pcm_data = 0;
89static size_t pcm_size = 0; 89static size_t pcm_size = 0;
@@ -103,6 +103,18 @@ static int set_hwparams(snd_pcm_t *handle)
103 snd_pcm_hw_params_t *params; 103 snd_pcm_hw_params_t *params;
104 snd_pcm_hw_params_malloc(&params); 104 snd_pcm_hw_params_malloc(&params);
105 105
106 /* Size playback buffers based on sample rate */
107 if (pcm_sampr > SAMPR_96) {
108 buffer_size = MIX_FRAME_SAMPLES * 32 * 4; /* ~64k */
109 period_size = MIX_FRAME_SAMPLES * 4 * 4; /* ~16k */
110 } else if (pcm_sampr > SAMPR_48) {
111 buffer_size = MIX_FRAME_SAMPLES * 32 * 2; /* ~32k */
112 period_size = MIX_FRAME_SAMPLES * 4 * 2; /* ~8k */
113 } else {
114 buffer_size = MIX_FRAME_SAMPLES * 32; /* ~16k */
115 period_size = MIX_FRAME_SAMPLES * 4; /* ~4k */
116 }
117
106 /* choose all parameters */ 118 /* choose all parameters */
107 err = snd_pcm_hw_params_any(handle, params); 119 err = snd_pcm_hw_params_any(handle, params);
108 if (err < 0) 120 if (err < 0)
@@ -195,7 +207,7 @@ static int set_swparams(snd_pcm_t *handle)
195 printf("Unable to determine current swparams for playback: %s\n", snd_strerror(err)); 207 printf("Unable to determine current swparams for playback: %s\n", snd_strerror(err));
196 goto error; 208 goto error;
197 } 209 }
198 /* start the transfer when the buffer is haalmost full */ 210 /* start the transfer when the buffer is half full */
199 err = snd_pcm_sw_params_set_start_threshold(handle, swparams, buffer_size / 2); 211 err = snd_pcm_sw_params_set_start_threshold(handle, swparams, buffer_size / 2);
200 if (err < 0) 212 if (err < 0)
201 { 213 {