alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: sutar.mounesh@gmail.com
To: patch@alsa-project.org
Cc: Mounesh Sutar <sutar.mounesh@gmail.com>,
	Timo Wischer <twischer@de.adit-jv.com>,
	alsa-devel@alsa-project.org, mounesh_sutar@mentor.com
Subject: [PATCH 2/2] pcm:plugin: Fix sound capture via MMAP access
Date: Tue,  4 Apr 2017 12:00:18 +0530	[thread overview]
Message-ID: <1491287418-11297-1-git-send-email-sutar.mounesh@gmail.com> (raw)

From: Timo Wischer <twischer@de.adit-jv.com>

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.

Signed-off-by: Timo Wischer <twischer@de.adit-jv.com>
Signed-off-by: Mounesh Sutar <sutar.mounesh@gmail.com>

diff --git a/src/pcm/pcm_plugin.c b/src/pcm/pcm_plugin.c
index aaea2ab..ec57f6e 100644
--- a/src/pcm/pcm_plugin.c
+++ b/src/pcm/pcm_plugin.c
@@ -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;
-- 
2.7.4

             reply	other threads:[~2017-04-04  6:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-04  6:30 sutar.mounesh [this message]
2017-04-05 19:40 ` [PATCH 2/2] pcm:plugin: Fix sound capture via MMAP access Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1491287418-11297-1-git-send-email-sutar.mounesh@gmail.com \
    --to=sutar.mounesh@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=mounesh_sutar@mentor.com \
    --cc=patch@alsa-project.org \
    --cc=twischer@de.adit-jv.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).