double getVoltage() {
	double w = 2*pi*(sim.t-freqTimeZero)*frequency + phaseShift;
	switch (waveform) {
	case WF_DC: return maxVoltage+bias;
	case WF_AC: return Math.sin(w)*maxVoltage+bias;
	case WF_SQUARE:
	    return bias+((w % (2*pi) > (2*pi*dutyCycle)) ?
			 -maxVoltage : maxVoltage);
	case WF_TRIANGLE:
	    return bias+triangleFunc(w % (2*pi))*maxVoltage;
	case WF_SAWTOOTH:
	    return bias+(w % (2*pi))*(maxVoltage/pi)-maxVoltage;
	case WF_PULSE:
	    return ((w % (2*pi)) < 1) ? maxVoltage+bias : bias;
	default: return 0;
	}
    }