Literature
J.V. Jose, E.J. Saletan, “Classical dynamics”, Sec. 3.3
H. Goldstein, C. Poole, J. Safko, “Classical mechanics”, Sec. 1.5
A harmonic oscillator with damping
Let's assume a harmonic oscillator that encounters some resistance during its motion. This can be represented by force $f_\tau = -\lambda\dot{x}$, where $\lambda$ is a positive constant. (The $f_\tau$ provides acceleration opposite to the speed.)
This friction force must be added to the right side of the motion equation,
$$ m\ddot{x} = -kx + f_\tau \Rightarrow m\ddot{x} = -kx - \lambda\dot{x}. $$
The solution is of the form $x(t) = C e^{\mu t}$ and we have the condition
$$ m \mu^2 + \lambda \mu + k = 0 \Rightarrow \mu = \frac{-\lambda \pm \sqrt{\lambda^2 - 4 m k}}{2m}. $$
For small damping parameter, $\lambda^2 < 4 mk$, we have
$$ \mu = -\alpha \pm i \omega, \qquad \alpha \equiv \frac{\lambda}{2m},\quad \omega \equiv \frac{\sqrt{4mk - \lambda^2}}{2m} $$
and the solution is
$$ x(t) = C e^{-\alpha t}\,e^{\pm i\omega t}. $$
[It represents an oscillation with decreasing amplitude.]
Energy changes over time according to
$$ \frac{dE}{dt} = \frac{d}{dt} \left(\frac{1}{2}\, m \dot{x}^2 + \frac{1}{2}\, k x^2 \right) = m \dot{x} \ddot{x} + k x \dot{x} = (m \ddot{x} + k x) \dot{x} = -\lambda \dot{x}^2 < 0. $$
Remark. Energy decreases over time regardless of the detailed temporal evolution of the system (we don't know the solution $x(t)$). So we confirm that the term we added to our original equation is truly a damping term.