From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=57744 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PcOb7-0002gb-8r for qemu-devel@nongnu.org; Mon, 10 Jan 2011 15:44:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PcOb4-0001Ld-Sc for qemu-devel@nongnu.org; Mon, 10 Jan 2011 15:44:13 -0500 Received: from fmmailgate02.web.de ([217.72.192.227]:41337) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PcOb3-0001Kt-Rh for qemu-devel@nongnu.org; Mon, 10 Jan 2011 15:44:10 -0500 Message-ID: <4D2B6F8B.5080302@web.de> Date: Mon, 10 Jan 2011 21:43:55 +0100 From: Jan Kiszka MIME-Version: 1.0 References: <1294185947-29250-1-git-send-email-michael@walle.cc> In-Reply-To: <1294185947-29250-1-git-send-email-michael@walle.cc> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig5F5CA57E4CE61C23F0F40831" Sender: jan.kiszka@web.de Subject: [Qemu-devel] Re: [PATCH] audio: split sample conversion and volume mixing List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Michael Walle Cc: qemu-devel@nongnu.org This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig5F5CA57E4CE61C23F0F40831 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable Am 05.01.2011 01:05, Michael Walle wrote: > Refactor the volume mixing, so it can be reused for capturing devices. > Additionally, it removes superfluous multiplications with the nominal > volume within the hardware voice code path. At least based on tests done with the Musicpal, I see problems with this patch, volume control still fine here. Jan >=20 > Signed-off-by: Michael Walle > --- > audio/alsaaudio.c | 2 +- > audio/audio.c | 11 ++++++----- > audio/audio_int.h | 2 +- > audio/dsoundaudio.c | 4 ++-- > audio/esdaudio.c | 3 +-- > audio/fmodaudio.c | 4 ++-- > audio/mixeng.c | 25 +++++++++++++++++++++++++ > audio/mixeng.h | 4 ++-- > audio/mixeng_template.h | 39 +++++++--------------------------------= > audio/ossaudio.c | 3 +-- > audio/paaudio.c | 2 +- > audio/spiceaudio.c | 5 ++--- > audio/winwaveaudio.c | 3 +-- > 13 files changed, 52 insertions(+), 55 deletions(-) >=20 > diff --git a/audio/alsaaudio.c b/audio/alsaaudio.c > index fef24f6..301a6af 100644 > --- a/audio/alsaaudio.c > +++ b/audio/alsaaudio.c > @@ -1094,7 +1094,7 @@ static int alsa_run_in (HWVoiceIn *hw) > } > } > =20 > - hw->conv (dst, src, nread, &nominal_volume); > + hw->conv (dst, src, nread); > =20 > src =3D advance (src, nread << hwshift); > dst +=3D nread; > diff --git a/audio/audio.c b/audio/audio.c > index 1707446..1729c0b 100644 > --- a/audio/audio.c > +++ b/audio/audio.c > @@ -104,7 +104,7 @@ static struct { > =20 > static AudioState glob_audio_state; > =20 > -struct mixeng_volume nominal_volume =3D { > +const struct mixeng_volume nominal_volume =3D { > .mute =3D 0, > #ifdef FLOAT_MIXENG > .r =3D 1.0, > @@ -702,13 +702,11 @@ void audio_pcm_info_clear_buf (struct audio_pcm_i= nfo *info, void *buf, int len) > /* > * Capture > */ > -static void noop_conv (struct st_sample *dst, const void *src, > - int samples, struct mixeng_volume *vol) > +static void noop_conv (struct st_sample *dst, const void *src, int sam= ples) > { > (void) src; > (void) dst; > (void) samples; > - (void) vol; > } > =20 > static CaptureVoiceOut *audio_pcm_capture_find_specific ( > @@ -956,6 +954,8 @@ int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, in= t size) > total +=3D isamp; > } > =20 > + mixeng_volume (sw->buf, ret, &sw->vol); > + > sw->clip (buf, sw->buf, ret); > sw->total_hw_samples_acquired +=3D total; > return ret << sw->info.shift; > @@ -1037,7 +1037,8 @@ int audio_pcm_sw_write (SWVoiceOut *sw, void *buf= , int size) > swlim =3D ((int64_t) dead << 32) / sw->ratio; > swlim =3D audio_MIN (swlim, samples); > if (swlim) { > - sw->conv (sw->buf, buf, swlim, &sw->vol); > + sw->conv (sw->buf, buf, swlim); > + mixeng_volume (sw->buf, swlim, &sw->vol); > } > =20 > while (swlim) { > diff --git a/audio/audio_int.h b/audio/audio_int.h > index d66f2c3..2003f8b 100644 > --- a/audio/audio_int.h > +++ b/audio/audio_int.h > @@ -211,7 +211,7 @@ extern struct audio_driver esd_audio_driver; > extern struct audio_driver pa_audio_driver; > extern struct audio_driver spice_audio_driver; > extern struct audio_driver winwave_audio_driver; > -extern struct mixeng_volume nominal_volume; > +extern const struct mixeng_volume nominal_volume; > =20 > void audio_pcm_init_info (struct audio_pcm_info *info, struct audsetti= ngs *as); > void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf,= int len); > diff --git a/audio/dsoundaudio.c b/audio/dsoundaudio.c > index e547955..e2d89fd 100644 > --- a/audio/dsoundaudio.c > +++ b/audio/dsoundaudio.c > @@ -831,11 +831,11 @@ static int dsound_run_in (HWVoiceIn *hw) > decr =3D len1 + len2; > =20 > if (p1 && len1) { > - hw->conv (hw->conv_buf + hw->wpos, p1, len1, &nominal_volume);= > + hw->conv (hw->conv_buf + hw->wpos, p1, len1); > } > =20 > if (p2 && len2) { > - hw->conv (hw->conv_buf, p2, len2, &nominal_volume); > + hw->conv (hw->conv_buf, p2, len2); > } > =20 > dsound_unlock_in (dscb, p1, p2, blen1, blen2); > diff --git a/audio/esdaudio.c b/audio/esdaudio.c > index 9a1f2f8..ff97b39 100644 > --- a/audio/esdaudio.c > +++ b/audio/esdaudio.c > @@ -346,8 +346,7 @@ static void *qesd_thread_in (void *arg) > break; > } > =20 > - hw->conv (hw->conv_buf + wpos, buf, nread >> hw->info.shif= t, > - &nominal_volume); > + hw->conv (hw->conv_buf + wpos, buf, nread >> hw->info.shif= t); > wpos =3D (wpos + chunk) % hw->samples; > to_grab -=3D chunk; > } > diff --git a/audio/fmodaudio.c b/audio/fmodaudio.c > index 7f08e14..c34cf53 100644 > --- a/audio/fmodaudio.c > +++ b/audio/fmodaudio.c > @@ -488,10 +488,10 @@ static int fmod_run_in (HWVoiceIn *hw) > decr =3D len1 + len2; > =20 > if (p1 && blen1) { > - hw->conv (hw->conv_buf + hw->wpos, p1, len1, &nominal_volume);= > + hw->conv (hw->conv_buf + hw->wpos, p1, len1); > } > if (p2 && len2) { > - hw->conv (hw->conv_buf, p2, len2, &nominal_volume); > + hw->conv (hw->conv_buf, p2, len2); > } > =20 > fmod_unlock_sample (fmd->fmod_sample, p1, p2, blen1, blen2); > diff --git a/audio/mixeng.c b/audio/mixeng.c > index 9f1d93f..4a9e8eb 100644 > --- a/audio/mixeng.c > +++ b/audio/mixeng.c > @@ -333,3 +333,28 @@ void mixeng_clear (struct st_sample *buf, int len)= > { > memset (buf, 0, len * sizeof (struct st_sample)); > } > + > +void mixeng_volume (struct st_sample *buf, int len, struct mixeng_volu= me *vol) > +{ > +#ifdef CONFIG_MIXEMU > + if (vol->mute) { > + mixeng_clear (buf, len); > + return; > + } > + > + while (len--) { > +#ifdef FLOAT_MIXENG > + buf->l =3D buf->l * vol->l; > + buf->r =3D buf->r * vol->r; > +#else > + buf->l =3D (buf->l * vol->l) >> 32; > + buf->r =3D (buf->r * vol->r) >> 32; > +#endif > + buf +=3D 1; > + } > +#else > + (void) buf; > + (void) len; > + (void) vol; > +#endif > +} > diff --git a/audio/mixeng.h b/audio/mixeng.h > index 4af1dd9..9de443b 100644 > --- a/audio/mixeng.h > +++ b/audio/mixeng.h > @@ -33,8 +33,7 @@ struct mixeng_volume { int mute; int64_t r; int64_t l= ; }; > struct st_sample { int64_t l; int64_t r; }; > #endif > =20 > -typedef void (t_sample) (struct st_sample *dst, const void *src, > - int samples, struct mixeng_volume *vol); > +typedef void (t_sample) (struct st_sample *dst, const void *src, int s= amples); > typedef void (f_sample) (void *dst, const struct st_sample *src, int s= amples); > =20 > extern t_sample *mixeng_conv[2][2][2][3]; > @@ -47,5 +46,6 @@ void st_rate_flow_mix (void *opaque, struct st_sample= *ibuf, struct st_sample *o > int *isamp, int *osamp); > void st_rate_stop (void *opaque); > void mixeng_clear (struct st_sample *buf, int len); > +void mixeng_volume (struct st_sample *buf, int len, struct mixeng_volu= me *vol); > =20 > #endif /* mixeng.h */ > diff --git a/audio/mixeng_template.h b/audio/mixeng_template.h > index 5617705..a2d0ef8 100644 > --- a/audio/mixeng_template.h > +++ b/audio/mixeng_template.h > @@ -31,16 +31,6 @@ > #define HALF (IN_MAX >> 1) > #endif > =20 > -#ifdef CONFIG_MIXEMU > -#ifdef FLOAT_MIXENG > -#define VOL(a, b) ((a) * (b)) > -#else > -#define VOL(a, b) ((a) * (b)) >> 32 > -#endif > -#else > -#define VOL(a, b) a > -#endif > - > #define ET glue (ENDIAN_CONVERSION, glue (_, IN_T)) > =20 > #ifdef FLOAT_MIXENG > @@ -109,40 +99,26 @@ static inline IN_T glue (clip_, ET) (int64_t v) > #endif > =20 > static void glue (glue (conv_, ET), _to_stereo) > - (struct st_sample *dst, const void *src, int samples, struct mixen= g_volume *vol) > + (struct st_sample *dst, const void *src, int samples) > { > struct st_sample *out =3D dst; > IN_T *in =3D (IN_T *) src; > -#ifdef CONFIG_MIXEMU > - if (vol->mute) { > - mixeng_clear (dst, samples); > - return; > - } > -#else > - (void) vol; > -#endif > + > while (samples--) { > - out->l =3D VOL (glue (conv_, ET) (*in++), vol->l); > - out->r =3D VOL (glue (conv_, ET) (*in++), vol->r); > + out->l =3D glue (conv_, ET) (*in++); > + out->r =3D glue (conv_, ET) (*in++); > out +=3D 1; > } > } > =20 > static void glue (glue (conv_, ET), _to_mono) > - (struct st_sample *dst, const void *src, int samples, struct mixen= g_volume *vol) > + (struct st_sample *dst, const void *src, int samples) > { > struct st_sample *out =3D dst; > IN_T *in =3D (IN_T *) src; > -#ifdef CONFIG_MIXEMU > - if (vol->mute) { > - mixeng_clear (dst, samples); > - return; > - } > -#else > - (void) vol; > -#endif > + > while (samples--) { > - out->l =3D VOL (glue (conv_, ET) (in[0]), vol->l); > + out->l =3D glue (conv_, ET) (in[0]); > out->r =3D out->l; > out +=3D 1; > in +=3D 1; > @@ -174,4 +150,3 @@ static void glue (glue (clip_, ET), _from_mono) > =20 > #undef ET > #undef HALF > -#undef VOL > diff --git a/audio/ossaudio.c b/audio/ossaudio.c > index 0439ef5..1fda519 100644 > --- a/audio/ossaudio.c > +++ b/audio/ossaudio.c > @@ -784,8 +784,7 @@ static int oss_run_in (HWVoiceIn *hw) > hw->info.align + 1); > } > read_samples +=3D nread >> hwshift; > - hw->conv (hw->conv_buf + bufs[i].add, p, nread >> hwsh= ift, > - &nominal_volume); > + hw->conv (hw->conv_buf + bufs[i].add, p, nread >> hwsh= ift); > } > =20 > if (bufs[i].len - nread) { > diff --git a/audio/paaudio.c b/audio/paaudio.c > index ff71dac..9cf685d 100644 > --- a/audio/paaudio.c > +++ b/audio/paaudio.c > @@ -195,7 +195,7 @@ static void *qpa_thread_in (void *arg) > return NULL; > } > =20 > - hw->conv (hw->conv_buf + wpos, buf, chunk, &nominal_volume= ); > + hw->conv (hw->conv_buf + wpos, buf, chunk); > wpos =3D (wpos + chunk) % hw->samples; > to_grab -=3D chunk; > } > diff --git a/audio/spiceaudio.c b/audio/spiceaudio.c > index 373e4c4..a5c0d6b 100644 > --- a/audio/spiceaudio.c > +++ b/audio/spiceaudio.c > @@ -268,11 +268,10 @@ static int line_in_run (HWVoiceIn *hw) > len[1] =3D 0; > } > =20 > - hw->conv (hw->conv_buf + hw->wpos, samples, len[0], &nominal_volum= e); > + hw->conv (hw->conv_buf + hw->wpos, samples, len[0]); > =20 > if (len[1]) { > - hw->conv (hw->conv_buf, samples + len[0], len[1], > - &nominal_volume); > + hw->conv (hw->conv_buf, samples + len[0], len[1]); > } > =20 > hw->wpos =3D (hw->wpos + num_samples) % hw->samples; > diff --git a/audio/winwaveaudio.c b/audio/winwaveaudio.c > index cdf483b..e5ad3c6 100644 > --- a/audio/winwaveaudio.c > +++ b/audio/winwaveaudio.c > @@ -581,8 +581,7 @@ static int winwave_run_in (HWVoiceIn *hw) > int conv =3D audio_MIN (left, decr); > hw->conv (hw->conv_buf + hw->wpos, > advance (wave->pcm_buf, wave->rpos << hw->info.shift= ), > - conv, > - &nominal_volume); > + conv); > =20 > wave->rpos =3D (wave->rpos + conv) % hw->samples; > hw->wpos =3D (hw->wpos + conv) % hw->samples; --------------enig5F5CA57E4CE61C23F0F40831 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.15 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org/ iEYEARECAAYFAk0rb4sACgkQitSsb3rl5xS2SwCfWhOc+OWY9vk/5sXdn8f1bqu8 tkYAn3Je8Xl6iWcgdW2tZvRY7vgrBWaL =8zDn -----END PGP SIGNATURE----- --------------enig5F5CA57E4CE61C23F0F40831--