Skip to contentSkip to conversation

pcm:plugin: Fix sound capture via MMAP access

PATCH Applied [email protected] 2 participants 2 messages Apr 4, 2017 – Apr 5, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 pcm:plugin: Fix sound capture via MMAP access

From: Timo Wischer <[email protected]>

Distorted sound is heard if the capture device of an ioplug plugin is used, which is accessed through any ALSA plugin (like copy, linear, ...) via MMAP access. E.g. aplay -> loop -> copy -> arecord -M -> aplay -> hw:0
As mentioned in the ALSA API (see pcm/pcm.c:942):
The function #snd_pcm_avail_update() have to be called
before any mmap begin+commit operation.

src/pcm/pcm_plugin.c +8 -1
index aaea2ab..ec57f6e 100644
@@ -490,7 +490,14 @@ static snd_pcm_sframes_t snd_pcm_plugin_avail_update(snd_pcm_t *pcm)
 			snd_pcm_uframes_t slave_offset;
 			snd_pcm_uframes_t slave_frames = ULONG_MAX;
 			snd_pcm_sframes_t result;
-
+			/* As mentioned in the ALSA API (see pcm/pcm.c:942):
+			 * The function #snd_pcm_avail_update()
+			 * have to be called before any mmap begin+commit operation.
+			 * Otherwise the snd_pcm_areas_copy will not called a second time.
+			 * But this is needed, if the ring buffer wrap is reached and
+			 * there is more data available.
+			 */
+			slave_size = snd_pcm_avail_update(slave);
 			result = snd_pcm_mmap_begin(slave, &slave_areas, &slave_offset, &slave_frames);
 			if (result < 0) {
 				err = result;
Signature · 1 line
2.7.4
Applied
#1 lore raw
Quoted 10 lines · On Tue, 04 Apr 2017 08:30:18 +0200, [email protected] wrote:

From: Timo Wischer <[email protected]>

Distorted sound is heard if the capture device of an ioplug plugin is used, which is accessed through any ALSA plugin (like copy, linear, ...) via MMAP access. E.g. aplay -> loop -> copy -> arecord -M -> aplay -> hw:0
As mentioned in the ALSA API (see pcm/pcm.c:942):
The function #snd_pcm_avail_update() have to be called
before any mmap begin+commit operation.

Quoted 2 lines

Applied this one, too. Thanks.

Takashi

Quoted 24 lines
src/pcm/pcm_plugin.c +8 -1
index aaea2ab..ec57f6e 100644
@@ -490,7 +490,14 @@ static snd_pcm_sframes_t snd_pcm_plugin_avail_update(snd_pcm_t *pcm)
 			snd_pcm_uframes_t slave_offset;
 			snd_pcm_uframes_t slave_frames = ULONG_MAX;
 			snd_pcm_sframes_t result;
-
+			/* As mentioned in the ALSA API (see pcm/pcm.c:942):
+			 * The function #snd_pcm_avail_update()
+			 * have to be called before any mmap begin+commit operation.
+			 * Otherwise the snd_pcm_areas_copy will not called a second time.
+			 * But this is needed, if the ring buffer wrap is reached and
+			 * there is more data available.
+			 */
+			slave_size = snd_pcm_avail_update(slave);
 			result = snd_pcm_mmap_begin(slave, &slave_areas, &slave_offset, &slave_frames);
 			if (result < 0) {
 				err = result;
Signature · 1 line
2.7.4