case 4: /* tone 2 : frequency */\r
R->Period[c] = R->UpdateStep * data;\r
if (R->Period[c] == 0) R->Period[c] = R->UpdateStep;\r
- R->Count[c] = 0;\r
if (r == 4)\r
{\r
/* update noise shift frequency */\r
R->NoiseFB = (n & 4) ? FB_WNOISE : FB_PNOISE;\r
n &= 3;\r
/* N/512,N/1024,N/2048,Tone #3 output */\r
- R->Period[3] = (n == 3) ? 2 * R->Period[2] : (R->UpdateStep << (4 + n));\r
- R->Count[3] = 0;\r
+ R->Period[3] = 2 * (n == 3 ? R->Period[2] : R->UpdateStep << (4 + n));\r
\r
/* reset noise shifter */\r
R->RNG = FB_PNOISE;\r
/* If we exit the loop in the middle, Output[i] has to be inverted */\r
/* and vol[i] incremented only if the exit status of the square */\r
/* wave is 1. */\r
- if (R->Count[i] < -2*R->Period[i]) {\r
+ if (R->Count[i] < -2*R->Period[i] || R->Volume[i] == 0) {\r
/* Cut of anything above the Nyquist freqency */\r
/* It will only create aliasing anyway */\r
vol[i] += STEP/2; // mean value\r
}\r
\r
left -= nextevent;\r
- } while (left > 0);\r
+ } while (left > 0 && R->Volume[3]);\r
if (R->Output[3]) vol[3] -= R->Count[3];\r
\r
out = vol[0] * R->Volume[0] + vol[1] * R->Volume[1] +\r