1. An image forming apparatus comprising: an image-bearing member; a charging member configured to charge the image-bearing member by receiving a charge voltage in which a direct-current voltage and an alternating-current voltage are superposed on each other; a power source configured to apply a voltage to the charging member; a toner-image forming unit configured to form a toner image on the image-bearing member charged by the charging member; a detector configured to detect a current flowing through the charging member when the power source applies the charge voltage to the charging member; an extraction unit configured to extract, from the current detected by the detector when the charge voltage is applied to the charging member, a current in a frequency band including a discharge current component; an adjustment unit configured to adjust the alternating-current voltage based on the current extracted by the extraction unit; an acquisition unit configured to acquire environmental information; and a setting unit configured to set, based on the environmental information acquired by the acquisition unit, a frequency band for extraction performed by the extraction unit.