aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2016-08-13 15:19:12 +0200
committerAndreas Eversberg <jolly@eversberg.eu>2016-08-13 15:19:12 +0200
commit7d111546c418d7a0176d6aba4d21f727a75915db (patch)
tree9013af22f2d60b3f4eb9f953fe9ed41769042c18 /src
parent541eafe59effc407a811f645608a7a9c93425732 (diff)
Alsa: Keep 8 samples in input buffer to avoid reading corrupted samples
Diffstat (limited to 'src')
-rw-r--r--src/common/sound_alsa.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/common/sound_alsa.c b/src/common/sound_alsa.c
index 638f25e..8762f1a 100644
--- a/src/common/sound_alsa.c
+++ b/src/common/sound_alsa.c
@@ -218,6 +218,8 @@ int sound_write(void *inst, int16_t *samples_left, int16_t *samples_right, int n
return rc;
}
+#define KEEP_FRAMES 8 /* minimum frames not to read, due to bug in ALSA */
+
int sound_read(void *inst, int16_t *samples_left, int16_t *samples_right, int num)
{
sound_t *sound = (sound_t *)inst;
@@ -227,12 +229,12 @@ int sound_read(void *inst, int16_t *samples_left, int16_t *samples_right, int nu
/* get samples in rx buffer */
in = snd_pcm_avail(sound->chandle);
- /* if less than 2 frames available, try next time */
- if (in < 2)
+ /* if not more than KEEP_FRAMES frames available, try next time */
+ if (in <= KEEP_FRAMES)
return 0;
- /* read one frame less than in buffer, because snd_pcm_readi() seems
- * to corrupt last frame */
- in--;
+ /* read some frames less than in buffer, because snd_pcm_readi() seems
+ * to corrupt last frames */
+ in -= KEEP_FRAMES;
if (in > num)
in = num;