Skip to content

Commit 15139cf

Browse files
committed
Fix channel shuffling for 12 channel streams
1 parent bf6081b commit 15139cf

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

DataTool/ConvertLogic/WEM/WwiseRIFFOpus.cs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,22 +155,40 @@ public WwiseRIFFOpus(Stream stream, bool forceStereo) {
155155
WAVEChannelMask.SEVENPOINT1 => 2,
156156
_ => 0,
157157
};
158+
159+
if (DEBUGForceStereo && Header.Channels > 2) {
160+
Header.CoupledCount = 1;
161+
Header.Channels = 2;
162+
MappingFamily = 1;
163+
}
164+
158165
Header.StreamCount = Header.Channels - Header.CoupledCount;
159166

167+
Header.ChannelMapping = new byte[Header.Channels];
160168
if (MappingFamily == 1) {
161169
for (var i = 0; i < Header.Channels; i++) {
162170
Header.ChannelMapping[i] = MappingMatrix[Header.Channels - 1][i];
163171
}
164172
} else {
165-
if (DEBUGForceStereo && Header.Channels > 2) {
166-
Header.StreamCount = Header.Channels;
167-
Header.Channels = 2;
168-
MappingFamily = 1;
169-
}
170-
171-
Header.ChannelMapping = new byte[Header.Channels];
172-
for (var i = 0; i < Header.Channels; i++) {
173-
Header.ChannelMapping[i] = (byte) i;
173+
if ((Header.ChannelLayout & 8) == 0) {
174+
for (var i = 0; i < Header.Channels; i++) {
175+
Header.ChannelMapping[i] = (byte) i;
176+
}
177+
} else {
178+
for (var i = 0; i < Header.Channels; i++) {
179+
var idx = 0;
180+
for (var j = Header.ChannelLayout & 7; j > 0; j &= j - 1) {
181+
idx++;
182+
}
183+
184+
if (idx == i) {
185+
Header.ChannelMapping[i] = (byte)(idx - 1);
186+
} else if (i > idx) {
187+
Header.ChannelMapping[i] = (byte)(i - 1);
188+
} else {
189+
Header.ChannelMapping[i] = (byte) i;
190+
}
191+
}
174192
}
175193
}
176194
}

0 commit comments

Comments
 (0)