Running into a funny situation with my tool suite. I take multichannel ogg files (up to 18 channels) and do various things with them. Sometimes I mix channels together, sometimes I delete channels, sometimes I do a matrix and combine to stereo and play it back, or pick one of the channels to play that back, etc.
Most of the files i work with are 10 channels are more. But today I came across two 8 channel files and i realized there's a bug either with my code or with BASS. Probably my code, hence why i'm here.
First image is the input file. Second image is the output file. As you can see, the audio has been shifted two channels down. That creates all kinds of problems for me and my users.
(these images are something to my tool suite creates using BASS to visualize the contents of the given .ogg file)
I understand that per Ogg Vorbis spec up to 8 channels is used for 7.1 audio and the channels are rearranged. That's why I had this bit of code that I "thought" was working but I guess not?
public int[] ArrangeStreamChannels(int totalChannels, bool isOgg)
{
var channels = new int[totalChannels];
if (isOgg)
{
switch (totalChannels)
{
case 3:
channels[0] = 0;
channels[1] = 2;
channels[2] = 1;
break;
case 5:
channels[0] = 0;
channels[1] = 2;
channels[2] = 1;
channels[3] = 3;
channels[4] = 4;
break;
case 6:
channels[0] = 0;
channels[1] = 2;
channels[2] = 1;
channels[3] = 4;
channels[4] = 5;
channels[5] = 3;
break;
case 7:
channels[0] = 0;
channels[1] = 2;
channels[2] = 1;
channels[3] = 4;
channels[4] = 5;
channels[5] = 6;
channels[6] = 3;
break;
case 8:
channels[0] = 0;
channels[1] = 2;
channels[2] = 1;
channels[3] = 4;
channels[4] = 5;
channels[5] = 6;
channels[6] = 7;
channels[7] = 3;
break;
default:
goto DoAllChannels;
}
return channels;
}
DoAllChannels:
for (var i = 0; i < totalChannels; i++)
{
channels[i] = i;
}
return channels;
}
Applying that channel arrangement to the matrix leaves me with the second image as a result.
So I thought, if i'm doing 1:1 exporting just changing the quality of the audio (that's the use case for this scenario) then why not just go 1:1 with the channels. Didn't work.
So then I thought, again, if i'm not rearranging channels, why not skip the step altogether for adding a channel matrix and just create the stream and then output to disk? Didn't work. It's like, once the audio comes in, it's automatically scrambled and I HAVE to fix it. But I don't know how to fix it. Here's the relevant BASS code:
UPDATED CODE BELOWI'm about to declare this a BUG that can't be fixed. But I figured I would ask here again since you've all been so helpful. Thanks!
EDIT: I'm fairly confident the error is not with the ArrangeChannels code because if I modify that code, then all other applications that rely on it break, including the one that creates the images. The images are 1:1 accurate to what Audacity puts out (not quite in wave form accuracy but channel data and channel order). But if i input the ogg and export the ogg, bam, channels are scrambled. Thoughts?