From nobody Wed Nov 12 06:52:11 2025 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=fail; 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=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1568576646; cv=none; d=zoho.com; s=zohoarc; b=JMiJAjDc+fT3L99ByeUQqegoK8V4WrTqmjZaQxvQ3QrrPcS405+6GHRH9gFwxfo5pSWQQ38bQFvfjwhXCHUqHert3FuJbg9oP9egQRPaCy4JdM/yOE/7W8wtiV//4FArJTa5rE3P+PoQcZjXUNoL4AvsT8NeS2MRTiIls8AgIW0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568576646; 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:ARC-Authentication-Results; bh=hBNbSNYdRxpi4YPwJzeBrQcOF4eLYJl4drOoaIZgmh0=; b=cDaKR8A7GNyeuA2xlnW+SyokcNF46ScHPV/Vorea5+Kt+lX9huorgGY9YmTV8vGL++1w7M+OZW6knw/ZlJ+B2BEASBXKkoPLlsP+8iqx3B7REuapwRKf1fq4Ms99gsE7xgfZ2RYFrFmHtd9fsFOF/IH+cMfMrh8XVJKUH6c2fs4= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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=fail 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 1568576646211935.1459510094094; Sun, 15 Sep 2019 12:44:06 -0700 (PDT) Received: from localhost ([::1]:56718 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i9aRI-0002EP-M7 for importer@patchew.org; Sun, 15 Sep 2019 15:44:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40122) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i9a7p-0006ER-Vc for qemu-devel@nongnu.org; Sun, 15 Sep 2019 15:23:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i9a7o-00022D-9f for qemu-devel@nongnu.org; Sun, 15 Sep 2019 15:23:57 -0400 Received: from mail-ed1-x543.google.com ([2a00:1450:4864:20::543]:41263) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i9a7o-00021r-0E for qemu-devel@nongnu.org; Sun, 15 Sep 2019 15:23:56 -0400 Received: by mail-ed1-x543.google.com with SMTP id z9so31223644edq.8 for ; Sun, 15 Sep 2019 12:23:55 -0700 (PDT) Received: from nullptr.home.dirty-ice.org (2a01-036c-0113-74ef-0000-0000-0000-0005.pool6.digikabel.hu. [2a01:36c:113:74ef::5]) by smtp.gmail.com with ESMTPSA id j20sm6480562edy.95.2019.09.15.12.23.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Sep 2019 12:23:54 -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=O2z5qgykZfwNkSJ7wOeHxWGIbIvTENhw7a4Tc2+PdF3TjhaEfwK92u+txCSu2mQ+S6 Lcp1PyI6pNp/6qFeb7KkIWgd04StqMs4tgL2qrCs6zCAdPEUfinDBKbTnxLDlscsqcA0 gpgmrsPc6RTLdv1kicTQ4ZcnKcxh7EzPDHx6zU/9p++doBalKBe1BFaU8V/GfmkHk1w/ ke8lI4CeiKcUIwWZIn1mxRG/P+pOHvblr0EJNjsoiEHJYkBrXLbZ4B//tbn2zmBVrVaj GOdYr8k6+VGGmLL9VWqlSNkgPdK3I9xQGjkEEwSQZ/Rn7Vt7hwzB7Mc1e0jaBY/PWdNw Yp8g== 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=qYkp9xAvP/bw2x9uN7sOeI1nJm6PKTHZLks+bSdStXH9jQwILrCTk1groyFahCJIVU VzCJyPLFHdkOTz6EhlxE+Ag3xMpimy1vW9JI7LN+aeq3GQWEz7X75/wtjpkP3NGIZPaM Ob5kohFfMqHsd6CD1C406hWfzVIZNT7jtIFmXTCV1wBFjRh5P2kJK41PM7fe29lF+8JM Ocq14sLj7xrwPwBImUILHJkTD5rCVzP8Rj2ug99snxkSiEPBEJHKOZBHXFK5eL2pwxVL 0iCeC+Ca3wpIJsAPCQ132rFsob4MRHrunUQIcWmNDWgZbZyE2SBJZgvJ8F052WYB5Kac OKFQ== X-Gm-Message-State: APjAAAWgfAcJXZTTZLX9Qp3OyN0TBaIaF6u8gpuuIMjpdCjWVwPMGXkA eS547VzM8jukIEv79Sta6veDkniS X-Google-Smtp-Source: APXvYqylwkyW4dMLDYgdWL4M+yJskPaGGoRBiRLfetobsAx79pkfsNJ8csLag4V3tcTfRZj5wx2jjg== X-Received: by 2002:a05:6402:7d1:: with SMTP id u17mr58293648edy.132.1568575434680; Sun, 15 Sep 2019 12:23:54 -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 Date: Sun, 15 Sep 2019 21:23:34 +0200 Message-Id: <4c938a46b760792319dbc2f61a442a41a36718d3.1568574965.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::543 Subject: [Qemu-devel] [PATCH v3 18/24] audio: support more than two channels in volume setting 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: fail (Header signature does not verify) 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