diff --git a/Cavern/Channels/SpatialRemapping.cs b/Cavern/Channels/SpatialRemapping.cs
index 8edd04f6..ed0d48b4 100644
--- a/Cavern/Channels/SpatialRemapping.cs
+++ b/Cavern/Channels/SpatialRemapping.cs
@@ -2,6 +2,7 @@
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Text;
+using System.Xml;
using Cavern.Utilities;
@@ -97,6 +98,39 @@ public static string ToEqualizerAPO(float[][] matrix) {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string ToEqualizerAPO(Channel[] playedContent) => ToEqualizerAPO(GetMatrix(playedContent));
+ ///
+ /// Convert a spatial remapping matrix to an XML file.
+ ///
+ public static string ToXML(float[][] matrix) {
+ StringBuilder result = new StringBuilder();
+ using XmlWriter writer = XmlWriter.Create(result);
+ writer.WriteStartElement("matrix");
+ for (int output = 0; output < matrix.Length; output++) {
+ float[] inputs = matrix[output];
+ writer.WriteStartElement("output");
+ writer.WriteAttributeString("channel", output.ToString());
+ for (int input = 0; input < inputs.Length; input++) {
+ if (inputs[input] != 0) {
+ writer.WriteStartElement("input");
+ writer.WriteAttributeString("channel", input.ToString());
+ writer.WriteAttributeString("gain", inputs[input].ToString(CultureInfo.InvariantCulture));
+ writer.WriteEndElement();
+ }
+ }
+ writer.WriteEndElement();
+ }
+ writer.WriteEndElement();
+ writer.Flush();
+ return result.ToString();
+ }
+
+ ///
+ /// Create an XML file that describes a matrix mix that mixes the to the user-set
+ /// of the current system.
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static string ToXML(Channel[] playedContent) => ToXML(GetMatrix(playedContent));
+
///
/// Create a that is 1 at the channel's index and 0 everywhere else.
///
diff --git a/Tests/Test.Cavern/Channels/SpatialRemapping_Tests.cs b/Tests/Test.Cavern/Channels/SpatialRemapping_Tests.cs
index 9fffde4f..3bce9094 100644
--- a/Tests/Test.Cavern/Channels/SpatialRemapping_Tests.cs
+++ b/Tests/Test.Cavern/Channels/SpatialRemapping_Tests.cs
@@ -26,6 +26,19 @@ public void Remap5Point1() {
TestUtils.AssertNumberOfZeros(matrix, 28);
}
+ ///
+ /// Tests if remapping 2.0 is done correctly and converted to the valid XML output.
+ ///
+ [TestMethod, Timeout(1000)]
+ public void RemapQuadroXML() {
+ const string expected = "";
+ string result = SpatialRemapping.ToXML(SpatialRemapping.GetMatrix(ChannelPrototype.ToLayout(ChannelPrototype.ref200),
+ ChannelPrototype.ToLayoutAlternative(ChannelPrototype.ref200)));
+ Assert.AreEqual(expected, result);
+ }
+
///
/// Tests if remapping 7.1 is done correctly to 5.1.2 and converted to the valid Equalizer APO line.
///