audio: Add winaudio as an alternative audio backend for Windows

QEMU's default audio backend for Windows, winwave, does not work well
with the goldfish audio device when audio input is enabled. The classic
Android emulator does not use winwave, but introduces its own Windows
audio backend called winaudio. This patch adapts winaudio for QEMU 2.x
and makes it available as an alternative audio backend for Windows.

Change-Id: I2da855957035b6d95bdf6e0044a3e807b769abf2
Signed-off-by: Yu Ning <yu.ning@intel.com>
diff --git a/audio/Makefile.objs b/audio/Makefile.objs
index 26a0ac9..b495cb4 100644
--- a/audio/Makefile.objs
+++ b/audio/Makefile.objs
@@ -9,6 +9,7 @@
 common-obj-$(CONFIG_ESD) += esdaudio.o
 common-obj-$(CONFIG_PA) += paaudio.o
 common-obj-$(CONFIG_WINWAVE) += winwaveaudio.o
+common-obj-$(CONFIG_WINAUDIO) += winaudio.o
 common-obj-$(CONFIG_AUDIO_PT_INT) += audio_pt_int.o
 common-obj-$(CONFIG_AUDIO_WIN_INT) += audio_win_int.o
 common-obj-y += wavcapture.o
diff --git a/audio/audio_int.h b/audio/audio_int.h
index fd019a0..031eb6e 100644
--- a/audio/audio_int.h
+++ b/audio/audio_int.h
@@ -214,6 +214,7 @@
 extern struct audio_driver pa_audio_driver;
 extern struct audio_driver spice_audio_driver;
 extern struct audio_driver winwave_audio_driver;
+extern struct audio_driver winaudio_audio_driver;
 extern const struct mixeng_volume nominal_volume;
 
 void audio_pcm_init_info (struct audio_pcm_info *info, struct audsettings *as);
diff --git a/audio/winaudio.c b/audio/winaudio.c
index faaffb7..e4fea22 100644
--- a/audio/winaudio.c
+++ b/audio/winaudio.c
@@ -2,6 +2,7 @@
  * QEMU "simple" Windows audio driver
  *
  * Copyright (c) 2007 The Android Open Source Project
+ * Copyright (c) 2015 Intel Corporation
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -21,13 +22,17 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-#include <mmsystem.h>
+
+#include "qemu-common.h"
+#include "sysemu/sysemu.h"
+#include "audio.h"
 
 #define AUDIO_CAP "winaudio"
 #include "audio_int.h"
 
+#include <windows.h>
+#include <mmsystem.h>
+
 /* define DEBUG to 1 to dump audio debugging info at runtime to stderr */
 #define  DEBUG  0
 
@@ -544,7 +549,7 @@
                __FUNCTION__, s->read_index, s->read_pos, s->read_size, wav_samples, wav_bytes, live,
                hw->wpos, hw->samples);
 
-            hw->conv(dst, src, wav_samples, &nominal_volume);
+            hw->conv(dst, src, wav_samples);
 
             hw->wpos += wav_samples;
             if (hw->wpos >= hw->samples)
@@ -650,16 +655,16 @@
     winaudio_in_ctl
 };
 
-struct audio_driver win_audio_driver = {
-    INIT_FIELD (name           = ) "winaudio",
-    INIT_FIELD (descr          = ) "Windows wave audio",
-    INIT_FIELD (options        = ) winaudio_options,
-    INIT_FIELD (init           = ) winaudio_init,
-    INIT_FIELD (fini           = ) winaudio_fini,
-    INIT_FIELD (pcm_ops        = ) &winaudio_pcm_ops,
-    INIT_FIELD (can_be_default = ) 1,
-    INIT_FIELD (max_voices_out = ) 1,
-    INIT_FIELD (max_voices_in  = ) 1,
-    INIT_FIELD (voice_size_out = ) sizeof (WinAudioOut),
-    INIT_FIELD (voice_size_in  = ) sizeof (WinAudioIn)
+struct audio_driver winaudio_audio_driver = {
+    .name           = "winaudio",
+    .descr          = "Windows wave audio",
+    .options        = winaudio_options,
+    .init           = winaudio_init,
+    .fini           = winaudio_fini,
+    .pcm_ops        = &winaudio_pcm_ops,
+    .can_be_default = 1,
+    .max_voices_out = 1,
+    .max_voices_in  = 1,
+    .voice_size_out = sizeof (WinAudioOut),
+    .voice_size_in  = sizeof (WinAudioIn)
 };
diff --git a/configure b/configure
index da4ce05..9b7701f 100755
--- a/configure
+++ b/configure
@@ -560,7 +560,7 @@
 ;;
 MINGW32*)
   mingw32="yes"
-  audio_possible_drivers="winwave dsound sdl fmod"
+  audio_possible_drivers="winwave dsound sdl fmod winaudio"
   audio_drv_list="winwave"
 ;;
 GNU/kFreeBSD)
@@ -2579,6 +2579,10 @@
       audio_win_int="yes"
     ;;
 
+    winaudio)
+      libs_softmmu="-lwinmm $libs_softmmu"
+    ;;
+
     *)
     echo "$audio_possible_drivers" | grep -q "\<$drv\>" || {
         error_exit "Unknown driver '$drv' selected" \