audio: Mixing engine and mixer emulation
Hi,
the SWVoiceIn volume is never used, although there is AUD_set_volume_in() to set it. Would it be possible to add support for it? So we could get the mixer emulation for capture devices too?
BTW i see you can only attenuate an audio stream with these volume settings (you can only set a max value of 255 and the formula is nominal_value * vol / 255). Would it be possible to support amplification too?
Signature · 1 line
Michael
Quoted 10 lines · Michael Walle
Hi,
the SWVoiceIn volume is never used, although there is
AUD_set_volume_in()to set it. Would it be possible to add support for it? So we could get the mixer emulation for capture devices too?BTW i see you can only attenuate an audio stream with these volume settings (you can only set a max value of 255 and the formula is
nominal_value* vol / 255). Would it be possible to support amplification too?
I've never touched this code since writing it way back then, if you cook up a patch... (This is a reply to both your questions)
Signature · 1 line
mailto:[email protected]
PATCH 1/1 audio: split sample conversion and volume mixing
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.
--- 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(-)
audio/alsaaudio.c +1 -1
@@ -1094,7 +1094,7 @@ static int alsa_run_in (HWVoiceIn *hw) } } - hw->conv (dst, src, nread, &nominal_volume); + hw->conv (dst, src, nread); src =advance (src, nread << hwshift); dst += nread;
audio/audio.c +6 -5
@@ -104,7 +104,7 @@ static struct {static AudioState glob_audio_state; -struct mixeng_volume nominal_volume = { +const struct mixeng_volume nominal_volume = { .mute =0 , #ifdef FLOAT_MIXENG .r = 1.0,
@@ -702,13 +702,11 @@ void audio_pcm_info_clear_buf (struct audio_pcm_info *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 samples) { (void ) src; (void ) dst; (void ) samples; - (void ) vol; } static CaptureVoiceOut *audio_pcm_capture_find_specific (
@@ -956,6 +954,8 @@ int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int size) total += isamp; } +mixeng_volume (sw->buf, ret, &sw->vol); + sw->clip (buf, sw->buf, ret); sw->total_hw_samples_acquired += total;return ret << sw->info.shift;
@@ -1037,7 +1037,8 @@ int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int size) swlim = ((int64_t ) dead <<32 ) / sw->ratio; swlim =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); }while (swlim) {
audio/audio_int.h +1 -1
@@ -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;void audio_pcm_init_info (struct audio_pcm_info *info,struct audsettings *as);void audio_pcm_info_clear_buf (struct audio_pcm_info *info,void *buf,int len);
audio/dsoundaudio.c +2 -2
@@ -831,11 +831,11 @@ static int dsound_run_in (HWVoiceIn *hw) decr = len1 + len2;if (p1 && len1) { - 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); }dsound_unlock_in (dscb, p1, p2, blen1, blen2);
audio/esdaudio.c +1 -2
@@ -346,8 +346,7 @@ static void *qesd_thread_in (void *arg)break ; } - hw->conv (hw->conv_buf + wpos, buf, nread >> hw->info.shift, - &nominal_volume); + hw->conv (hw->conv_buf + wpos, buf, nread >> hw->info.shift); wpos = (wpos + chunk) % hw->samples; to_grab -= chunk; }
audio/fmodaudio.c +2 -2
@@ -488,10 +488,10 @@ static int fmod_run_in (HWVoiceIn *hw) decr = len1 + len2;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); }fmod_unlock_sample (fmd->fmod_sample, p1, p2, blen1, blen2);
audio/mixeng.c +25 -0
@@ -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_volume *vol) +{ +#ifdef CONFIG_MIXEMU +if (vol->mute) { +mixeng_clear (buf, len); +return ; + } + +while (len--) { +#ifdef FLOAT_MIXENG + buf->l = buf->l * vol->l; + buf->r = buf->r * vol->r; +#else + buf->l = (buf->l * vol->l) >>32 ; + buf->r = (buf->r * vol->r) >>32 ; +#endif + buf +=1 ; + } +#else + (void ) buf; + (void ) len; + (void ) vol; +#endif +}
audio/mixeng.h +2 -2
@@ -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 -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 samples);typedef void (f_sample ) (void *dst,const struct st_sample *src,int samples);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_volume *vol);#endif /* mixeng.h */
audio/mixeng_template.h +7 -32
@@ -31,16 +31,6 @@#define HALF (IN_MAX >> 1)#endif -#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))#ifdef FLOAT_MIXENG
@@ -109,40 +99,26 @@ static inline IN_T glue (clip_, ET) (int64_t v)#endif static void glue (glue (conv_ ,ET ),_to_stereo ) - (struct st_sample *dst,const void *src,int samples,struct mixeng_volume *vol) + (struct st_sample *dst,const void *src,int samples) {struct st_sample *out = dst;IN_T *in = (IN_T *) src; -#ifdef CONFIG_MIXEMU -if (vol->mute) { -mixeng_clear (dst, samples); -return ; - } -#else - (void ) vol; -#endif +while (samples--) { - out->l =VOL (glue (conv_,ET ) (*in++), vol->l); - out->r =VOL (glue (conv_,ET ) (*in++), vol->r); + out->l =glue (conv_,ET ) (*in++); + out->r =glue (conv_,ET ) (*in++); out +=1 ; } }static void glue (glue (conv_ ,ET ),_to_mono ) - (struct st_sample *dst,const void *src,int samples,struct mixeng_volume *vol) + (struct st_sample *dst,const void *src,int samples) {struct st_sample *out = dst;IN_T *in = (IN_T *) src; -#ifdef CONFIG_MIXEMU -if (vol->mute) { -mixeng_clear (dst, samples); -return ; - } -#else - (void ) vol; -#endif +while (samples--) { - out->l =VOL (glue (conv_,ET ) (in[0 ]), vol->l); + out->l =glue (conv_,ET ) (in[0 ]); out->r = out->l; out +=1 ; in +=1 ;
@@ -174,4 +150,3 @@ static void glue (glue (clip_, ET), _from_mono)#undef ET#undef HALF -#undef VOL
audio/ossaudio.c +1 -2
@@ -784,8 +784,7 @@ static int oss_run_in (HWVoiceIn *hw) hw->info.align + 1); } read_samples += nread >> hwshift; - hw->conv (hw->conv_buf + bufs[i].add, p, nread >> hwshift, - &nominal_volume); + hw->conv (hw->conv_buf + bufs[i].add, p, nread >> hwshift); }if (bufs[i].len - nread) {
audio/paaudio.c +1 -1
@@ -195,7 +195,7 @@ static void *qpa_thread_in (void *arg)return NULL ; } - hw->conv (hw->conv_buf + wpos, buf, chunk, &nominal_volume); + hw->conv (hw->conv_buf + wpos, buf, chunk); wpos = (wpos + chunk) % hw->samples; to_grab -= chunk; }
audio/spiceaudio.c +2 -3
@@ -268,11 +268,10 @@ static int line_in_run (HWVoiceIn *hw) len[1 ] =0 ; } - hw->conv (hw->conv_buf + hw->wpos, samples, len[0 ], &nominal_volume); + hw->conv (hw->conv_buf + hw->wpos, samples, len[0 ]);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 ]); } hw->wpos = (hw->wpos + num_samples) % hw->samples;
audio/winwaveaudio.c +1 -2
@@ -581,8 +581,7 @@ static int winwave_run_in (HWVoiceIn *hw)int conv =audio_MIN (left, decr); hw->conv (hw->conv_buf + hw->wpos,advance (wave->pcm_buf, wave->rpos << hw->info.shift), - conv, - &nominal_volume); + conv); wave->rpos = (wave->rpos + conv) % hw->samples; hw->wpos = (hw->wpos + conv) % hw->samples;
Signature · 1 line
1.7.2.3
[Qemu-devel] Re: [PATCH] audio: split sample conversion and volume mixing
Quoted 3 lines · Michael Walle
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
Quoted 327 lines
Signed-off-by Michael Walle <[email protected]>--- 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(-)audio/alsaaudio.c +1
-1@@ -1094,7 +1094,7 @@ static int alsa_run_in (HWVoiceIn *hw) } } - hw->conv (dst, src, nread, &nominal_volume); + hw->conv (dst, src, nread); src =advance (src, nread << hwshift); dst += nread;audio/audio.c +6
-5@@ -104,7 +104,7 @@ static struct {static AudioState glob_audio_state; -struct mixeng_volume nominal_volume = { +const struct mixeng_volume nominal_volume = { .mute =0 , #ifdef FLOAT_MIXENG .r = 1.0,@@ -702,13 +702,11 @@ void audio_pcm_info_clear_buf (struct audio_pcm_info *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 samples) { (void ) src; (void ) dst; (void ) samples; - (void ) vol; } static CaptureVoiceOut *audio_pcm_capture_find_specific (@@ -956,6 +954,8 @@ int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int size) total += isamp; } +mixeng_volume (sw->buf, ret, &sw->vol); + sw->clip (buf, sw->buf, ret); sw->total_hw_samples_acquired += total;return ret << sw->info.shift;@@ -1037,7 +1037,8 @@ int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int size) swlim = ((int64_t ) dead <<32 ) / sw->ratio; swlim =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); }while (swlim) {audio/audio_int.h +1
-1@@ -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;void audio_pcm_init_info (struct audio_pcm_info *info,struct audsettings *as);void audio_pcm_info_clear_buf (struct audio_pcm_info *info,void *buf,int len);audio/dsoundaudio.c +2
-2@@ -831,11 +831,11 @@ static int dsound_run_in (HWVoiceIn *hw) decr = len1 + len2;if (p1 && len1) { - 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); }dsound_unlock_in (dscb, p1, p2, blen1, blen2);audio/esdaudio.c +1
-2@@ -346,8 +346,7 @@ static void *qesd_thread_in (void *arg)break ; } - hw->conv (hw->conv_buf + wpos, buf, nread >> hw->info.shift, - &nominal_volume); + hw->conv (hw->conv_buf + wpos, buf, nread >> hw->info.shift); wpos = (wpos + chunk) % hw->samples; to_grab -= chunk; }audio/fmodaudio.c +2
-2@@ -488,10 +488,10 @@ static int fmod_run_in (HWVoiceIn *hw) decr = len1 + len2;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); }fmod_unlock_sample (fmd->fmod_sample, p1, p2, blen1, blen2);audio/mixeng.c +25
-0@@ -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_volume *vol) +{ +#ifdef CONFIG_MIXEMU +if (vol->mute) { +mixeng_clear (buf, len); +return ; + } + +while (len--) { +#ifdef FLOAT_MIXENG + buf->l = buf->l * vol->l; + buf->r = buf->r * vol->r; +#else + buf->l = (buf->l * vol->l) >>32 ; + buf->r = (buf->r * vol->r) >>32 ; +#endif + buf +=1 ; + } +#else + (void ) buf; + (void ) len; + (void ) vol; +#endif +}audio/mixeng.h +2
-2@@ -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 -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 samples);typedef void (f_sample ) (void *dst,const struct st_sample *src,int samples);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_volume *vol);#endif /* mixeng.h */ audio/mixeng_template.h +7
-32@@ -31,16 +31,6 @@#define HALF (IN_MAX >> 1)#endif -#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))#ifdef FLOAT_MIXENG @@ -109,40 +99,26 @@ static inline IN_T glue (clip_, ET) (int64_t v)#endif static void glue (glue (conv_ ,ET ),_to_stereo ) - (struct st_sample *dst,const void *src,int samples,struct mixeng_volume *vol) + (struct st_sample *dst,const void *src,int samples) {struct st_sample *out = dst;IN_T *in = (IN_T *) src; -#ifdef CONFIG_MIXEMU -if (vol->mute) { -mixeng_clear (dst, samples); -return ; - } -#else - (void ) vol; -#endif +while (samples--) { - out->l =VOL (glue (conv_,ET ) (*in++), vol->l); - out->r =VOL (glue (conv_,ET ) (*in++), vol->r); + out->l =glue (conv_,ET ) (*in++); + out->r =glue (conv_,ET ) (*in++); out +=1 ; } }static void glue (glue (conv_ ,ET ),_to_mono ) - (struct st_sample *dst,const void *src,int samples,struct mixeng_volume *vol) + (struct st_sample *dst,const void *src,int samples) {struct st_sample *out = dst;IN_T *in = (IN_T *) src; -#ifdef CONFIG_MIXEMU -if (vol->mute) { -mixeng_clear (dst, samples); -return ; - } -#else - (void ) vol; -#endif +while (samples--) { - out->l =VOL (glue (conv_,ET ) (in[0 ]), vol->l); + out->l =glue (conv_,ET ) (in[0 ]); out->r = out->l; out +=1 ; in +=1 ;@@ -174,4 +150,3 @@ static void glue (glue (clip_, ET), _from_mono)#undef ET#undef HALF -#undef VOLaudio/ossaudio.c +1
-2@@ -784,8 +784,7 @@ static int oss_run_in (HWVoiceIn *hw) hw->info.align + 1); } read_samples += nread >> hwshift; - hw->conv (hw->conv_buf + bufs[i].add, p, nread >> hwshift, - &nominal_volume); + hw->conv (hw->conv_buf + bufs[i].add, p, nread >> hwshift); }if (bufs[i].len - nread) {audio/paaudio.c +1
-1@@ -195,7 +195,7 @@ static void *qpa_thread_in (void *arg)return NULL ; } - hw->conv (hw->conv_buf + wpos, buf, chunk, &nominal_volume); + hw->conv (hw->conv_buf + wpos, buf, chunk); wpos = (wpos + chunk) % hw->samples; to_grab -= chunk; }audio/spiceaudio.c +2
-3@@ -268,11 +268,10 @@ static int line_in_run (HWVoiceIn *hw) len[1 ] =0 ; } - hw->conv (hw->conv_buf + hw->wpos, samples, len[0 ], &nominal_volume); + hw->conv (hw->conv_buf + hw->wpos, samples, len[0 ]);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 ]); } hw->wpos = (hw->wpos + num_samples) % hw->samples;audio/winwaveaudio.c +1
-2@@ -581,8 +581,7 @@ static int winwave_run_in (HWVoiceIn *hw)int conv =audio_MIN (left, decr); hw->conv (hw->conv_buf + hw->wpos,advance (wave->pcm_buf, wave->rpos << hw->info.shift), - conv, - &nominal_volume); + conv); wave->rpos = (wave->rpos + conv) % hw->samples; hw->wpos = (hw->wpos + conv) % hw->samples;
[Qemu-devel] Re: [PATCH] audio: split sample conversion and volume mixing
Quoted 7 lines · Jan Kiszka
Quoted 3 lines · Michael Walle
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.
"I see problems" or "I see _no_ problems".
[..snip..]
Signature · 1 line
mailto:[email protected]
[Qemu-devel] Re: [PATCH] audio: split sample conversion and volume mixing
Quoted 11 lines · malc
Quoted 7 lines · Jan Kiszka
Quoted 3 lines · Michael Walle
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.
"I see problems" or "I see _no_ problems".
Sorry, "no problem" of course.
Jan
RE: [Qemu-devel] Re: [PATCH] audio: split sample conversion and volumemixing
In reply to Jan KiszkaThe fixed point path for scaling in mixeng_volume() seems to be under by a factor of two, IMHO. The right shift should be by 31, not 32. (Because the volume, which I assume is a signed 32 bit integer, can be 0.5 at most).
Does the code work with FLOAT_MIXENG undefined?
- Wolfgang Schildbach
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Jan Kiszka
Sent: Monday, January 10, 2011 9:44 PM
To: Michael Walle
Cc: [email protected]
Subject: [Qemu-devel] Re: [PATCH] audio: split sample conversion and volumemixing
Quoted 3 lines · Michael Walle
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
Quoted 12 lines
Signed-off-by Michael Walle <[email protected]>--- 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/audio.c int audio_pcm_sw_write (SWVoiceOut *sw, void
Quoted 59 lines
audio/ossaudio.c | 3 +-- audio/paaudio.c | 2 +- audio/spiceaudio.c | 5 ++--- audio/winwaveaudio.c | 3 +-- 13 files changed, 52 insertions(+), 55 deletions(-)audio/alsaaudio.c index renamed from audio/alsaaudio.c +0
-0fef24f6..301a6af 100644
audio/alsaaudio.c +1
-1@@ -1094,7 +1094,7 @@ static int alsa_run_in (HWVoiceIn *hw) } } - hw->conv (dst, src, nread, &nominal_volume); + hw->conv (dst, src, nread); src =advance (src, nread << hwshift); dst += nread;audio/audio.c index 1707446..1729c0b renamed from audio/audio.c +0
-0100644
audio/audio.c +6
-4@@ -104,7 +104,7 @@ static struct {static AudioState glob_audio_state; -struct mixeng_volume nominal_volume = { +const struct mixeng_volume nominal_volume = { .mute =0 , #ifdef FLOAT_MIXENG .r = 1.0,@@ -702,13 +702,11 @@ void audio_pcm_info_clear_buf (struct audio_pcm_info *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 +samples) { (void ) src; (void ) dst; (void ) samples; - (void ) vol; } static CaptureVoiceOut *audio_pcm_capture_find_specific ( @@ -956,6 +954,8 @@ int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int size) total += isamp; } +mixeng_volume (sw->buf, ret, &sw->vol); + sw->clip (buf, sw->buf, ret); sw->total_hw_samples_acquired += total;return ret << sw->info.shift;@@ -1037,7 +1037,8 @@ int audio_pcm_sw_write (SWVoiceOut *sw, void
*buf, int size)
Quoted 27 lines
audio/audio.c +2
-1swlim = ((int64_t ) dead <<32 ) / sw->ratio; swlim =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); }while (swlim) {audio/audio_int.h index renamed from audio/audio_int.h +0
-0d66f2c3..2003f8b 100644
audio/audio_int.h +0
-0@@ -211,7 +211,7 @@ extern struct audio_driver esd_audio_driver;extern struct
audio_driverpa_audio_driver; extern structaudio_driverspice_audio_driver; extern structaudio_driverwinwave_audio_driver; -extern structmixeng_volumenominal_volume; +extern const structmixeng_volumenominal_volume;void
audio_pcm_init_info(structaudio_pcm_info*info, struct
audsettings *as); voidaudio_pcm_info_clear_buf(structaudio_pcm_info*info, void *buf, int len); diff --gita/audio/dsoundaudio.cb/audio/dsoundaudio.cindex e547955..e2d89fd 100644
audio/dsoundaudio.c static int dsound_run_in (HWVoiceIn *hw) · line 834
Quoted 4 lines
audio/dsoundaudio.c +0
-1@@ -831,11 +831,11 @@ static int dsound_run_in (HWVoiceIn *hw) decr = len1 + len2;if (p1 && len1) { - hw->conv (hw->conv_buf + hw->wpos, p1, len1,
&nominal_volume);
Quoted 13 lines
audio/dsoundaudio.c +2
-1+ 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); } dsound_unlock_in (dscb, p1, p2, blen1, blen2); diff --git
a/audio/esdaudio.cb/audio/esdaudio.cindex 9a1f2f8..ff97b39 100644
audio/esdaudio.c static void *qesd_thread_in (void *arg) · line 349
Quoted 4 lines
audio/esdaudio.c +0
-1@@ -346,8 +346,7 @@ static void *qesd_thread_in (void *arg)break ; } - hw->conv (hw->conv_buf + wpos, buf, nread >>
hw->info.shift,
Quoted 11 lines
audio/esdaudio.c +2
-1- &nominal_volume); + hw->conv (hw->conv_buf + wpos, buf, nread >> + hw->info.shift); wpos = (wpos + chunk) % hw->samples; to_grab -= chunk; }audio/fmodaudio.c index renamed from audio/fmodaudio.c +0
-07f08e14..c34cf53 100644
audio/fmodaudio.c static int fmod_run_in (HWVoiceIn *hw) · line 491
Quoted 4 lines
audio/fmodaudio.c +0
-1@@ -488,10 +488,10 @@ static int fmod_run_in (HWVoiceIn *hw) decr = len1 + len2;if (p1 && blen1) { - hw->conv (hw->conv_buf + hw->wpos, p1, len1,
&nominal_volume);
Quoted 52 lines
audio/fmodaudio.c +2
-2+ 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); }fmod_unlock_sample (fmd->fmod_sample, p1, p2, blen1, blen2); diff --git a/audio/mixeng.c b/audio/mixeng.c index 9f1d93f..4a9e8eb 100644audio/mixeng.c +23
-0@@ -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_volume *vol) {#ifdef CONFIG_MIXEMU +if (vol->mute) { +mixeng_clear (buf, len); +return ; + } + +while (len--) { +#ifdef FLOAT_MIXENG + buf->l = buf->l * vol->l; + buf->r = buf->r * vol->r; +#else + buf->l = (buf->l * vol->l) >>32 ; + buf->r = (buf->r * vol->r) >>32 ;#endif + buf +=1 ; + } +#else + (void ) buf; + (void ) len; + (void ) vol; +#endif +}audio/mixeng.h index 4af1dd9..9de443b renamed from audio/mixeng.h +0
-0100644
audio/mixeng.h +0
-0@@ -33,8 +33,7 @@ struct mixeng_volume { int mute; int64_t r; int64_tl; }; struct
st_sample{int64_tl;int64_tr; }; #endifaudio/mixeng.h +2
-2-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 +samples); typedef void (f_sample) (void *dst, const struct st_sample *src, intsamples);
Quoted 2 lines
extern
t_sample*mixeng_conv[2][2][2][3]; @@ -47,5 +46,6 @@ voidst_rate_flow_mix(void *opaque, structst_sample*ibuf, struct
st_sample *o
Quoted 28 lines
int *isamp, int *osamp); void
st_rate_stop
(void *opaque); voidmixeng_clear(structst_sample*buf, int len);audio/mixeng.h +2
-0+void mixeng_volume (struct st_sample *buf,int len,struct +mixeng_volume *vol);#endif /* mixeng.h */ audio/mixeng_template.h index renamed from audio/mixeng_template.h +0
-05617705..a2d0ef8 100644
audio/mixeng_template.h +0
-10@@ -31,16 +31,6 @@#define HALF (IN_MAX >> 1)#endif -#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))#ifdef FLOAT_MIXENG
audio/mixeng_template.h static inline IN_T glue (clip_, ET) (int64_t v) · line 112
Quoted 4 lines
audio/mixeng_template.h +0
-1@@ -109,40 +99,26 @@ static inline IN_T glue (clip_, ET) (int64_t v)#endif static void glue (glue (conv_ ,ET ),_to_stereo ) - (struct st_sample *dst, const void *src, int samples, struct
mixeng_volume *vol)
Quoted 14 lines
audio/mixeng_template.h +2
-8+ (struct st_sample *dst, const void *src, int samples) {struct st_sample *out = dst;IN_T *in = (IN_T *) src; -#ifdef CONFIG_MIXEMU -if (vol->mute) { -mixeng_clear (dst, samples); -return ; - } -#else - (void ) vol; -#endif +while (samples--) {
audio/mixeng_template.h static inline IN_T glue (clip_, ET) (int64_t v)
Quoted 10 lines
audio/mixeng_template.h +2
-3- out->l =VOL (glue (conv_,ET ) (*in++), vol->l); - out->r =VOL (glue (conv_,ET ) (*in++), vol->r); + out->l =glue (conv_,ET ) (*in++); + out->r =glue (conv_,ET ) (*in++); out +=1 ; } }static void glue (glue (conv_ ,ET ),_to_mono ) - (struct st_sample *dst, const void *src, int samples, struct
mixeng_volume *vol)
Quoted 29 lines
audio/mixeng_template.h +3
-10+ (struct st_sample *dst, const void *src, int samples) {struct st_sample *out = dst;IN_T *in = (IN_T *) src; -#ifdef CONFIG_MIXEMU -if (vol->mute) { -mixeng_clear (dst, samples); -return ; - } -#else - (void ) vol; -#endif +while (samples--) { - out->l =VOL (glue (conv_,ET ) (in[0 ]), vol->l); + out->l =glue (conv_,ET ) (in[0 ]); out->r = out->l; out +=1 ; in +=1 ;@@ -174,4 +150,3 @@ static void glue (glue (clip_, ET), _from_mono)#undef ET#undef HALF -#undef VOLaudio/ossaudio.c index renamed from audio/ossaudio.c +0
-00439ef5..1fda519 100644
audio/ossaudio.c static int oss_run_in (HWVoiceIn *hw) · line 787
Quoted 4 lines
audio/ossaudio.c +0
-1@@ -784,8 +784,7 @@ static int oss_run_in (HWVoiceIn *hw) hw->info.align + 1); } read_samples += nread >> hwshift; - hw->conv (hw->conv_buf + bufs[i].add, p, nread >>
hwshift,
Quoted 10 lines
audio/ossaudio.c +2
-1- &nominal_volume); + hw->conv (hw->conv_buf + bufs[i].add, p, nread >> + hwshift); } if (bufs[i].len - nread) { diff --git a/audio/paaudio.c
b/audio/paaudio.cindex ff71dac..9cf685d 100644
audio/paaudio.c static void *qpa_thread_in (void *arg) · line 198
Quoted 4 lines
audio/paaudio.c +0
-1@@ -195,7 +195,7 @@ static void *qpa_thread_in (void *arg)return NULL ; } - hw->conv (hw->conv_buf + wpos, buf, chunk,
&nominal_volume);
audio/spiceaudio.c static int line_in_run (HWVoiceIn *hw) · line 271
Quoted 13 lines
audio/paaudio.c +1
-0+ hw->conv (hw->conv_buf + wpos, buf, chunk); wpos = (wpos + chunk) % hw->samples; to_grab -= chunk; }audio/spiceaudio.c index renamed from audio/spiceaudio.c +0
-0373e4c4..a5c0d6b 100644
audio/spiceaudio.c +0
-1@@ -268,11 +268,10 @@ static int line_in_run (HWVoiceIn *hw) len[1 ] =0 ; } - hw->conv (hw->conv_buf + hw->wpos, samples, len[0],
&nominal_volume);
Quoted 14 lines
audio/spiceaudio.c +2
-2+ hw->conv (hw->conv_buf + hw->wpos, samples, len[0 ]);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 ]); } hw->wpos = (hw->wpos + num_samples) % hw->samples; diff --git
a/audio/winwaveaudio.cb/audio/winwaveaudio.cindex cdf483b..e5ad3c6 100644
audio/winwaveaudio.c static int winwave_run_in (HWVoiceIn *hw) · line 583
Quoted 3 lines
audio/winwaveaudio.c +0
-0@@ -581,8 +581,7 @@ static int winwave_run_in (HWVoiceIn *hw)int conv =audio_MIN (left, decr); hw->conv (hw->conv_buf + hw->wpos, advance (wave->pcm_buf, wave->rpos <<
hw->info.shift),
Quoted 6 lines
audio/winwaveaudio.c +1
-2- conv, - &nominal_volume); + conv); wave->rpos = (wave->rpos + conv) % hw->samples; hw->wpos = (hw->wpos + conv) % hw->samples;
[Qemu-devel] Re: [PATCH] audio: split sample conversion and volumemixing
Hi Wolfgang,
Quoted 4 lines
The fixed point path for scaling in
mixeng_volume()seems to be under by a factor of two, IMHO. The right shift should be by 31, not 32. (Because the volume, which I assume is a signed 32 bit integer, can be 0.5 at most).
I must admit i just copied the shift from the original define. But the volume and the samples are signed 64bit values.
@malc: any comments on this?
Quoted 1 line
Does the code work with
FLOAT_MIXENGundefined?
At least for my input voice, it works with integer arithmetic.
Signature · 1 line
Michael
[Qemu-devel] Re: [PATCH] audio: split sample conversion and volumemixing
Quoted 11 lines · Michael Walle
Hi Wolfgang,
Quoted 4 lines
The fixed point path for scaling in
mixeng_volume()seems to be under by a factor of two, IMHO. The right shift should be by 31, not 32. (Because the volume, which I assume is a signed 32 bit integer, can be 0.5 at most).I must admit i just copied the shift from the original define. But the volume and the samples are signed 64bit values.
@malc: any comments on this?
I don't understand the problem, the result of multiplication is converted from 32.32 fixed point to integer by shifting right by 32.. It escapes me how 31 fits here.
Quoted 5 lines
Quoted 2 lines
Does the code work with
FLOAT_MIXENGundefined?At least for my input voice, it works with integer arithmetic.
Signature · 1 line
mailto:[email protected]
[Qemu-devel] RE: [PATCH] audio: split sample conversion and volumemixing
Ah, I assumed that the volume would be stored in a 32 bit integer, and be represented as a signed Q31 fixed point. Sorry for the noise.
- Wolfgang
-----Original Message-----
From: malc [mailto:[email protected]]
Sent: Wednesday, January 12, 2011 12:15 AM
To: Michael Walle
Cc: Schildbach, Wolfgang; Jan Kiszka; [email protected]
Subject: Re: [PATCH] audio: split sample conversion and volumemixing
Quoted 6 lines · Michael Walle
Hi Wolfgang,
Quoted 2 lines
The fixed point path for scaling in
mixeng_volume()seems to be under by a factor of two, IMHO. The right shift should be by 31, not
Quoted 7 lines
Quoted 2 lines
32. (Because the volume, which I assume is a signed 32 bit integer, can be 0.5 at most).
I must admit i just copied the shift from the original define. But the
volume and the samples are signed 64bit values.
@malc: any comments on this?
I don't understand the problem, the result of multiplication is converted from 32.32 fixed point to integer by shifting right by 32.. It escapes me how 31 fits here.
Quoted 5 lines
Quoted 2 lines
Does the code work with
FLOAT_MIXENGundefined?At least for my input voice, it works with integer arithmetic.
--
mailto:[email protected]
malc
Applied[Qemu-devel] Re: [PATCH] audio: split sample conversion and volume mixing
In reply to Michael WalleQuoted 3 lines · Michael Walle
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.
Thanks, applied.
[..snip..]
Signature · 1 line
mailto:[email protected]