public long getDelay(Frame frame) {
        if(frame == null)
            throw new IllegalArgumentException("Null frame given as argument");
		frames = (frames + 1) % framesBetweenSync;
		if(frames == 1) {
			accumulatedTime = System.currentTimeMillis();
			synchronizationTime = accumulatedTime;
		}
		accumulatedTime += frame.getSize() * 8 / frame.getBitrate();
		switch(mode) {
		case 'B':
			saturator = 0.0f;
			break;
		case 'E':
			if(frames != 0)
				saturator = +(frameBufferSize / 8) * (accumulatedTime - synchronizationTime) / frames;
			break;
		case 'F':
			if(frames != 0)
				saturator = -(frameBufferSize / 8) * (accumulatedTime - synchronizationTime) / frames;
			break;
		}
		delay = accumulatedTime - System.currentTimeMillis() + saturator;
		if(delay > 0)
			return (long)delay;
		return 0;
	}