public int getSample()
    {
        if (!enabled) return 0;

        // Decrement Counter
        counter -= psg_cycles;

        // Counter Expired
        if (counter < 0)
        {
            // Toggle Amplitude Flip Flop
            amplitude_flipflop = !amplitude_flipflop;

            // Reload counter
            while (counter < 0)
            {
                if (frequency > 0)
                    counter+=frequency;
                else
                    counter=1; // so we don't get stuck in an endless loop
            }
        }

        int output_volume = 15 - (volume&0x0F); // ie 0 is 15, 1 is 14 etc

        // Real SMS Only Outputs Values Over 4?
        if (frequency > 4)
        {
            if (amplitude_flipflop)
                return +output_volume;
            else
                return -output_volume;
        }
        else
            return 0;
    }