Index: /trunk/include/VBox/settings.h
===================================================================
--- /trunk/include/VBox/settings.h	(revision 56515)
+++ /trunk/include/VBox/settings.h	(revision 56516)
@@ -696,4 +696,5 @@
         : fEnabled(true),
           controllerType(AudioControllerType_AC97),
+          codecType(AudioCodecType_STAC9700),
           driverType(AudioDriverType_Null)
     {}
@@ -704,4 +705,5 @@
                 || (    (fEnabled        == a.fEnabled)
                      && (controllerType  == a.controllerType)
+                     && (codecType       == a.codecType)
                      && (driverType      == a.driverType)
                      && (properties      == a.properties)
@@ -711,4 +713,5 @@
     bool                    fEnabled;
     AudioControllerType_T   controllerType;
+    AudioCodecType_T        codecType;
     AudioDriverType_T       driverType;
     settings::StringsMap properties;
Index: /trunk/src/VBox/Main/src-server/AudioAdapterImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/src-server/AudioAdapterImpl.cpp	(revision 56515)
+++ /trunk/src/VBox/Main/src-server/AudioAdapterImpl.cpp	(revision 56516)
@@ -33,5 +33,6 @@
         mEnabled(false),
         mAudioDriver(AudioDriverType_Null),
-        mAudioController(AudioControllerType_AC97)
+        mAudioController(AudioControllerType_AC97),
+        mAudioCodec(AudioCodecType_STAC9700)
     {}
 
@@ -507,4 +508,5 @@
     mData->m->mEnabled = data.fEnabled;
     mData->m->mAudioController = data.controllerType;
+    mData->m->mAudioCodec = data.codecType;
     mData->m->mAudioDriver = data.driverType;
 
@@ -535,4 +537,5 @@
     data.fEnabled = !!mData->m->mEnabled;
     data.controllerType = mData->m->mAudioController;
+    data.codecType = mData->m->mAudioCodec;
     data.driverType = mData->m->mAudioDriver;
 
Index: /trunk/src/VBox/Main/xml/Settings.cpp
===================================================================
--- /trunk/src/VBox/Main/xml/Settings.cpp	(revision 56515)
+++ /trunk/src/VBox/Main/xml/Settings.cpp	(revision 56516)
@@ -2651,4 +2651,36 @@
     }
 
+    if (elmAudioAdapter.getAttributeValue("codec", strTemp))
+    {
+        if (strTemp == "SB16")
+            aa.codecType = AudioCodecType_SB16;
+        else if (strTemp == "STAC9700")
+            aa.codecType = AudioCodecType_STAC9700;
+        else if (strTemp == "AD1980")
+            aa.codecType = AudioCodecType_AD1980;
+        else if (strTemp == "STAC9221")
+            aa.codecType = AudioCodecType_STAC9221;
+        else
+            throw ConfigFileError(this, &elmAudioAdapter, N_("Invalid value '%s' in AudioAdapter/@codec attribute"), strTemp.c_str());
+    }
+    else
+    {
+        /* No codec attribute provided; use defaults. */
+        switch (aa.controllerType)
+        {
+            case AudioControllerType_AC97:
+                aa.codecType = AudioCodecType_STAC9700;
+                break;
+            case AudioControllerType_SB16:
+                aa.codecType = AudioCodecType_SB16;
+                break;
+            case AudioControllerType_HDA:
+                aa.codecType = AudioCodecType_STAC9221;
+                break;
+            default:
+                Assert(false);  /* We just checked the controller type above. */
+        }
+    }
+
     if (elmAudioAdapter.getAttributeValue("driver", strTemp))
     {
@@ -4716,4 +4748,31 @@
     }
     pelmAudio->setAttribute("controller", pcszController);
+
+    const char *pcszCodec;
+    switch (hw.audioAdapter.codecType)
+    {
+        /* Only write out the setting for non-default AC'97 codec
+         * and leave the rest alone.
+         */
+#if 0
+        case AudioCodecType_SB16:
+            pcszCodec = "SB16";
+            break;
+        case AudioCodecType_STAC9221:
+            pcszCodec = "STAC9221";
+            break;
+        case AudioCodecType_STAC9700:
+            pcszCodec = "STAC9700";
+            break;
+#endif
+        case AudioCodecType_AD1980:
+            pcszCodec = "AD1980";
+            break;
+        default:
+            /* Don't write out anything if unknown. */
+            pcszCodec = NULL;
+    }
+    if (pcszCodec)
+        pelmAudio->setAttribute("codec", pcszCodec);
 
     if (m->sv >= SettingsVersion_v1_10)
