From patchwork Sun Dec 4 21:16:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1712099 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=d6FHfYSi; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NQKHj6M39z23ns for ; Mon, 5 Dec 2022 08:16:49 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4B67E8555F; Sun, 4 Dec 2022 22:16:35 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.b="d6FHfYSi"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5E67285543; Sun, 4 Dec 2022 22:16:32 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from smtp-relay-canonical-1.canonical.com (smtp-relay-canonical-1.canonical.com [185.125.188.121]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id EF7FB8550C for ; Sun, 4 Dec 2022 22:16:29 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=heinrich.schuchardt@canonical.com Received: from LT2ubnt.fritz.box (ip-088-152-145-137.um26.pools.vodafone-ip.de [88.152.145.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-1.canonical.com (Postfix) with ESMTPSA id 1E62541CE9; Sun, 4 Dec 2022 21:16:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1670188586; bh=wzfZkmk9Mn+OKqzuoyZCQ8AaEfJIwEjDJJ8BD9VMRm0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=d6FHfYSidrFdQ5aJcqaXaO08L7SGEt/y5wZIlzqt8aeyFMLUgThlUy2iLZLQMRX5s 4xpyvsMX/2vNFVRFaxJBPr3C0smX/taI0kqFygjBvg34B8uGuPTgRg45qJoZ4yM7qT NWqSvt4uMBR9Gxln1OR9Oqf98YEwH0xWJ4OkFwITj49ugmgRBeQmFwpZE/n1bPwlui ueSB2DG9cPEwxDhxVpRRDZ86UOS9Egd3EhDpy1w1gAW9r1GfO4Y6jtNA6md4KsgI8X uGqHHITUyKIR3H+pL6ApFbN5WnsKTqrN5PhSglVb1+jCd9Is8IkPTNnQqZA40Ul3GE 01VDzD1Eqn6cA== From: Heinrich Schuchardt To: Simon Glass Cc: Andrew Scull , "R . Chandrasekar" , Minkyu Kang , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH v2 1/7] sound: avoid endless loop Date: Sun, 4 Dec 2022 22:16:01 +0100 Message-Id: <20221204211607.227443-2-heinrich.schuchardt@canonical.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221204211607.227443-1-heinrich.schuchardt@canonical.com> References: <20221204211607.227443-1-heinrich.schuchardt@canonical.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean 'sound play 1 100000' results in an endless loop on the sandbox. If the frequency exceeds half the sampling rate, zero out the output buffer. Fixes: 511ed5fdd389 ("SOUND: SAMSUNG: Add I2S driver") Signed-off-by: Heinrich Schuchardt --- v2: no change --- drivers/sound/sound.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/sound/sound.c b/drivers/sound/sound.c index 041dfdccfe..c0fc50c99d 100644 --- a/drivers/sound/sound.c +++ b/drivers/sound/sound.c @@ -15,7 +15,10 @@ void sound_create_square_wave(uint sample_rate, unsigned short *data, int size, const int period = freq ? sample_rate / freq : 0; const int half = period / 2; - assert(freq); + if (!half) { + memset(data, 0, size); + return; + } /* Make sure we don't overflow our buffer */ if (size % 2) From patchwork Sun Dec 4 21:16:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1712104 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=COS48mTt; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NQKJn1r5Tz23ns for ; Mon, 5 Dec 2022 08:17:45 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 12B328555D; Sun, 4 Dec 2022 22:16:51 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.b="COS48mTt"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8B40C8553D; Sun, 4 Dec 2022 22:16:37 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from smtp-relay-canonical-1.canonical.com (smtp-relay-canonical-1.canonical.com [185.125.188.121]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 7156E85530 for ; Sun, 4 Dec 2022 22:16:30 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=heinrich.schuchardt@canonical.com Received: from LT2ubnt.fritz.box (ip-088-152-145-137.um26.pools.vodafone-ip.de [88.152.145.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-1.canonical.com (Postfix) with ESMTPSA id 93C2841D13; Sun, 4 Dec 2022 21:16:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1670188589; bh=05FzOVM6jX+25lTX2yY/43mhalj7MMUEx7U7fY5wN10=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=COS48mTtoItLb0e385xss/p/DIPUkvgjapsa9VkkpzSnAQSjd8PTIA2L0gUV07FJ4 0jpyXMdjILBd7CrPUzhFEcQpCKNUEzrmzas2Yl+0GrehYz5wOtKtHgf/8uqMpsINNF lgyITWtFTQ6tqLy7lThfUQiMsKPw3TB8DpaE0Z8OmjAxq4TNAN6ajLTkI4efPQ7oJU wprmaYneHbFwNv2leWPxm8iColjI55C9aY/aNmbcI7Dfyptg8KS7pXY2tzOQJxlZPS M5UvMZs1VY3ekzlXTJDIRdRf2e8/sP5dFx3RFrcNfj/am4PmnTwAY+STcGdDaKUBTV wvJlCjYPF/M1w== From: Heinrich Schuchardt To: Simon Glass Cc: Andrew Scull , "R . Chandrasekar" , Minkyu Kang , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH v2 2/7] test: test sandbox sound driver more rigorously Date: Sun, 4 Dec 2022 22:16:02 +0100 Message-Id: <20221204211607.227443-3-heinrich.schuchardt@canonical.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221204211607.227443-1-heinrich.schuchardt@canonical.com> References: <20221204211607.227443-1-heinrich.schuchardt@canonical.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Consider unexpected values for frequency: * negative frequency * zero frequency * frequency exceeding sampling frequency As in these cases the sum of the samples is zero also check the count of the samples. Signed-off-by: Heinrich Schuchardt --- v2: no change --- arch/sandbox/include/asm/test.h | 10 ++++++++++ drivers/sound/sandbox.c | 9 +++++++++ test/dm/sound.c | 11 +++++++++++ 3 files changed, 30 insertions(+) diff --git a/arch/sandbox/include/asm/test.h b/arch/sandbox/include/asm/test.h index 0406085917..568738c16d 100644 --- a/arch/sandbox/include/asm/test.h +++ b/arch/sandbox/include/asm/test.h @@ -188,6 +188,16 @@ int sandbox_get_setup_called(struct udevice *dev); */ int sandbox_get_sound_active(struct udevice *dev); +/** + * sandbox_get_sound_count() - Read back the count of the sound data so far + * + * This data is provided to the sandbox driver by the sound play() method. + * + * @dev: Device to check + * Return: count of audio data + */ +int sandbox_get_sound_count(struct udevice *dev); + /** * sandbox_get_sound_sum() - Read back the sum of the sound data so far * diff --git a/drivers/sound/sandbox.c b/drivers/sound/sandbox.c index 4a2c87a84c..c6cbd81fdb 100644 --- a/drivers/sound/sandbox.c +++ b/drivers/sound/sandbox.c @@ -29,6 +29,7 @@ struct sandbox_i2s_priv { struct sandbox_sound_priv { int setup_called; /* Incremented when setup() method is called */ bool active; /* TX data is being sent */ + int count; /* Use to count the provided audio data */ int sum; /* Use to sum the provided audio data */ bool allow_beep; /* true to allow the start_beep() interface */ int frequency_hz; /* Beep frequency if active, else 0 */ @@ -68,6 +69,13 @@ int sandbox_get_sound_active(struct udevice *dev) return priv->active; } +int sandbox_get_sound_count(struct udevice *dev) +{ + struct sandbox_sound_priv *priv = dev_get_priv(dev); + + return priv->count; +} + int sandbox_get_sound_sum(struct udevice *dev) { struct sandbox_sound_priv *priv = dev_get_priv(dev); @@ -168,6 +176,7 @@ static int sandbox_sound_play(struct udevice *dev, void *data, uint data_size) for (i = 0; i < data_size; i++) priv->sum += ((uint8_t *)data)[i]; + priv->count += data_size; return i2s_tx_data(uc_priv->i2s, data, data_size); } diff --git a/test/dm/sound.c b/test/dm/sound.c index b73f6ab111..15d545ab5a 100644 --- a/test/dm/sound.c +++ b/test/dm/sound.c @@ -26,8 +26,19 @@ static int dm_test_sound(struct unit_test_state *uts) ut_asserteq(0, sandbox_get_setup_called(dev)); ut_assertok(sound_beep(dev, 1, 100)); + ut_asserteq(48, sandbox_get_sound_count(dev)); ut_asserteq(4560, sandbox_get_sound_sum(dev)); ut_assertok(sound_beep(dev, 1, 100)); + ut_asserteq(96, sandbox_get_sound_count(dev)); + ut_asserteq(9120, sandbox_get_sound_sum(dev)); + ut_assertok(sound_beep(dev, 1, -100)); + ut_asserteq(144, sandbox_get_sound_count(dev)); + ut_asserteq(9120, sandbox_get_sound_sum(dev)); + ut_assertok(sound_beep(dev, 1, 0)); + ut_asserteq(192, sandbox_get_sound_count(dev)); + ut_asserteq(9120, sandbox_get_sound_sum(dev)); + ut_assertok(sound_beep(dev, 1, INT_MAX)); + ut_asserteq(240, sandbox_get_sound_count(dev)); ut_asserteq(9120, sandbox_get_sound_sum(dev)); ut_asserteq(false, sandbox_get_sound_active(dev)); From patchwork Sun Dec 4 21:16:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1712101 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=F07PAoB6; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NQKJ80fLVz23ns for ; Mon, 5 Dec 2022 08:17:11 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6BE8D8553C; Sun, 4 Dec 2022 22:16:42 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.b="F07PAoB6"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0B47F85553; Sun, 4 Dec 2022 22:16:35 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from smtp-relay-canonical-1.canonical.com (smtp-relay-canonical-1.canonical.com [185.125.188.121]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 154BF85536 for ; Sun, 4 Dec 2022 22:16:31 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=heinrich.schuchardt@canonical.com Received: from LT2ubnt.fritz.box (ip-088-152-145-137.um26.pools.vodafone-ip.de [88.152.145.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-1.canonical.com (Postfix) with ESMTPSA id 1680A41E4A; Sun, 4 Dec 2022 21:16:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1670188590; bh=iTvOwP3AFOKKr2q4M+6y0+0Gg5AMM5ZPphjtgLQ36Jo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=F07PAoB6DXA4KW96ZWlhPRWJ/J1O9EMj8u10n2vi7h3BGFuO3rkDB+CuW49sI/BKu oRQ32Sdy8lJDp7L76zxn2S21QXebK4AOW+oOBY06/yhI20cUnXXTK/g8/CLgiE71kH L4xVGBDSd2sAZ5onUAeNIfI5q7Duz8jHXSVhgzSJMcbzshBl+HjHFli+zvhFjRUYRZ Mmk+X/iybegjZge3ljOWfQsfWxd9fPw6S7ntHoSuz4Xd/9vx2zlyXVxV9skD7lqMNy x/zZZRk6BGtglPnINmOSBt6xXft+WGQJ/eMIXbbEkMa54oeiZjnHBTrI/U638UrMLW QJBJmmwB+ihmw== From: Heinrich Schuchardt To: Simon Glass Cc: Andrew Scull , "R . Chandrasekar" , Minkyu Kang , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH v2 3/7] cmd: fix long text for sound command Date: Sun, 4 Dec 2022 22:16:03 +0100 Message-Id: <20221204211607.227443-4-heinrich.schuchardt@canonical.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221204211607.227443-1-heinrich.schuchardt@canonical.com> References: <20221204211607.227443-1-heinrich.schuchardt@canonical.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Make it clear that if only 1 parameter is provided this is the duration. The ISO symbol for hertz is Hz. Fixes: c0c88533fffd ("Sound: Add command for audio playback") Signed-off-by: Heinrich Schuchardt --- v2: no change --- cmd/sound.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/sound.c b/cmd/sound.c index f82f2aa670..20ac3f758e 100644 --- a/cmd/sound.c +++ b/cmd/sound.c @@ -86,5 +86,5 @@ U_BOOT_CMD( sound, 4, 1, do_sound, "sound sub-system", "init - initialise the sound driver\n" - "sound play [len] [freq] - play a sound for len ms at freq hz\n" + "sound play [len [freq]] - play a sound for len ms at freq Hz\n" ); From patchwork Sun Dec 4 21:16:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1712103 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=F+ByHUxf; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NQKJY4gNSz23ns for ; Mon, 5 Dec 2022 08:17:33 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3D7928554F; Sun, 4 Dec 2022 22:16:48 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.b="F+ByHUxf"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8A4CD85542; Sun, 4 Dec 2022 22:16:36 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from smtp-relay-canonical-1.canonical.com (smtp-relay-canonical-1.canonical.com [185.125.188.121]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 34A228553C for ; Sun, 4 Dec 2022 22:16:31 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=heinrich.schuchardt@canonical.com Received: from LT2ubnt.fritz.box (ip-088-152-145-137.um26.pools.vodafone-ip.de [88.152.145.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-1.canonical.com (Postfix) with ESMTPSA id 8350041F11; Sun, 4 Dec 2022 21:16:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1670188590; bh=RbAyDX82d/nFU/amjzy9gq8S7Q22tX+VnLNQvJvFwdc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=F+ByHUxfU73pOl0wnx3yP4G5VBWYdw2+sH2Y/MOB2IgtlryTyfkjJ5ARvAlV8bGz4 0eFXcnAtsBIFW0H0Z7r0Y8KKzPlHuQ94nwvjQ1QtEGAry+r4q6Tk1pAxAW/wvwsb7T FMbgTvTfhJ3O0gGfkMWM+3W3G32Xq1smLxdPNCrZyuI8y4Y35mH1X/NUns/cbQ2ShI DWh3zt7RZJ2IxSzhQHrNiLrmF06R+e+lzKjwBj+gXgxtC0ASRvHot2ZmlMq1fk+FJq HYSskpBCadNTmWHe26a+ii7Uxm7kd003d/fdG9z9faYnYPKushp70bzZpT7S9qPBd5 I89nueDfR/9lw== From: Heinrich Schuchardt To: Simon Glass Cc: Andrew Scull , "R . Chandrasekar" , Minkyu Kang , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH v2 4/7] doc: man-page for the sound command Date: Sun, 4 Dec 2022 22:16:04 +0100 Message-Id: <20221204211607.227443-5-heinrich.schuchardt@canonical.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221204211607.227443-1-heinrich.schuchardt@canonical.com> References: <20221204211607.227443-1-heinrich.schuchardt@canonical.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Provide a man-page for the sound command. Signed-off-by: Heinrich Schuchardt --- v2: add default values --- doc/usage/cmd/sound.rst | 41 +++++++++++++++++++++++++++++++++++++++++ doc/usage/index.rst | 1 + 2 files changed, 42 insertions(+) create mode 100644 doc/usage/cmd/sound.rst diff --git a/doc/usage/cmd/sound.rst b/doc/usage/cmd/sound.rst new file mode 100644 index 0000000000..d3fac243b1 --- /dev/null +++ b/doc/usage/cmd/sound.rst @@ -0,0 +1,41 @@ +.. SPDX-License-Identifier: GPL-2.0+ +.. Copyright 2022, Heinrich Schuchardt + +sound command +============= + +Synopsis +-------- + +:: + + sound init + sound play [len [freq]] + +Description +----------- + +The *sound* command is used to play a beep sound. + +sound init + initializes the sound driver. + +sound play + plays a square wave sound. It does not depend on previously calling + *sound init*. + +len + duration of the sound in ms, defaults to 1000 ms + +freq + frequency of the sound in Hz, defaults to 400 Hz + +Configuration +------------- + +The sound command is enabled by CONFIG_CMD_SOUND=y. + +Return value +------------ + +The return value $? is 0 (true) if the command succeeds, 1 (false) otherwise. diff --git a/doc/usage/index.rst b/doc/usage/index.rst index 0bc82887e9..bbd40a6e18 100644 --- a/doc/usage/index.rst +++ b/doc/usage/index.rst @@ -73,6 +73,7 @@ Shell commands cmd/scp03 cmd/setexpr cmd/size + cmd/sound cmd/temperature cmd/tftpput cmd/true From patchwork Sun Dec 4 21:16:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1712100 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=KjDN7oSw; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NQKHw4rglz23ns for ; Mon, 5 Dec 2022 08:17:00 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0DCF7854D4; Sun, 4 Dec 2022 22:16:40 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.b="KjDN7oSw"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9FEDE85542; Sun, 4 Dec 2022 22:16:35 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from smtp-relay-canonical-1.canonical.com (smtp-relay-canonical-1.canonical.com [185.125.188.121]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 99BA585541 for ; Sun, 4 Dec 2022 22:16:31 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=heinrich.schuchardt@canonical.com Received: from LT2ubnt.fritz.box (ip-088-152-145-137.um26.pools.vodafone-ip.de [88.152.145.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-1.canonical.com (Postfix) with ESMTPSA id 0A80E41F1E; Sun, 4 Dec 2022 21:16:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1670188591; bh=iPem12xIrJXQEuCRbc2gcLE2P+tzSSlpVqwJ/7DXzpQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KjDN7oSwuarNi+WVAuZ/T9kjEDvsZs8nr1jzxWNAZ3tL0dPs6i26LcLObTQVhvvG2 AfuRo1qUslNWaLsfz798DItR12yc6KCUqiOw2Y0vlGg6COZJVV0Mfy/9Ri1y5abnKB iHTgiidXx6OGXndxCvoInceo/o7JCrDNl6IvQJbGzpLZ8+cGZox+3N5ZN21U2Y/xot oWz9oUIgRc7NfSRT5k9hT6aCCwUwv1955SBrCJ7noZHZu9TVPgkuXam0iFx3AtcdeF D2M/y5cGdQXqG/smwqZjNFFuW3+BNRjUXBWz6+natWaMp83JXvaIMvVRDgqtBx6CZh 0kJTAvE4jOFWA== From: Heinrich Schuchardt To: Simon Glass Cc: Andrew Scull , "R . Chandrasekar" , Minkyu Kang , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH v2 5/7] sound: function to generate sine wave Date: Sun, 4 Dec 2022 22:16:05 +0100 Message-Id: <20221204211607.227443-6-heinrich.schuchardt@canonical.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221204211607.227443-1-heinrich.schuchardt@canonical.com> References: <20221204211607.227443-1-heinrich.schuchardt@canonical.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Add function sound_create_sine_wave(). Signed-off-by: Heinrich Schuchardt --- v2: remove stray printf() --- drivers/sound/sound.c | 37 +++++++++++++++++++++++++++++++++++++ include/sound.h | 12 ++++++++++++ 2 files changed, 49 insertions(+) diff --git a/drivers/sound/sound.c b/drivers/sound/sound.c index c0fc50c99d..abf9bb6de2 100644 --- a/drivers/sound/sound.c +++ b/drivers/sound/sound.c @@ -8,6 +8,43 @@ #include #include +/* Amplitude between 1 and 32767 */ +#define AMP 16384 +#define AMP2PI ((int)(6.28318530718 * AMP)) + +void sound_create_sine_wave(uint sample_rate, unsigned short *data, int size, + uint freq, uint channels) +{ + int v, x = 0, y = AMP; + + if (freq >= 0 && freq < sample_rate / 8) { + v = (AMP2PI * freq) / sample_rate; + /* tan(x) = x + x^3/3 + ... */ + v += ((v * v) / AMP * v) / (3 * AMP); + } else { + v = 0; + } + + for (int i = 0; i < size - (2 * channels - 1);) { + int s, dx, dy; + + dx = (v * y) / AMP; + dy = -((v * x) / AMP); + x += dx; + y += dy; + + /* Normalize radius: (1+x)^2 ~ 1+2x, for small x */ + s = AMP * AMP - x * x - y * y; + s /= 2 * AMP; + s += AMP; + x = (s * x) / AMP; + y = (s * y) / AMP; + + for (int j = 0; size && j < channels; ++j, i += 2) + *data++ = x; + } +} + void sound_create_square_wave(uint sample_rate, unsigned short *data, int size, uint freq, uint channels) { diff --git a/include/sound.h b/include/sound.h index dab9ea186e..cf9c3e8fb7 100644 --- a/include/sound.h +++ b/include/sound.h @@ -34,6 +34,18 @@ struct sound_uc_priv { int setup_done; }; +/** + * Generates sine wave sound data for 1 second + * + * @sample_rate: Sample rate in Hz + * @data: data buffer pointer + * @size: size of the buffer in bytes + * @freq: frequency of the wave + * @channels: Number of channels to use + */ +void sound_create_sine_wave(uint sample_rate, unsigned short *data, int size, + uint freq, uint channels); + /** * Generates square wave sound data for 1 second * From patchwork Sun Dec 4 21:16:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1712102 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=wK0TRAqi; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NQKJL1bSvz23ns for ; Mon, 5 Dec 2022 08:17:22 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 870CF85569; Sun, 4 Dec 2022 22:16:45 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.b="wK0TRAqi"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2CC778555B; Sun, 4 Dec 2022 22:16:35 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from smtp-relay-canonical-1.canonical.com (smtp-relay-canonical-1.canonical.com [185.125.188.121]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 2544585542 for ; Sun, 4 Dec 2022 22:16:32 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=heinrich.schuchardt@canonical.com Received: from LT2ubnt.fritz.box (ip-088-152-145-137.um26.pools.vodafone-ip.de [88.152.145.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-1.canonical.com (Postfix) with ESMTPSA id 7635841F24; Sun, 4 Dec 2022 21:16:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1670188591; bh=R+WusgsQNibmvvQvvf04ZAUJ/Giyr5R0animKeQORCc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=wK0TRAqiKOQ6xGOQ9F74IHfhsZBXaSYVtMiRhF1eCdtuJN3INnxEhygmKuxf0x6DY q72E08caP+oS42GiJp5krrHEkde6/5X6Eo6sSypt/sSRKqqAP6b0gG1qiEwbDUBWiC dLjPGgIDuicPvBLXHeav3AweQAnSdIKb97XZeoswOsWY+0ctrchHaI4rD6cXyRI/QG TaVXyfOrSH435DPr2qMLSb3iCvkEEVt7QDWG0fM9t6njnILrSClQTLDOXP6lQrQ1A1 cr3XoTo9zU/IJPiBCS3B7T25pj6/UbJezZeMNq29diJsSxyEiNlOQwh82nMr1MY7jn iqOjKWWHlGgrw== From: Heinrich Schuchardt To: Simon Glass Cc: Andrew Scull , "R . Chandrasekar" , Minkyu Kang , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH v2 6/7] sound: add CONFIG_SOUND_SINE symbol Date: Sun, 4 Dec 2022 22:16:06 +0100 Message-Id: <20221204211607.227443-7-heinrich.schuchardt@canonical.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221204211607.227443-1-heinrich.schuchardt@canonical.com> References: <20221204211607.227443-1-heinrich.schuchardt@canonical.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Provide a configuration symbol to allow the sound command play a sine wave instead of a square wave. Signed-off-by: Heinrich Schuchardt --- v2: update documentation --- doc/usage/cmd/sound.rst | 3 +++ drivers/sound/Kconfig | 6 ++++++ drivers/sound/sound-uclass.c | 10 ++++++++-- test/dm/sound.c | 20 ++++++++++++-------- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/doc/usage/cmd/sound.rst b/doc/usage/cmd/sound.rst index d3fac243b1..aa988fa261 100644 --- a/doc/usage/cmd/sound.rst +++ b/doc/usage/cmd/sound.rst @@ -35,6 +35,9 @@ Configuration The sound command is enabled by CONFIG_CMD_SOUND=y. +By default a square wave is generated. With CONFIG_SOUND_SINE=y a sine wave is +used instead. + Return value ------------ diff --git a/drivers/sound/Kconfig b/drivers/sound/Kconfig index 0948d8caab..1005192fd4 100644 --- a/drivers/sound/Kconfig +++ b/drivers/sound/Kconfig @@ -12,6 +12,12 @@ config SOUND audio codecs are called from the sound-i2s code. This could be converted to driver model. +config SOUND_SINE + bool "Generate sine wave" + help + When this setting is enabled playing a sound produces a sine + wave. If the settings is not enabled, a square wave is produced. + config I2S bool "Enable I2S support" depends on SOUND diff --git a/drivers/sound/sound-uclass.c b/drivers/sound/sound-uclass.c index 2ffc4fc7c1..637f6b11ab 100644 --- a/drivers/sound/sound-uclass.c +++ b/drivers/sound/sound-uclass.c @@ -99,8 +99,14 @@ int sound_beep(struct udevice *dev, int msecs, int frequency_hz) return -ENOMEM; } - sound_create_square_wave(i2s_uc_priv->samplingrate, data, data_size, - frequency_hz, i2s_uc_priv->channels); + if (CONFIG_IS_ENABLED(SOUND_SINE)) + sound_create_sine_wave(i2s_uc_priv->samplingrate, data, + data_size, frequency_hz, + i2s_uc_priv->channels); + else + sound_create_square_wave(i2s_uc_priv->samplingrate, data, + data_size, frequency_hz, + i2s_uc_priv->channels); ret = 0; while (msecs >= 1000) { diff --git a/test/dm/sound.c b/test/dm/sound.c index 15d545ab5a..f16ea80157 100644 --- a/test/dm/sound.c +++ b/test/dm/sound.c @@ -17,6 +17,12 @@ static int dm_test_sound(struct unit_test_state *uts) { struct sound_uc_priv *uc_priv; struct udevice *dev; + int expected; + + if (CONFIG_IS_ENABLED(SOUND_SINE)) + expected = 3494; + else + expected = 4560; /* check probe success */ ut_assertok(uclass_first_device_err(UCLASS_SOUND, &dev)); @@ -24,24 +30,22 @@ static int dm_test_sound(struct unit_test_state *uts) ut_asserteq_str("audio-codec", uc_priv->codec->name); ut_asserteq_str("i2s", uc_priv->i2s->name); ut_asserteq(0, sandbox_get_setup_called(dev)); - ut_assertok(sound_beep(dev, 1, 100)); ut_asserteq(48, sandbox_get_sound_count(dev)); - ut_asserteq(4560, sandbox_get_sound_sum(dev)); + ut_asserteq(expected, sandbox_get_sound_sum(dev)); ut_assertok(sound_beep(dev, 1, 100)); ut_asserteq(96, sandbox_get_sound_count(dev)); - ut_asserteq(9120, sandbox_get_sound_sum(dev)); + expected *= 2; + ut_asserteq(expected, sandbox_get_sound_sum(dev)); ut_assertok(sound_beep(dev, 1, -100)); ut_asserteq(144, sandbox_get_sound_count(dev)); - ut_asserteq(9120, sandbox_get_sound_sum(dev)); + ut_asserteq(expected, sandbox_get_sound_sum(dev)); ut_assertok(sound_beep(dev, 1, 0)); ut_asserteq(192, sandbox_get_sound_count(dev)); - ut_asserteq(9120, sandbox_get_sound_sum(dev)); + ut_asserteq(expected, sandbox_get_sound_sum(dev)); ut_assertok(sound_beep(dev, 1, INT_MAX)); ut_asserteq(240, sandbox_get_sound_count(dev)); - ut_asserteq(9120, sandbox_get_sound_sum(dev)); - ut_asserteq(false, sandbox_get_sound_active(dev)); - + ut_asserteq(expected, sandbox_get_sound_sum(dev)); return 0; } DM_TEST(dm_test_sound, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); From patchwork Sun Dec 4 21:16:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1712105 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=nGzrmaFz; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NQKJz6b84z23ns for ; Mon, 5 Dec 2022 08:17:55 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 02AD88559D; Sun, 4 Dec 2022 22:16:54 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.b="nGzrmaFz"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F128D854BE; Sun, 4 Dec 2022 22:16:37 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from smtp-relay-canonical-1.canonical.com (smtp-relay-canonical-1.canonical.com [185.125.188.121]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D2D4B854BE for ; Sun, 4 Dec 2022 22:16:32 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=heinrich.schuchardt@canonical.com Received: from LT2ubnt.fritz.box (ip-088-152-145-137.um26.pools.vodafone-ip.de [88.152.145.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-1.canonical.com (Postfix) with ESMTPSA id EBEDE41F25; Sun, 4 Dec 2022 21:16:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1670188592; bh=7GqHL/5O1nN0BCzsJd7caFKZOgM/0NvDhVqbDqS/UgI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nGzrmaFzq76f8j+/KI24KMaAWXKpDglzhYEIcKye+LIdzNc1IPiBSkrcGpJfbVsbc A3E202rggH5paoSmslbJIxQC+BNScEgImJ3KDWL9wLt9xLMVOEtRDnweN7pLI5XT1Q zfYERDAeC4iEUNr6zQGws6958j3exQ0DntfQDmhCq7/ybcuiKDv2raQF8OHp7x2PoH mSJC5cWZvrGs39bOnCgIteooG2Db69r30XHc4ckgtzDoTOf+kGfJ7YSZT7zIHKhaib AP3uema7nR/VoHK8zXh0Xs4FZnMV47SoEPrAIpPHP2MN+iYYpo0xgnAAu6LF/gy9nS q9scM+MdmPtzA== From: Heinrich Schuchardt To: Simon Glass Cc: Andrew Scull , "R . Chandrasekar" , Minkyu Kang , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH v2 7/7] sandbox: fix sound driver Date: Sun, 4 Dec 2022 22:16:07 +0100 Message-Id: <20221204211607.227443-8-heinrich.schuchardt@canonical.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221204211607.227443-1-heinrich.schuchardt@canonical.com> References: <20221204211607.227443-1-heinrich.schuchardt@canonical.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean In the callback function we have to use memcpy(). Otherwise we add the new samples on top of what is stored in the stream buffer. If we don't have enough data, zero out the rest of the stream buffer. Our sampling frequency is 48000. Let the batch size for the callback function be 960. If we play a multiple of 20 ms, this will always be a full batch. Signed-off-by: Heinrich Schuchardt --- v2: no change --- arch/sandbox/cpu/sdl.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/arch/sandbox/cpu/sdl.c b/arch/sandbox/cpu/sdl.c index f4ca36b35c..2c570ed8d1 100644 --- a/arch/sandbox/cpu/sdl.c +++ b/arch/sandbox/cpu/sdl.c @@ -441,7 +441,6 @@ void sandbox_sdl_fill_audio(void *udata, Uint8 *stream, int len) { struct buf_info *buf; int avail; - bool have_data = false; int i; for (i = 0; i < 2; i++) { @@ -453,10 +452,9 @@ void sandbox_sdl_fill_audio(void *udata, Uint8 *stream, int len) } if (avail > len) avail = len; - have_data = true; - SDL_MixAudio(stream, buf->data + buf->pos, avail, - SDL_MIX_MAXVOLUME); + memcpy(stream, buf->data + buf->pos, avail); + stream += avail; buf->pos += avail; len -= avail; @@ -466,7 +464,8 @@ void sandbox_sdl_fill_audio(void *udata, Uint8 *stream, int len) else break; } - sdl.stopping = !have_data; + memset(stream, 0, len); + sdl.stopping = !!len; } int sandbox_sdl_sound_init(int rate, int channels) @@ -484,7 +483,7 @@ int sandbox_sdl_sound_init(int rate, int channels) wanted.freq = rate; wanted.format = AUDIO_S16; wanted.channels = channels; - wanted.samples = 1024; /* Good low-latency value for callback */ + wanted.samples = 960; /* Good low-latency value for callback */ wanted.callback = sandbox_sdl_fill_audio; wanted.userdata = NULL;