public void play(byte[] b, int length, int offset) {
		int val = 0;

		if (totalLength != 0) {
			totalLength--;

			if (timeSweep != 0) {
				counterSweep++;
				if (counterSweep > timeSweep) {
					if (decreaseSweep) {
						setFrequency(gbFrequency - (gbFrequency >> numSweep));
					} else {
						setFrequency(gbFrequency + (gbFrequency >> numSweep));
					}
					counterSweep = 0;
				}
			}

			counterEnvelope++;
			if (numStepsEnvelope != 0) {
				if (((counterEnvelope % numStepsEnvelope) == 0) && (amplitude > 0)) {
					if (!increaseEnvelope) {
						if (amplitude > 0) amplitude-=2;
					} else {
						if (amplitude < 16) amplitude+=2;
					}
				}
			}
			for (int r = offset; r < offset + length; r++) {

				if (cycleLength != 0) {
					if (((8 * cyclePos) / cycleLength) >= dutyCycle) {
						val = amplitude;
					} else {
						val = -amplitude;
					}
				}

				/*    if (cyclePos >= (cycleLength / 2)) {
     val = amplitude;
    } else {
     val = -amplitude;
    }*/


				if ((channel & CHAN_LEFT) != 0) b[r * 2] += val;
				if ((channel & CHAN_RIGHT) != 0) b[r * 2 + 1] += val;
				if ((channel & CHAN_MONO) != 0) b[r] += val;

				//   System.out.print(val + " ");

				cyclePos = (cyclePos + 256) % cycleLength;
			}
		}
	}