From patchwork Thu Oct 18 10:50:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timo Wischer X-Patchwork-Id: 10647035 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 89411109C for ; Thu, 18 Oct 2018 11:26:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6DA9D2863B for ; Thu, 18 Oct 2018 11:26:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5C2A52864A; Thu, 18 Oct 2018 11:26:49 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham 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 5ABC52863B for ; Thu, 18 Oct 2018 11:26:48 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id B300E2675BD; Thu, 18 Oct 2018 12:50:47 +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 79F912675BD; Thu, 18 Oct 2018 12:50:45 +0200 (CEST) Received: from smtp1.de.adit-jv.com (smtp1.de.adit-jv.com [62.225.105.245]) by alsa0.perex.cz (Postfix) with ESMTP id 53C5D26759E; Thu, 18 Oct 2018 12:50:40 +0200 (CEST) Received: from localhost (smtp1.de.adit-jv.com [127.0.0.1]) by smtp1.de.adit-jv.com (Postfix) with ESMTP id 8F3E13C02EC; Thu, 18 Oct 2018 12:50:39 +0200 (CEST) Received: from smtp1.de.adit-jv.com ([127.0.0.1]) by localhost (smtp1.de.adit-jv.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UeLNRndEJzom; Thu, 18 Oct 2018 12:50:33 +0200 (CEST) Received: from HI2EXCH01.adit-jv.com (hi2exch01.adit-jv.com [10.72.92.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by smtp1.de.adit-jv.com (Postfix) with ESMTPS id 4FC883C02EF; Thu, 18 Oct 2018 12:50:32 +0200 (CEST) Received: from vmlxhi-087.adit-jv.com (10.72.93.172) by HI2EXCH01.adit-jv.com (10.72.92.24) with Microsoft SMTP Server (TLS) id 14.3.408.0; Thu, 18 Oct 2018 12:50:32 +0200 From: To: Date: Thu, 18 Oct 2018 12:50:26 +0200 Message-ID: <1539859826-17683-1-git-send-email-twischer@de.adit-jv.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [10.72.93.172] Cc: Timo Wischer , alsa-devel@alsa-project.org Subject: [alsa-devel] [PATCH - Intervals 1/1] interval: Interpret (x x+1] correctly and return x+1 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP From: Timo Wischer Without this change an interval of (x x+1] will be interpreted as an empty interval but the right value would be x+1. This leads to a failing snd_pcm_hw_params() call which returns -EINVAL. An example issue log is given in the following: snd_pcm_hw_params failed with err -22 (Invalid argument) ACCESS: MMAP_NONINTERLEAVED FORMAT: S16_LE SUBFORMAT: STD SAMPLE_BITS: 16 FRAME_BITS: 16 CHANNELS: 1 RATE: 16000 PERIOD_TIME: (15999 16000] PERIOD_SIZE: (255 256] PERIOD_BYTES: (510 512] PERIODS: [2 3) BUFFER_TIME: 32000 BUFFER_SIZE: 512 BUFFER_BYTES: 1024 In case of (x x+1) we have to interpret it anyway as a single value of x to compensate rounding issues. For example the period size will result in an interval of (352 353) when the period time is 16ms and the sample rate 22050 Hz (16ms * 22,05 kHz = 352,8 frames). But 352 has to be chosen to allow a buffer size of 705 (32ms * 22,05 kHz = 705,6 frames) which has to be >= 2x period size to avoid Xruns. The buffer size will not end up with an interval of (705 706) similar to the period size because snd_pcm_rate_hw_refine_cchange() calls snd_interval_floor() for the buffer size. Therefore this value will be interpreted as an integer interval instead of a real interval further on. This issue seems to exist since the change of 9bb985c38 ("pcm: snd_interval_refine_first/last: exclude value only if also excluded before") Signed-off-by: Timo Wischer diff --git a/src/pcm/interval_inline.h b/src/pcm/interval_inline.h index a68e292..5e59d72 100644 --- a/src/pcm/interval_inline.h +++ b/src/pcm/interval_inline.h @@ -51,12 +51,14 @@ INTERVAL_INLINE int snd_interval_single(const snd_interval_t *i) { assert(!snd_interval_empty(i)); return (i->min == i->max || - (i->min + 1 == i->max && i->openmax)); + (i->min + 1 == i->max && (i->openmin || i->openmax))); } INTERVAL_INLINE int snd_interval_value(const snd_interval_t *i) { assert(snd_interval_single(i)); + if (!i->openmax) + return i->max; return i->min; }