public void play(byte[] b, int length, int offset) {

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

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


			int step = ((finalFreq) / (sampleRate >> 8));
			// System.out.println("Step=" + step);

			for (int r = offset; r < offset + length; r++) {
				boolean value = randomValues[((cycleOffset ) + (cyclePos >> 8)) & 0x7FFF];
				int v = value? (amplitude / 2): (-amplitude / 2);

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

				cyclePos = (cyclePos + step) % cycleLength;
			}

			/*
   for (int r = offset; r < offset + length; r++) {
    val = (int) ((Math.random() * amplitude * 2) - 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;

   }*/
		}
	}