From nobody Mon Feb 9 10:57:19 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1570997112; cv=none; d=zoho.com; s=zohoarc; b=IvlBitBHWB71BH667Q3F7urnQ5ZbMGz8oAtjYxUZT6hXK8i4SlsPW0POnoascd1WZgdMKS0UACaswokRuX3OKA8Y5887H80HMTLivz8g8wEQdhDP4THZaiA8TECpwJsVlJ/MVIhCcJgN31lnwnxbT8IcituAFEl2QNPzxQYWC+A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570997112; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hBNbSNYdRxpi4YPwJzeBrQcOF4eLYJl4drOoaIZgmh0=; b=SX9vFs2NkzxHcU+kNDD2Au+ylG4WchySgXeyzx03/D/kDftizc9BI5KND9DY2ReJ8IKw/y6RksAb00jIvWwokEKWrsIZbhRr7ALtWnpLvhBqfmT11uZJyHAR6cvJKJgyhiJbJX3MsYRXx5JC2MJeRgELIcCf8VxFBVsM2UZsT4M= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1570997112645989.2595860188079; Sun, 13 Oct 2019 13:05:12 -0700 (PDT) Received: from localhost ([::1]:42034 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJk75-0002Rn-48 for importer@patchew.org; Sun, 13 Oct 2019 16:05:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37248) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJk0M-0005SA-Qf for qemu-devel@nongnu.org; Sun, 13 Oct 2019 15:58:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iJk0L-0003Fe-3N for qemu-devel@nongnu.org; Sun, 13 Oct 2019 15:58:14 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:35719) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iJk0K-0003EN-T4 for qemu-devel@nongnu.org; Sun, 13 Oct 2019 15:58:13 -0400 Received: by mail-wr1-x443.google.com with SMTP id v8so17255140wrt.2 for ; Sun, 13 Oct 2019 12:58:12 -0700 (PDT) Received: from nullptr.home.dirty-ice.org (2a01-036c-0113-0052-0000-0000-0000-0005.pool6.digikabel.hu. [2a01:36c:113:52::5]) by smtp.gmail.com with ESMTPSA id x129sm29941857wmg.8.2019.10.13.12.58.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Oct 2019 12:58:11 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=hBNbSNYdRxpi4YPwJzeBrQcOF4eLYJl4drOoaIZgmh0=; b=PBXdWNFzUkyjmNRugR4G7C1VODFBO7+giz6OiOV1A8WqaqZ+gkZURKZAZwutTB9AwO bJAhLA33EFucfYVEGhltwwyhI2PV7Vi0gkeD3ZN5D1Egf7iY80EOY7kOJidsctufM3/w /JmhwlkyO9G1EVkdaY3fj8dBeYhaxl/7qXdEFbnUGupmc1xKTDJnc7iEkI/CyJccbUKR PKJFGRBuNDa8fjBkJdc11eGJUajRaUqyIfx2FWV72PWzLvMXYdskUELeMck5nyRj3aq2 TXV7ggi4T69HuQFdcJa3SyX245bJ5kXogROib+oMHB2Uwe8yHbpCCcxUScXiFODULj/n 19xA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=hBNbSNYdRxpi4YPwJzeBrQcOF4eLYJl4drOoaIZgmh0=; b=jPl8ja4QVeE77RTMPQRPJcEvgICJe2nR79OrQqX4LKMIfRVDi79pCkD6aZB+raD0lq cM+u9Fhm78n3IWPUylgAuCboSGWp46WCnUH+olumnQlcpqwe5/KRZinQ5hLnXuOvjN4i SRYuLfV2Q/hNu/QjN7qp/TUeZ9NYPaVsiaYWAYOYVWwa3Wp97sG8Gdj84WrmvsjD/FaV CDRNWVNkzNxgKYREZu2OMyS/evXGRSTrb9LG4xTnHb6l02wK1Zp/22/5Unn9/RDUc0DP g96hD0KLBf6ldDk/IkgJW8RbGNiAx5DKhHi3dxOfn3ocYWLFb5WbDp84WbwQR4eJ6LTa UiLg== X-Gm-Message-State: APjAAAV1ZBxtSyT5LPbDIZ/t4D9EuAwK09yLcCi17iRQ9hFTbHqXX9nE QhwMreD5PDsA1+YSNcAPjoubfNIm X-Google-Smtp-Source: APXvYqx2kLo+WBVKqnH2TfDqWEWdI1mVAl91yNb8ALMatjo8Wfg4NGpjODZ88S1YWaAcKuYHag2V+g== X-Received: by 2002:a5d:420c:: with SMTP id n12mr22103076wrq.85.1570996691684; Sun, 13 Oct 2019 12:58:11 -0700 (PDT) From: "=?UTF-8?q?K=C5=91v=C3=A1g=C3=B3=2C=20Zolt=C3=A1n?=" X-Google-Original-From: =?UTF-8?q?K=C5=91v=C3=A1g=C3=B3=2C=20Zolt=C3=A1n?= To: qemu-devel@nongnu.org Subject: [PATCH v6 04/10] audio: support more than two channels in volume setting Date: Sun, 13 Oct 2019 21:58:01 +0200 Message-Id: <5d3dd2ee3baaa62805e79c3901abb7415ae32461.1570996490.git.DirtY.iCE.hu@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::443 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: Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) Signed-off-by: K=C5=91v=C3=A1g=C3=B3, Zolt=C3=A1n --- audio/audio.c | 30 ++++++++++++++++++++++-------- audio/audio.h | 10 ++++++++++ audio/audio_int.h | 4 ++-- audio/paaudio.c | 20 ++++++++++++-------- audio/spiceaudio.c | 14 ++++++++------ 5 files changed, 54 insertions(+), 24 deletions(-) diff --git a/audio/audio.c b/audio/audio.c index d616a4af98..f1c145dfcd 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -1891,31 +1891,45 @@ void AUD_del_capture (CaptureVoiceOut *cap, void *c= b_opaque) } =20 void AUD_set_volume_out (SWVoiceOut *sw, int mute, uint8_t lvol, uint8_t r= vol) +{ + Volume vol =3D { .mute =3D mute, .channels =3D 2, .vol =3D { lvol, rvo= l } }; + audio_set_volume_out(sw, &vol); +} + +void audio_set_volume_out(SWVoiceOut *sw, Volume *vol) { if (sw) { HWVoiceOut *hw =3D sw->hw; =20 - sw->vol.mute =3D mute; - sw->vol.l =3D nominal_volume.l * lvol / 255; - sw->vol.r =3D nominal_volume.r * rvol / 255; + sw->vol.mute =3D vol->mute; + sw->vol.l =3D nominal_volume.l * vol->vol[0] / 255; + sw->vol.r =3D nominal_volume.l * vol->vol[vol->channels > 1 ? 1 : = 0] / + 255; =20 if (hw->pcm_ops->volume_out) { - hw->pcm_ops->volume_out(hw, &sw->vol); + hw->pcm_ops->volume_out(hw, vol); } } } =20 void AUD_set_volume_in (SWVoiceIn *sw, int mute, uint8_t lvol, uint8_t rvo= l) +{ + Volume vol =3D { .mute =3D mute, .channels =3D 2, .vol =3D { lvol, rvo= l } }; + audio_set_volume_in(sw, &vol); +} + +void audio_set_volume_in(SWVoiceIn *sw, Volume *vol) { if (sw) { HWVoiceIn *hw =3D sw->hw; =20 - sw->vol.mute =3D mute; - sw->vol.l =3D nominal_volume.l * lvol / 255; - sw->vol.r =3D nominal_volume.r * rvol / 255; + sw->vol.mute =3D vol->mute; + sw->vol.l =3D nominal_volume.l * vol->vol[0] / 255; + sw->vol.r =3D nominal_volume.r * vol->vol[vol->channels > 1 ? 1 : = 0] / + 255; =20 if (hw->pcm_ops->volume_in) { - hw->pcm_ops->volume_in(hw, &sw->vol); + hw->pcm_ops->volume_in(hw, vol); } } } diff --git a/audio/audio.h b/audio/audio.h index c74abb8c47..0db3c7dd5e 100644 --- a/audio/audio.h +++ b/audio/audio.h @@ -124,6 +124,16 @@ uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEM= UAudioTimeStamp *ts); void AUD_set_volume_out (SWVoiceOut *sw, int mute, uint8_t lvol, uint8_t r= vol); void AUD_set_volume_in (SWVoiceIn *sw, int mute, uint8_t lvol, uint8_t rvo= l); =20 +#define AUDIO_MAX_CHANNELS 16 +typedef struct Volume { + bool mute; + int channels; + uint8_t vol[AUDIO_MAX_CHANNELS]; +} Volume; + +void audio_set_volume_out(SWVoiceOut *sw, Volume *vol); +void audio_set_volume_in(SWVoiceIn *sw, Volume *vol); + SWVoiceIn *AUD_open_in ( QEMUSoundCard *card, SWVoiceIn *sw, diff --git a/audio/audio_int.h b/audio/audio_int.h index 22a703c13e..9176db249b 100644 --- a/audio/audio_int.h +++ b/audio/audio_int.h @@ -166,7 +166,7 @@ struct audio_pcm_ops { */ size_t (*put_buffer_out)(HWVoiceOut *hw, void *buf, size_t size); void (*enable_out)(HWVoiceOut *hw, bool enable); - void (*volume_out)(HWVoiceOut *hw, struct mixeng_volume *vol); + void (*volume_out)(HWVoiceOut *hw, Volume *vol); =20 int (*init_in) (HWVoiceIn *hw, audsettings *as, void *drv_opaque); void (*fini_in) (HWVoiceIn *hw); @@ -174,7 +174,7 @@ struct audio_pcm_ops { void *(*get_buffer_in)(HWVoiceIn *hw, size_t *size); void (*put_buffer_in)(HWVoiceIn *hw, void *buf, size_t size); void (*enable_in)(HWVoiceIn *hw, bool enable); - void (*volume_in)(HWVoiceIn *hw, struct mixeng_volume *vol); + void (*volume_in)(HWVoiceIn *hw, Volume *vol); }; =20 void *audio_generic_get_buffer_in(HWVoiceIn *hw, size_t *size); diff --git a/audio/paaudio.c b/audio/paaudio.c index 6ccdf31415..d195b1caa8 100644 --- a/audio/paaudio.c +++ b/audio/paaudio.c @@ -531,20 +531,22 @@ static void qpa_fini_in (HWVoiceIn *hw) } } =20 -static void qpa_volume_out(HWVoiceOut *hw, struct mixeng_volume *vol) +static void qpa_volume_out(HWVoiceOut *hw, Volume *vol) { PAVoiceOut *pa =3D (PAVoiceOut *) hw; pa_operation *op; pa_cvolume v; PAConnection *c =3D pa->g->conn; + int i; =20 #ifdef PA_CHECK_VERSION /* macro is present in 0.9.16+ */ pa_cvolume_init (&v); /* function is present in 0.9.13+ */ #endif =20 - v.channels =3D 2; - v.values[0] =3D ((PA_VOLUME_NORM - PA_VOLUME_MUTED) * vol->l) / UINT32= _MAX; - v.values[1] =3D ((PA_VOLUME_NORM - PA_VOLUME_MUTED) * vol->r) / UINT32= _MAX; + v.channels =3D vol->channels; + for (i =3D 0; i < vol->channels; ++i) { + v.values[i] =3D ((PA_VOLUME_NORM - PA_VOLUME_MUTED) * vol->vol[i])= / 255; + } =20 pa_threaded_mainloop_lock(c->mainloop); =20 @@ -571,20 +573,22 @@ static void qpa_volume_out(HWVoiceOut *hw, struct mix= eng_volume *vol) pa_threaded_mainloop_unlock(c->mainloop); } =20 -static void qpa_volume_in(HWVoiceIn *hw, struct mixeng_volume *vol) +static void qpa_volume_in(HWVoiceIn *hw, Volume *vol) { PAVoiceIn *pa =3D (PAVoiceIn *) hw; pa_operation *op; pa_cvolume v; PAConnection *c =3D pa->g->conn; + int i; =20 #ifdef PA_CHECK_VERSION pa_cvolume_init (&v); #endif =20 - v.channels =3D 2; - v.values[0] =3D ((PA_VOLUME_NORM - PA_VOLUME_MUTED) * vol->l) / UINT32= _MAX; - v.values[1] =3D ((PA_VOLUME_NORM - PA_VOLUME_MUTED) * vol->r) / UINT32= _MAX; + v.channels =3D vol->channels; + for (i =3D 0; i < vol->channels; ++i) { + v.values[i] =3D ((PA_VOLUME_NORM - PA_VOLUME_MUTED) * vol->vol[i])= / 255; + } =20 pa_threaded_mainloop_lock(c->mainloop); =20 diff --git a/audio/spiceaudio.c b/audio/spiceaudio.c index 9860f9c5e1..6ed7f7a79e 100644 --- a/audio/spiceaudio.c +++ b/audio/spiceaudio.c @@ -179,13 +179,14 @@ static void line_out_enable(HWVoiceOut *hw, bool enab= le) } =20 #if ((SPICE_INTERFACE_PLAYBACK_MAJOR >=3D 1) && (SPICE_INTERFACE_PLAYBACK_= MINOR >=3D 2)) -static void line_out_volume(HWVoiceOut *hw, struct mixeng_volume *vol) +static void line_out_volume(HWVoiceOut *hw, Volume *vol) { SpiceVoiceOut *out =3D container_of(hw, SpiceVoiceOut, hw); uint16_t svol[2]; =20 - svol[0] =3D vol->l / ((1ULL << 16) + 1); - svol[1] =3D vol->r / ((1ULL << 16) + 1); + assert(vol->channels =3D=3D 2); + svol[0] =3D vol->vol[0] * 257; + svol[1] =3D vol->vol[1] * 257; spice_server_playback_set_volume(&out->sin, 2, svol); spice_server_playback_set_mute(&out->sin, vol->mute); } @@ -262,13 +263,14 @@ static void line_in_enable(HWVoiceIn *hw, bool enable) } =20 #if ((SPICE_INTERFACE_RECORD_MAJOR >=3D 2) && (SPICE_INTERFACE_RECORD_MINO= R >=3D 2)) -static void line_in_volume(HWVoiceIn *hw, struct mixeng_volume *vol) +static void line_in_volume(HWVoiceIn *hw, Volume *vol) { SpiceVoiceIn *in =3D container_of(hw, SpiceVoiceIn, hw); uint16_t svol[2]; =20 - svol[0] =3D vol->l / ((1ULL << 16) + 1); - svol[1] =3D vol->r / ((1ULL << 16) + 1); + assert(vol->channels =3D=3D 2); + svol[0] =3D vol->vol[0] * 257; + svol[1] =3D vol->vol[1] * 257; spice_server_record_set_volume(&in->sin, 2, svol); spice_server_record_set_mute(&in->sin, vol->mute); } --=20 2.23.0