// Channel 3
if (chanOn[2])
{
static double polarity[] = { -1, -0.8667, -0.7334, -0.6, -0.4668, -0.3335, -0.2, -0.067, 0.0664, 0.2, 0.333, 0.4668, 0.6, 0.7334, 0.8667, 1 } ;
if (chanVol[2] != 0)
{
// Read the sample from ram
int wavTone = ioRam[0x30+(chan3WavPos/2)];
wavTone = chan3WavPos%2? wavTone&0xF : wavTone>>4;
// Add the sample to the output
if (chanToOut1[2])
toneSO1 += (polarity[wavTone])*(0xF >> (chanVol[2]-1));
if (chanToOut2[2])
toneSO2 += (polarity[wavTone])*(0xF >> (chanVol[2]-1));
}
chanPolarityCounter[2] -= cycles;
// Update polarity
if (chanPolarityCounter[2] <= 0)
{
chanPolarityCounter[2] = clockSpeed/(65536/(2048-chanFreq[2])*32);
chan3WavPos++;
if (chan3WavPos >= 32)
chan3WavPos = 0;
}
// Check that it hasn't timed out
if (chanUseLen[2])
{
chanLenCounter[2] -= cycles;
if (chanLenCounter[2] <= 0)
{
chanOn[2] = 0;
chanPolarityCounter[2] = 0;
clearChan3();
}
}
}