From patchwork Tue Apr 4 06:30:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: sutar.mounesh@gmail.com X-Patchwork-Id: 9660877 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 21948602B9 for ; Tue, 4 Apr 2017 06:35:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1575928329 for ; Tue, 4 Apr 2017 06:35:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 068702846D; Tue, 4 Apr 2017 06:35:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=no version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E82D28329 for ; Tue, 4 Apr 2017 06:35:29 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id A636B266E07; Tue, 4 Apr 2017 08:35:24 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 9624D266E13; Tue, 4 Apr 2017 08:35:23 +0200 (CEST) Received: from mail-wr0-f195.google.com (mail-wr0-f195.google.com [209.85.128.195]) by alsa0.perex.cz (Postfix) with ESMTP id DFDD9266E07; Tue, 4 Apr 2017 08:35:05 +0200 (CEST) Received: by mail-wr0-f195.google.com with SMTP id k6so37911815wre.3; Mon, 03 Apr 2017 23:35:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=Qp8dc9oMELQshHQSIip+Vgu6Y1e2iMFjV4hJkek2wEg=; b=Tc+qY7mbpqpuAgTrgihi2b/IgGKLBrTi1LfN99lXpHKwEMxGkAUgLF+btrqYVkFHTi nBu9/CKHQHMinrnO3Eb1l5cZAOgDCRXgzh3NUYoCQ69fodf5q+dBAKUPNczpypmFrJg5 GKvuOB1MhYbe+NIVxHFYwBtR8YwONdktPlc3GW0OXLxxL8veSLg/v8nhIAQqYJNbPFCA 34IfQu3sx8cjB5FPdtATTbZ4Eyq3o+oMBj8CKv4bIaHZFCfeF1jf4FKUx1ynWh07WbpL ybztmUr6sGWDG/P+C7s+UXYgG1XnHI3r+mynFtUizKWjiwRuuOsinzURz2E1biidvhX5 15QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Qp8dc9oMELQshHQSIip+Vgu6Y1e2iMFjV4hJkek2wEg=; b=UnAN6zcbre7M6Gz9yMRRhrMGRivEtYaGvKfX535QT6HhWPgjEMq+wT9KhD8pGVXloL vlTwk/XkCj5+GeYV6Lmtr1kKToUF3eklalk6ZAM9pOXPQnYOlPoEUCEUSs2Qef6/Tb5r 1HgqAnQx4YVM3SPwiFKpXvYwuJYwV5USoNZUcb9t1CcKTeOjFx2Qb5vZPqGHqSZomsCP nt06AhJCUGFYqySkx5L3eV4wkSuldobvqWLw1iq1Y9Z0zE3TBRSAJ42qe2/aPfnz+1ni 1eM3wXpPM0rir5CvxzHXfwfmPnEXfAmS1UNV8/h1ebIxgDaaG05rjiII766Q7XVc+N5M TBug== X-Gm-Message-State: AFeK/H3OgvMKrBEpJS88rSEvUs+b+vUq4KK/F46m5/3O8/0WwPdqseOD1sLNwl7ee+g5Fg== X-Received: by 10.223.172.129 with SMTP id o1mr17048402wrc.121.1491287704900; Mon, 03 Apr 2017 23:35:04 -0700 (PDT) Received: from msutar-VirtualBox.mgc.mentorg.com (nat-sch.mentorg.com. [139.181.36.34]) by smtp.gmail.com with ESMTPSA id v188sm2534527wmg.11.2017.04.03.23.35.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 03 Apr 2017 23:35:04 -0700 (PDT) From: sutar.mounesh@gmail.com To: patch@alsa-project.org Date: Tue, 4 Apr 2017 12:00:18 +0530 Message-Id: <1491287418-11297-1-git-send-email-sutar.mounesh@gmail.com> X-Mailer: git-send-email 2.7.4 Cc: Mounesh Sutar , Timo Wischer , alsa-devel@alsa-project.org, mounesh_sutar@mentor.com Subject: [alsa-devel] [PATCH 2/2] pcm:plugin: Fix sound capture via MMAP access X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP From: Timo Wischer 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 Signed-off-by: Mounesh Sutar 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;