From nobody Wed Nov 12 10:11:20 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=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=1569877125; cv=none; d=zoho.com; s=zohoarc; b=NHoXj+jCd5uzNqFcRsfq77l3haz1vQVybTT7DAUof2eKaD5+3wcFMVfNaMXcqiZYkiV0UhVkYriZWms/rK/3NJTmU6peg5X2ZzFmS0FOq6CKwTsEup51FXyr2WylXnOgAhEaZUlKbVAjxPJvK9Z97bQ9/wvKumzmTmkVrBoNq24= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569877125; 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=CrGIqcqI78hzcNeEeP/Yof6RQsfETD3IT81DLC9vTNfcWD5fLIVeUeSMklvtGZHspFKcrNkJAZ0jypedxQO8T1dT4L9ApSYf5nykkuvrCqRWCN7q9Fadkw6A+Hq6xWVGm1eCd837/LAbSGt2EFgPKxyAI29wO4hyQ7um3RmJWJg= 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 1569877125278181.87789678951754; Mon, 30 Sep 2019 13:58:45 -0700 (PDT) Received: from localhost ([::1]:57248 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iF2kh-0004gC-P6 for importer@patchew.org; Mon, 30 Sep 2019 16:58:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45755) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iF2Hc-0003yS-MP for qemu-devel@nongnu.org; Mon, 30 Sep 2019 16:28:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iF2Ha-0002Vd-Tt for qemu-devel@nongnu.org; Mon, 30 Sep 2019 16:28:36 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:38591) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iF2Ha-0002Ud-N8 for qemu-devel@nongnu.org; Mon, 30 Sep 2019 16:28:34 -0400 Received: by mail-wm1-x344.google.com with SMTP id 3so833478wmi.3 for ; Mon, 30 Sep 2019 13:28:34 -0700 (PDT) Received: from nullptr.home.dirty-ice.org (2a01-036c-0113-e8f4-0000-0000-0000-0005.pool6.digikabel.hu. [2a01:36c:113:e8f4::5]) by smtp.gmail.com with ESMTPSA id o9sm34402911wrh.46.2019.09.30.13.28.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2019 13:28:32 -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=ms10rP32sZnKeZos9wbQQvyQTYP6hSSoy+PMIevApEBnDnUCH+U5N7lOwn7zJ8i8OP J55/UoehyuqCkjnXh3za+clSmtD1E2yfIeBThT3SDWXKqaLjZj50BXew8o6Vot/SMxl+ 4PsIcHim/l16Nj4Lxfbg8YT2ZF8V7TOVNTGT0SOQTQnv6ETypwjD1b4rwCr214678Ld8 jYHdiK/ekYkPTy1UmtSpOatUL8h2n9m8LDAB8kFp0JCUfDrgLv3UrUH6iqIukKt2KYPT E2nEQLlkjeKGEByif/zfbbOVeb/pPnapJx8SJohGvmycOilTlYOqYhJ7xo/KegZMzhky Ej9A== 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=jl4tadNzrmdNovqktNIIIVG4d8RULhMcN0qo2EtSpaQwDLtTPPQNah0Xee6bLRl70k ss1lBE18PY1kWECF+FIRK/tpOX2oEUmcVMAkqikeuGW7ECWFhBj0rDef3g8YPYC0+xj0 9bizGsORIh7mc3FFs6Dfl92+IrrmUw4YgYkTsByx9bEYlfkquS6fZXpMyAxsT+TTXsBM Akitfx7WAyvV3sp5koFvo/XcHBzMdJHtoYGGKt+JSyjzJIyyV7TfRKXS9LyYAWldCk8Y 0iEV+nbTSdmVwRw+qWz9j4JFLSOd7iJHTvCAJE2y5/d+OVhki0OydBC6wEUDYr40h9Z1 ry8g== X-Gm-Message-State: APjAAAX2+oajA7ubydDTvckZSudbkWkVS5B2ZS2s9Zk3CZvWreMeuiS0 PGZlBOyG9TtBqtSSoQ7x6O5PCEiD X-Google-Smtp-Source: APXvYqxV07HUGkoTkODvSYUa+KlfTCGIZlDoSdzjRr9FO28wFueltvftI7x4Vq7woC9DnPl5tBOiZw== X-Received: by 2002:a1c:4384:: with SMTP id q126mr768052wma.153.1569875313494; Mon, 30 Sep 2019 13:28:33 -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 v5 04/10] audio: support more than two channels in volume setting Date: Mon, 30 Sep 2019 22:28:57 +0200 Message-Id: <5b043a6e1895f78f83e0597aec878635f087ad71.1569874641.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::344 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