{
int i, j;
for (i = 0; i < s3m_numChans; i++)
{
if (ch[i].data != NULL)
{
for (j = 0; j < numSamples; j++)
{
if (ch[i].stereo)
{
float smpL, smpR;
if (interpolation)
{
float smp1_L = (float)ch[i].data[ch[i].index];
float smp1_R = (float)ch[i].data[ch[i].len + ch[i].index];
float smp2_L, smp2_R;
if (ch[i].loopLen >= 2)
{
if (ch[i].index >= (ch[i].loopEnd - 1))
{
smp2_L = (float)ch[i].data[ch[i].loopEnd - ch[i].loopLen];
smp2_R = (float)ch[i].data[ch[i].len + ch[i].loopEnd - ch[i].loopLen];
}
else
{
smp2_L = (float)ch[i].data[ch[i].index + 1];
smp2_R = (float)ch[i].data[ch[i].len + ch[i].index + 1];
}
}
else
{
if (ch[i].index >= (ch[i].len - 1))
{
smp2_L = 0.0f;
smp2_R = 0.0f;
}
else
{
smp2_L = (float)ch[i].data[ch[i].index + 1];
smp2_R = (float)ch[i].data[ch[i].len + ch[i].index + 1];
}
}
smpL = (smp1_L + (smp1_L - smp2_L) * ch[i].frac) * ch[i].vol;
smpR = (smp1_R + (smp1_R - smp2_R) * ch[i].frac) * ch[i].vol;
}
else
{
smpL = (float)ch[i].data[ch[i].index] * ch[i].vol;
smpR = (float)ch[i].data[ch[i].len + ch[i].index] * ch[i].vol;
}
masterBufferL[j] += (smpL * ch[i].panL);
masterBufferR[j] += (smpR * ch[i].panR);
ch[i].frac += ch[i].incRate;
if (ch[i].frac >= 1.0f)
{
ch[i].index += (int)ch[i].frac;
ch[i].frac -= (int)ch[i].frac;
if (ch[i].loopLen >= 2)
{
if (ch[i].index >= ch[i].loopEnd)
ch[i].index -= ch[i].loopLen;
}
else if (ch[i].index >= ch[i].len)
{
ch[i].data = NULL;
break;
}
}
}
else
{
float smp;
if (interpolation)
{
float smp1 = (float)ch[i].data[ch[i].index];
float smp2;
if (ch[i].loopLen >= 2)
{
if (ch[i].index >= (ch[i].loopEnd - 1))
smp2 = (float)ch[i].data[ch[i].loopEnd - ch[i].loopLen];
else
smp2 = (float)ch[i].data[ch[i].index + 1];
}
else
{
if (ch[i].index >= (ch[i].len - 1))
smp2 = 0.0f;
else
smp2 = (float)ch[i].data[ch[i].index + 1];
}
smp = (smp1 + (smp2 - smp1) * ch[i].frac) * ch[i].vol;
}
else
{
smp = (float)ch[i].data[ch[i].index] * ch[i].vol;
}
masterBufferL[j] += (smp * ch[i].panL);
masterBufferR[j] += (smp * ch[i].panR);
ch[i].frac += ch[i].incRate;
if (ch[i].frac >= 1.0f)
{
ch[i].index += (int)ch[i].frac;
ch[i].frac -= (int)ch[i].frac;
if (ch[i].loopLen >= 2)
{
if (ch[i].index >= ch[i].loopEnd)
ch[i].index -= ch[i].loopLen;
}
else if (ch[i].index >= ch[i].len)
{
ch[i].data = NULL;
break;
}
}
}
}
}
}
}