private double getSample() {
        double value;
        double phase = sampleNumber / (double) samplesPerPeriod;

        switch (waveform) {
            default:
            case SIN:
                value = Math.sin(2.0 * Math.PI * phase);
                break;
            case TRI:
                value = (2.0 * Math.sin(Math.sin(2.0 * Math.PI * phase))) / Math.PI;
                break;
            case SQU:
                if(phase > pulseWidth) {
                    value = 0.0;
                }
                else {
                    value = 1.0;
                }
                break;
            case SAW:
                value = phase - Math.floor(phase);
                break;
        }

        sampleNumber = (sampleNumber + 1) % samplesPerPeriod;

        return value;
    }