Example 4 Let $a$ be a real number, find the maximum value of the function $f(x)=|\sin x(a+\cos x)|(x \in \mathbf{R})$.
Let $\alpha$ be a parameter such that
$$\begin{aligned}
f^{2}(x) & =\frac{1}{\alpha^{2}} \sin ^{2} x(a \alpha+\alpha \cos x)^{2} \leqslant \frac{1}{\alpha^{2}} \sin ^{2} x\left(\alpha^{2}+\cos ^{2} x\right)\left(a^{2}+\alpha^{2}\right) \\
& \leqslant \frac{1}{\alpha^{2}}\left(\frac{\sin ^{2} x+\alpha^{2}+\cos ^{2} x}{2}\right)^{2}\left(a^{2}+\alpha^{2}\right)=\frac{1}{\alpha^{2}}\left(\frac{\alpha^{2}+1}{2}\right)^{2}\left(a^{2}+\alpha^{2}\right),
\end{aligned}$$

with equality holding if and only if $\alpha^{2}=a \cos x, \sin ^{2} x=\alpha^{2}+\cos ^{2} x$.
Eliminating $x$, we get $2 \alpha^{4}+a^{2} \alpha^{2}-a^{2}=0$.
Solving the equation, we get $\alpha^{2}=\frac{1}{4}\left(\sqrt{a^{4}+8 a^{2}}-a^{2}\right)$, thus $\cos x=\frac{1}{4}\left(\sqrt{a^{2}+8}-a\right)$.
Therefore, when $x=2 k \pi \pm \arccos \left[\frac{1}{4}\left(\sqrt{a^{2}+8}-a\right)\right](k \in \mathbf{Z})$,
$$f(x)_{\max }=\frac{\sqrt{a^{4}+8 a^{2}}-a^{2}+4}{8} \cdot \sqrt{\frac{\sqrt{a^{4}+8 a^{2}}+a^{2}+2}{2}} .$$