public void flushSound(int samples) {
        sampleSize = (int) Math.min((sampleRate / samples), buffer.length / 2);
        int soundsToMix = 0;
        int sound, read, rd = 0;
        int maxRead = 0;
        byte[] rdBuff = new byte[2];
        int currSound;
        short amplitude;
        int pos = -1;
        for (int j = 0; j < sampleSize; j++) {
            soundsToMix = 0;
            currSound = 0;
            if (music != null) {
                rd = testSounds[music.sound].read(rdBuff, music.read, 2);
                if (rd <= 0) {
                    music.read = 0;
                    rd = testSounds[music.sound].read(rdBuff, music.read, 2);
                } else music.read += rd;
                soundsToMix++;
                amplitude = (short) (((rdBuff[1] & 0xFF) << 8) | rdBuff[0] & 0xFF);
                currSound += amplitude * volume;
            }
            for (int i = 0; i < playingSounds.size(); i++) {
                if (playingSounds.get(i) != null) {
                    sound = playingSounds.get(i).sound;
                    read = playingSounds.get(i).read;
                    rd = testSounds[sound].read(rdBuff, read, 2);
                    if (rd <= 0)
                        playingSounds.remove(i);
                    else {
                        playingSounds.get(i).read += 2;
                        soundsToMix++;

                        // left = rdBuff[1] & 0xFF;
                        // right = rdBuff[0] & 0xFF;

                        amplitude = (short) (((rdBuff[1] & 0xFF) << 8) | rdBuff[0] & 0xFF);

                        currSound += amplitude;
                    }
                }
            }
            if (soundsToMix <= 0)
                break;
            currSound = (int) (currSound * volume);
            if (currSound > Short.MAX_VALUE)
                currSound = Short.MAX_VALUE;
            else if (currSound < Short.MIN_VALUE)
                currSound = Short.MIN_VALUE;
            buffer[++pos] = (byte) (currSound & 0xFF);
            buffer[++pos] = (byte) ((currSound >> 8) & 0xFF);
            maxRead += rd;
        }
        outputLine.write(buffer, 0, maxRead);
        outputLine.write(emptyBuff, maxRead, sampleSize * 2 - maxRead);
    }