From patchwork Mon Mar 2 19:10:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Volker_R=C3=BCmelin?= X-Patchwork-Id: 1247855 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=t-online.de Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48WV903rBKz9sPk for ; Tue, 3 Mar 2020 06:10:44 +1100 (AEDT) Received: from localhost ([::1]:37492 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j8qSg-0003wL-GT for incoming@patchwork.ozlabs.org; Mon, 02 Mar 2020 14:10:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53297) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j8qSD-0003uG-Ky for qemu-devel@nongnu.org; Mon, 02 Mar 2020 14:10:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j8qSC-0005Bn-Mu for qemu-devel@nongnu.org; Mon, 02 Mar 2020 14:10:13 -0500 Received: from mailout07.t-online.de ([194.25.134.83]:44184) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j8qSC-0005AY-Go for qemu-devel@nongnu.org; Mon, 02 Mar 2020 14:10:12 -0500 Received: from fwd23.aul.t-online.de (fwd23.aul.t-online.de [172.20.26.128]) by mailout07.t-online.de (Postfix) with SMTP id 767C8427E86E; Mon, 2 Mar 2020 20:10:11 +0100 (CET) Received: from linpower.localnet (Xdk530ZQoh8p3nyv3xgLOkINTMMFTH42yTQ-rNBGAz1auuFzwm2tdirH8FYbegQZML@[79.208.28.226]) by fwd23.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1j8qS5-2DuZm40; Mon, 2 Mar 2020 20:10:05 +0100 Received: by linpower.localnet (Postfix, from userid 1000) id 8D56D21159C; Mon, 2 Mar 2020 20:10:04 +0100 (CET) From: =?utf-8?q?Volker_R=C3=BCmelin?= To: Gerd Hoffmann , Eric Blake , Markus Armbruster Subject: [PATCH 1/5] qapi/audio: add documentation for AudioFormat Date: Mon, 2 Mar 2020 20:10:00 +0100 Message-Id: <20200302191004.5991-1-vr_qemu@t-online.de> X-Mailer: git-send-email 2.16.4 In-Reply-To: <417bfe2f-e3c1-d83d-b437-47859daf524d@t-online.de> References: <417bfe2f-e3c1-d83d-b437-47859daf524d@t-online.de> MIME-Version: 1.0 X-ID: Xdk530ZQoh8p3nyv3xgLOkINTMMFTH42yTQ-rNBGAz1auuFzwm2tdirH8FYbegQZML X-TOI-MSGID: 8435a86c-6486-416a-827f-2ae85c1f8bb7 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 194.25.134.83 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Arbuckle , Howard Spoelstra , Mark Cave-Ayland , QEMU , =?utf-8?b?Wm9sdMOhbiBLxZF2w6Fnw7M=?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The review for patch ed2a4a7941 "audio: proper support for float samples in mixeng" suggested this would be a good idea. Signed-off-by: Volker Rümelin Acked-by: Markus Armbruster --- qapi/audio.json | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/qapi/audio.json b/qapi/audio.json index d8c507cced..07e7b05516 100644 --- a/qapi/audio.json +++ b/qapi/audio.json @@ -273,6 +273,20 @@ # # An enumeration of possible audio formats. # +# @u8: unsigned 8 bit integer +# +# @s8: signed 8 bit integer +# +# @u16: unsigned 16 bit integer +# +# @s16: signed 16 bit integer +# +# @u32: unsigned 32 bit integer +# +# @s32: signed 32 bit integer +# +# @f32: single precision floating point (since 5.0) +# # Since: 4.0 ## { 'enum': 'AudioFormat', From patchwork Mon Mar 2 19:10:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Volker_R=C3=BCmelin?= X-Patchwork-Id: 1247854 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=t-online.de Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48WV8y0ptgz9sPK for ; Tue, 3 Mar 2020 06:10:42 +1100 (AEDT) Received: from localhost ([::1]:37490 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j8qSe-0003uW-1f for incoming@patchwork.ozlabs.org; Mon, 02 Mar 2020 14:10:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53277) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j8qSB-0003u8-Gm for qemu-devel@nongnu.org; Mon, 02 Mar 2020 14:10:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j8qSA-00055f-Bo for qemu-devel@nongnu.org; Mon, 02 Mar 2020 14:10:11 -0500 Received: from mailout07.t-online.de ([194.25.134.83]:44108) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j8qSA-00053z-2C for qemu-devel@nongnu.org; Mon, 02 Mar 2020 14:10:10 -0500 Received: from fwd39.aul.t-online.de (fwd39.aul.t-online.de [172.20.27.138]) by mailout07.t-online.de (Postfix) with SMTP id 0F1F64208573; Mon, 2 Mar 2020 20:10:08 +0100 (CET) Received: from linpower.localnet (VrkvCqZD8hyB-IEMgR48tQuEVgo1weNMjBmBCsLt-LroYYO8PNszmY4LkMXsVpHZpD@[79.208.28.226]) by fwd39.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1j8qS7-0YCO7k0; Mon, 2 Mar 2020 20:10:07 +0100 Received: by linpower.localnet (Postfix, from userid 1000) id 8F8FF21159F; Mon, 2 Mar 2020 20:10:04 +0100 (CET) From: =?utf-8?q?Volker_R=C3=BCmelin?= To: Gerd Hoffmann , Eric Blake , Markus Armbruster Subject: [PATCH 2/5] audio: change naming scheme of FLOAT_CONV macros Date: Mon, 2 Mar 2020 20:10:01 +0100 Message-Id: <20200302191004.5991-2-vr_qemu@t-online.de> X-Mailer: git-send-email 2.16.4 In-Reply-To: <417bfe2f-e3c1-d83d-b437-47859daf524d@t-online.de> References: <417bfe2f-e3c1-d83d-b437-47859daf524d@t-online.de> MIME-Version: 1.0 X-ID: VrkvCqZD8hyB-IEMgR48tQuEVgo1weNMjBmBCsLt-LroYYO8PNszmY4LkMXsVpHZpD X-TOI-MSGID: ec45cee6-a315-48ed-a0b1-934a4e997b18 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 194.25.134.83 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Arbuckle , Howard Spoelstra , Mark Cave-Ayland , QEMU , =?utf-8?b?Wm9sdMOhbiBLxZF2w6Fnw7M=?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This patch changes the naming scheme of the FLOAT_CONV_TO and FLOAT_CONV_FROM macros to the scheme used in mixeng_template.h. Signed-off-by: Volker Rümelin --- audio/mixeng.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/audio/mixeng.c b/audio/mixeng.c index c14b0d874c..b57fad83bf 100644 --- a/audio/mixeng.c +++ b/audio/mixeng.c @@ -268,17 +268,17 @@ f_sample *mixeng_clip[2][2][2][3] = { }; #ifdef FLOAT_MIXENG -#define FLOAT_CONV_TO(x) (x) -#define FLOAT_CONV_FROM(x) (x) +#define CONV_NATURAL_FLOAT(x) (x) +#define CLIP_NATURAL_FLOAT(x) (x) #else static const float float_scale = UINT_MAX; -#define FLOAT_CONV_TO(x) ((x) * float_scale) +#define CONV_NATURAL_FLOAT(x) ((x) * float_scale) #ifdef RECIPROCAL static const float float_scale_reciprocal = 1.f / UINT_MAX; -#define FLOAT_CONV_FROM(x) ((x) * float_scale_reciprocal) +#define CLIP_NATURAL_FLOAT(x) ((x) * float_scale_reciprocal) #else -#define FLOAT_CONV_FROM(x) ((x) / float_scale) +#define CLIP_NATURAL_FLOAT(x) ((x) / float_scale) #endif #endif @@ -288,7 +288,7 @@ static void conv_natural_float_to_mono(struct st_sample *dst, const void *src, float *in = (float *)src; while (samples--) { - dst->r = dst->l = FLOAT_CONV_TO(*in++); + dst->r = dst->l = CONV_NATURAL_FLOAT(*in++); dst++; } } @@ -299,8 +299,8 @@ static void conv_natural_float_to_stereo(struct st_sample *dst, const void *src, float *in = (float *)src; while (samples--) { - dst->l = FLOAT_CONV_TO(*in++); - dst->r = FLOAT_CONV_TO(*in++); + dst->l = CONV_NATURAL_FLOAT(*in++); + dst->r = CONV_NATURAL_FLOAT(*in++); dst++; } } @@ -316,7 +316,7 @@ static void clip_natural_float_from_mono(void *dst, const struct st_sample *src, float *out = (float *)dst; while (samples--) { - *out++ = FLOAT_CONV_FROM(src->l) + FLOAT_CONV_FROM(src->r); + *out++ = CLIP_NATURAL_FLOAT(src->l) + CLIP_NATURAL_FLOAT(src->r); src++; } } @@ -327,8 +327,8 @@ static void clip_natural_float_from_stereo( float *out = (float *)dst; while (samples--) { - *out++ = FLOAT_CONV_FROM(src->l); - *out++ = FLOAT_CONV_FROM(src->r); + *out++ = CLIP_NATURAL_FLOAT(src->l); + *out++ = CLIP_NATURAL_FLOAT(src->r); src++; } } From patchwork Mon Mar 2 19:10:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Volker_R=C3=BCmelin?= X-Patchwork-Id: 1247857 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=t-online.de Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48WVBt43h5z9sPK for ; Tue, 3 Mar 2020 06:12:22 +1100 (AEDT) Received: from localhost ([::1]:37522 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j8qUF-0006XJ-Ru for incoming@patchwork.ozlabs.org; Mon, 02 Mar 2020 14:12:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53360) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j8qSI-0003vB-EP for qemu-devel@nongnu.org; Mon, 02 Mar 2020 14:10:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j8qSH-0005Gj-FC for qemu-devel@nongnu.org; Mon, 02 Mar 2020 14:10:18 -0500 Received: from mailout04.t-online.de ([194.25.134.18]:45714) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j8qSH-0005Ex-8t for qemu-devel@nongnu.org; Mon, 02 Mar 2020 14:10:17 -0500 Received: from fwd24.aul.t-online.de (fwd24.aul.t-online.de [172.20.26.129]) by mailout04.t-online.de (Postfix) with SMTP id D70FE41FE4B1; Mon, 2 Mar 2020 20:10:15 +0100 (CET) Received: from linpower.localnet (JO0NbqZUghBncFwrVZOZcq8S8rgE5SI7sQyfrCrv5rMj+y2ddSFvFUlCGUDY4TvZKF@[79.208.28.226]) by fwd24.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1j8qSA-0GSSUi0; Mon, 2 Mar 2020 20:10:10 +0100 Received: by linpower.localnet (Postfix, from userid 1000) id 906E221B1C0; Mon, 2 Mar 2020 20:10:04 +0100 (CET) From: =?utf-8?q?Volker_R=C3=BCmelin?= To: Gerd Hoffmann , Eric Blake , Markus Armbruster Subject: [PATCH 3/5] audio: consistency changes Date: Mon, 2 Mar 2020 20:10:02 +0100 Message-Id: <20200302191004.5991-3-vr_qemu@t-online.de> X-Mailer: git-send-email 2.16.4 In-Reply-To: <417bfe2f-e3c1-d83d-b437-47859daf524d@t-online.de> References: <417bfe2f-e3c1-d83d-b437-47859daf524d@t-online.de> MIME-Version: 1.0 X-ID: JO0NbqZUghBncFwrVZOZcq8S8rgE5SI7sQyfrCrv5rMj+y2ddSFvFUlCGUDY4TvZKF X-TOI-MSGID: df0916cc-babe-4635-b357-2682298f46c3 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 194.25.134.18 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Arbuckle , Howard Spoelstra , Mark Cave-Ayland , QEMU , =?utf-8?b?Wm9sdMOhbiBLxZF2w6Fnw7M=?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Change the clip_natural_float_from_mono() function in audio/mixeng.c to be consistent with the clip_*_from_mono() functions in audio/mixeng_template.h. Signed-off-by: Volker Rümelin --- audio/mixeng.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/audio/mixeng.c b/audio/mixeng.c index b57fad83bf..725b529be7 100644 --- a/audio/mixeng.c +++ b/audio/mixeng.c @@ -316,7 +316,7 @@ static void clip_natural_float_from_mono(void *dst, const struct st_sample *src, float *out = (float *)dst; while (samples--) { - *out++ = CLIP_NATURAL_FLOAT(src->l) + CLIP_NATURAL_FLOAT(src->r); + *out++ = CLIP_NATURAL_FLOAT(src->l + src->r); src++; } } From patchwork Mon Mar 2 19:10:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Volker_R=C3=BCmelin?= X-Patchwork-Id: 1247856 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=t-online.de Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48WV944vJNz9sR4 for ; Tue, 3 Mar 2020 06:10:48 +1100 (AEDT) Received: from localhost ([::1]:37495 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j8qSk-00043Q-JR for incoming@patchwork.ozlabs.org; Mon, 02 Mar 2020 14:10:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53327) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j8qSF-0003uO-Ts for qemu-devel@nongnu.org; Mon, 02 Mar 2020 14:10:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j8qSE-0005Dl-QL for qemu-devel@nongnu.org; Mon, 02 Mar 2020 14:10:15 -0500 Received: from mailout03.t-online.de ([194.25.134.81]:60778) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j8qSE-0005CS-H1 for qemu-devel@nongnu.org; Mon, 02 Mar 2020 14:10:14 -0500 Received: from fwd22.aul.t-online.de (fwd22.aul.t-online.de [172.20.26.127]) by mailout03.t-online.de (Postfix) with SMTP id 36781426B9B2; Mon, 2 Mar 2020 20:10:13 +0100 (CET) Received: from linpower.localnet (rIEZI0ZOghWyWs2u3cQe5csDoTzsaBhI8B1A8xWxz3Cnj4RhM-3q-IPwq1dLH5PZB3@[79.208.28.226]) by fwd22.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1j8qSD-0p8owy0; Mon, 2 Mar 2020 20:10:13 +0100 Received: by linpower.localnet (Postfix, from userid 1000) id 9243D21B1C1; Mon, 2 Mar 2020 20:10:04 +0100 (CET) From: =?utf-8?q?Volker_R=C3=BCmelin?= To: Gerd Hoffmann , Eric Blake , Markus Armbruster Subject: [PATCH 4/5] audio: change mixing engine float range to [-1.f, 1.f] Date: Mon, 2 Mar 2020 20:10:03 +0100 Message-Id: <20200302191004.5991-4-vr_qemu@t-online.de> X-Mailer: git-send-email 2.16.4 In-Reply-To: <417bfe2f-e3c1-d83d-b437-47859daf524d@t-online.de> References: <417bfe2f-e3c1-d83d-b437-47859daf524d@t-online.de> MIME-Version: 1.0 X-ID: rIEZI0ZOghWyWs2u3cQe5csDoTzsaBhI8B1A8xWxz3Cnj4RhM-3q-IPwq1dLH5PZB3 X-TOI-MSGID: a79074d3-7e36-4398-93cf-7fc015258cbd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 194.25.134.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Arbuckle , Howard Spoelstra , Mark Cave-Ayland , QEMU , =?utf-8?b?Wm9sdMOhbiBLxZF2w6Fnw7M=?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Currently the internal float range of the mixing engine is [-.5f, .5f]. PulseAudio, SDL2 and libasound use a [-1.f, 1.f] range. This means with float samples the audio playback volume is 6dB too low and audio recording signals will be clipped in most cases. To avoid another scaling factor in the conv_natural_float_* and clip_natural_float_* functions with FLOAT_MIXENG defined this patch changes the mixing engine float range to [-1.f, 1.f]. Signed-off-by: Volker Rümelin --- audio/mixeng.c | 4 ++-- audio/mixeng_template.h | 17 ++++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/audio/mixeng.c b/audio/mixeng.c index 725b529be7..739a500449 100644 --- a/audio/mixeng.c +++ b/audio/mixeng.c @@ -271,11 +271,11 @@ f_sample *mixeng_clip[2][2][2][3] = { #define CONV_NATURAL_FLOAT(x) (x) #define CLIP_NATURAL_FLOAT(x) (x) #else -static const float float_scale = UINT_MAX; +static const float float_scale = UINT_MAX / 2.f; #define CONV_NATURAL_FLOAT(x) ((x) * float_scale) #ifdef RECIPROCAL -static const float float_scale_reciprocal = 1.f / UINT_MAX; +static const float float_scale_reciprocal = 2.f / UINT_MAX; #define CLIP_NATURAL_FLOAT(x) ((x) * float_scale_reciprocal) #else #define CLIP_NATURAL_FLOAT(x) ((x) / float_scale) diff --git a/audio/mixeng_template.h b/audio/mixeng_template.h index 77cc89b9e8..fc8e1d4d9e 100644 --- a/audio/mixeng_template.h +++ b/audio/mixeng_template.h @@ -41,32 +41,31 @@ static inline mixeng_real glue (conv_, ET) (IN_T v) #ifdef RECIPROCAL #ifdef SIGNED - return nv * (1.f / (mixeng_real) (IN_MAX - IN_MIN)); + return nv * (2.f / ((mixeng_real)IN_MAX - IN_MIN)); #else - return (nv - HALF) * (1.f / (mixeng_real) IN_MAX); + return (nv - HALF) * (2.f / (mixeng_real)IN_MAX); #endif #else /* !RECIPROCAL */ #ifdef SIGNED - return nv / (mixeng_real) ((mixeng_real) IN_MAX - IN_MIN); + return nv / (((mixeng_real)IN_MAX - IN_MIN) / 2.f); #else - return (nv - HALF) / (mixeng_real) IN_MAX; + return (nv - HALF) / ((mixeng_real)IN_MAX / 2.f); #endif #endif } static inline IN_T glue (clip_, ET) (mixeng_real v) { - if (v >= 0.5) { + if (v >= 1.f) { return IN_MAX; - } - else if (v < -0.5) { + } else if (v < -1.f) { return IN_MIN; } #ifdef SIGNED - return ENDIAN_CONVERT ((IN_T) (v * ((mixeng_real) IN_MAX - IN_MIN))); + return ENDIAN_CONVERT((IN_T)(v * (((mixeng_real)IN_MAX - IN_MIN) / 2.f))); #else - return ENDIAN_CONVERT ((IN_T) ((v * IN_MAX) + HALF)); + return ENDIAN_CONVERT((IN_T)((v * ((mixeng_real)IN_MAX / 2.f)) + HALF)); #endif } From patchwork Mon Mar 2 19:10:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Volker_R=C3=BCmelin?= X-Patchwork-Id: 1247858 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=t-online.de Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48WVBt6ZN5z9sPk for ; Tue, 3 Mar 2020 06:12:22 +1100 (AEDT) Received: from localhost ([::1]:37526 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j8qUG-0006ai-RF for incoming@patchwork.ozlabs.org; Mon, 02 Mar 2020 14:12:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53347) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j8qSH-0003uY-Qh for qemu-devel@nongnu.org; Mon, 02 Mar 2020 14:10:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j8qSG-0005Fm-Rl for qemu-devel@nongnu.org; Mon, 02 Mar 2020 14:10:17 -0500 Received: from mailout01.t-online.de ([194.25.134.80]:48544) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j8qSG-0005Er-LG for qemu-devel@nongnu.org; Mon, 02 Mar 2020 14:10:16 -0500 Received: from fwd02.aul.t-online.de (fwd02.aul.t-online.de [172.20.26.148]) by mailout01.t-online.de (Postfix) with SMTP id C08C3421E456; Mon, 2 Mar 2020 20:10:15 +0100 (CET) Received: from linpower.localnet (r44a3+ZUYh1HEwfogxLXoOS8jYkKsHoyDYbDBU25v+w2CCzIul-DdxdwLPlrojDght@[79.208.28.226]) by fwd02.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1j8qSF-03bHiC0; Mon, 2 Mar 2020 20:10:15 +0100 Received: by linpower.localnet (Postfix, from userid 1000) id 9473621B1C2; Mon, 2 Mar 2020 20:10:04 +0100 (CET) From: =?utf-8?q?Volker_R=C3=BCmelin?= To: Gerd Hoffmann , Eric Blake , Markus Armbruster Subject: [PATCH 5/5] audio: fix saturation nonlinearity in clip_* functions Date: Mon, 2 Mar 2020 20:10:04 +0100 Message-Id: <20200302191004.5991-5-vr_qemu@t-online.de> X-Mailer: git-send-email 2.16.4 In-Reply-To: <417bfe2f-e3c1-d83d-b437-47859daf524d@t-online.de> References: <417bfe2f-e3c1-d83d-b437-47859daf524d@t-online.de> MIME-Version: 1.0 X-ID: r44a3+ZUYh1HEwfogxLXoOS8jYkKsHoyDYbDBU25v+w2CCzIul-DdxdwLPlrojDght X-TOI-MSGID: 2c7527be-66b1-4209-a59d-a0184378cd26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 194.25.134.80 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Arbuckle , Howard Spoelstra , Mark Cave-Ayland , QEMU , =?utf-8?b?Wm9sdMOhbiBLxZF2w6Fnw7M=?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The current positive limit for the saturation nonlinearity is only correct if the type of the result has 8 bits or less. Signed-off-by: Volker Rümelin --- audio/mixeng_template.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/audio/mixeng_template.h b/audio/mixeng_template.h index fc8e1d4d9e..bc8509e423 100644 --- a/audio/mixeng_template.h +++ b/audio/mixeng_template.h @@ -83,10 +83,9 @@ static inline int64_t glue (conv_, ET) (IN_T v) static inline IN_T glue (clip_, ET) (int64_t v) { - if (v >= 0x7f000000) { + if (v >= 0x7fffffffLL) { return IN_MAX; - } - else if (v < -2147483648LL) { + } else if (v < -2147483648LL) { return IN_MIN; }