As the topic says, it'sThis is a very simple Forfor
loop doing that, but iI find it very, complex looking, and-looking. I hope you can give me some insight on how it may be improved.
int Tindex = 0;
int16_t Test[960];
int TestSize = SampleSize / 2; //Test is 16Bit, Half size of 32bit
int TestChannels = 2; //Stereo
float copy = 0; //Used to store Audio data used to Mixdown to Mono
bool left = true; //Only use Left Channel
bool MixMono = true; //MixMono has priority over left
if (MixMono || left) //Change the approprite variables if it's Mono instead of Stereo
{
int16_t Test[960 / 2];
TestSize = TestSize / 2; //If Mono is used, Half Channel/Size.
TestChannels = 1; //Mono
}
int ChannelCheck = 0;
for (int i = 0; i < bufferSize; i += 1) //For Loop for Downmixing and BitDepth Conversion
{
int s = (micBuffer[i] * 32768.0f); //32bit Float to 16Bit Int
ChannelCheck++;
if (MixMono)//Mixdown Stereo to Mono
{
copy += s;
if (ChannelCheck == 2)
{
Test[Tindex] = copy / 2;
copy = 0;
Tindex++;
ChannelCheck = 0;
}
}
else if (left)
{
if (ChannelCheck == 1)
{
Test[Tindex] = s;
ChannelCheck -= 2;
Tindex++;
}
}
else
{
Test[Tindex] = s;
Tindex++;
}
}
//End of For Loop
I tried commenting most stuff, so it should be self explained-explained.
PrettyIt's pretty much it's just, Mix Stereoa mix stereo to Mono = Combinemono. It combines 2 indexesindices from the floatfloat
array (add them), then divide them (to keep the correct volume).
16bit Conversion,16-bit conversion just multiplymultiplies by Int16 Max,Max; not much there (Would. I would like to have some kind of dithering, so if anyone knowknows some easy references, please link, or give suggestions)offer them.
But as you can see, it's overly complicated with checks all over the place, i. I think it can be improved, but iI can't really figure out a good way to do it.
Any and all suggestions are appreciated!