public static void apu_update(int chip) {

        int accum;
        int endp = sound_scalebufferpos(samps_per_sync);
        int elapsed;

        cur = APU[chip];
        buffer16 = new ShortPtr(cur.buffer);

        /* Recall last position updated and restore pointers */
        elapsed = cur.buf_pos;
        buffer16.offset += (elapsed * 2);

        while (elapsed < endp) {
            elapsed++;

            accum = apu_square(cur.squ[0]);
            accum += apu_square(cur.squ[1]);
            accum += apu_triangle(cur.tri);
            accum += apu_noise(cur.noi);
            accum += apu_dpcm(cur.dpcm);

            /* 8-bit clamps */
            if (accum > 127) {
                accum = 127;
            } else if (accum < -128) {
                accum = -128;
            }

            //* (buffer16++) = accum << 8;
            buffer16.write(0, (short) (accum << 8));
            buffer16.offset += 2;
        }
        cur.buf_pos = endp;
    }