I might repeat stuff already said, but for clarity purposes, here I go:
To change the rpm you need to accelerate (or decelerate) the crankshaft assembly. To get an accelation, you rely on good old F = ma; or in rotation:
\tau_{in} - \tau_{out} = I\alpha (
reference)
\tau_{out} is the torque needed to maintain the load put on the engine and \tau_{in} is the torque due to the pressure exerted on the piston (minus the losses).
If they are both equal, then \alpha = 0. Otherwise, the rotational acceleration \alpha becomes either negative or positive, leading to a reduction or an increase of the rpm.
What we can control and vary is \tau_{in}.
Here is a mathematical definition of \tau_{in}:
\tau_{in} = BMEP\frac{V_d}{\theta_c} (
reference)
BMEP = Brake Mean Effective Pressure;
V_d = Volume of air displaced for one cycle (displacement);
\theta_c = crankshaft angular duration of one cycle.
Knowing that the Brake Specific Fuel Consumption (BSFC) can be defined by:
BSFC = \frac{\rho_{atm}VE}{AFR \times BMEP} (
reference)
\rho_{atm} = atmospheric air density;
VE = Volumetric Efficiency;
AFR = Air-Fuel Ratio.
Replacing BMEP, we get for \tau_{in}:
\tau_{in} = \frac{\rho_{atm}}{BSFC}\frac{VE}{AFR}\frac{V_d}{\theta_c}
This equation gives us all the parameters that affect the torque of the engine:
\rho_{atm}: It is a given so it cannot be controlled by the operator;
BSFC: It depends on the design and construction of the engine (thermodynamic cycle, friction losses, combustion efficiency, etc) so it cannot be controlled by the operator;
That leaves us with 4 different ways to control the input torque of the engine (in other words, how to change its rpm):
VE: We can achieve that by restricting the airflow. Less air means less air-fuel mixture, hence less energy released during combustion.
This is what happens in a gasoline engine when we control the throttle with the gas pedal while keeping the AFR constant;
AFR: We can achieve that by controlling the fuel input, while keeping the air inlet (or VE) constant.
This is what happens in a diesel engine when we control the fuel pump with the gas pedal.
\theta_c: We can achieve that by varying the length of a cycle.
This is the control used in a hit-and-miss engine. The intake valve stays close as long as needed to prevent the air-fuel mixture to enter the cylinder, hence lengthening the cycle (in number of revolutions of the crankshaft).
V_d: We could achieved that method by varying the displacement of the engine. For example, by cancelling intake valve overture for certain cylinders when we want to decrease the torque. Although, I never heard of any engine working this way (
Variable-displacement engine are close, but the objective is not to control the torque of the engine).
Other parameters can slightly vary (ignition advance, compression ratio, stoiechiometric AFR (in gasoline engine), etc.) but their purpose is not to control the torque input, but to achieve optimization of the combustion under a given circumstance.
For example, a rich AFR will give more power and a poor AFR will give better fuel economy, and this at any rpm. So it is typical to set a poor mixture at idle (who needs power at that rpm?) and to get the richest mixture at high rpm (why would you go all the way to the max rpm if you didn't want all the power you can get?). But all of this has nothing to do with controlling the torque input of your engine.