approximation of integral of $|\cos x|^p$ Let $p\in [1,2)$. Let
$$
\beta = \frac{1}{2\pi}\int_0^{2\pi} |\cos x|^p\, dx = \frac{\Gamma(\frac{p+1}{2})}{\sqrt{\pi}\Gamma(1+\frac{p}{2})}.
$$
Consider the following approximation to the integral definition of $\beta$:
$$
S_n = \frac{1}{2n}\sum_{k=0}^{2n-1} \left| \cos\left(2\pi \cdot \frac{k}{2n}\right)\right|^p.
$$
We are interested in the asymptotics of the approximation error
$$
|S_n - \beta|.
$$
I have found empirically that
$$
|S_n - \beta| \leq \frac{c_p}{n^{p+1}}
$$
where $c_p$ is a constant that depends only on $p$ and $c_p\to 0$ as $p\to 2$. But I have no idea at all how to prove this. (This bound is actually tight, that is, the correct order should be $1/n^{p+1}$.)
I tried to split the integral from $0$ to $2\pi$ into $2n$ pieces and sum up the approximation errors in each piece, which only gives an error of $O(1/n^2)$ instead of $O(1/n^{p+1})$. Can anyone shed some light on how to deal with the $p$-th power or how $p$ enters the exponent in the approximation error?

Edit: The following seems to be a proof, up to tiny boundary sloppiness that can be easily fixed.
Assume that $n$ is even and so we replace $n$ with $2n$. Note that $\cos x$ is decreasing and positive on $[0,\pi/2]$. By symmetry, it suffices to bound
\begin{align*}
E &:= \frac{1}{2n}\sum_{k=0}^{2n-1} \left|\cos\frac{\pi k}{2n}\right|^p - \frac{1}{\pi}\int_0^\pi |\cos x|^p dx\\
&= \frac{1}{2n}\sum_{k=0}^{n-1} \left(\cos^p\left(\frac{\pi k}{2n}\right) + \cos^p\left(\frac{\pi (k+1)}{2n}\right)\right) - \frac{1}{\pi}\sum_{k=0}^{n-1} 2\int_{k\pi/(2n)}^{(k+1)\pi/(2n)} \cos^p xdx  \\
&= \frac{1}{n}\sum_{k=0}^{n-1}\left[ \frac{1}{2}\left(\cos^p\left(\frac{\pi k}{2n}\right) + \cos^p\left(\frac{\pi (k+1)}{2n}\right)\right) - \frac{1}{\pi/(2n)}\int_{k\pi/(2n)}^{(k+1)\pi/(2n)} \cos^p xdx\right]\\
&=: \frac{1}{n}\sum_{k=0}^{n-1} E_k
\end{align*}
Recall the following mean-value result for the error of trapezoidal rule:
$$
\frac{1}{b-a}\int_a^b f(x)dx - \frac{f(a)+f(b)}{2} = -\frac{(b-a)^2}{12}f''(\xi)
$$
Let $f(x) = \cos^p x$, then $f'(\pi/2-\delta)\asymp \delta^{p-1}$ and $f''(\pi/2-\delta)\asymp 1/\delta^{2-p}$.
Let $\epsilon \geq 2/n$ to be determined let $K = [n\epsilon]$ so $K \geq 2$. Applying the mean-value result to the intervals corresponding to $k=0,\dots,n-K-1$, we have
$$
E = \frac{1}{n}\sum_{k=0}^{n-K-1} \frac{1}{12}\left(\frac{\pi}{2n}\right)^2 f''(\xi_k) + \frac{1}{n}\sum_{k=n-K}^{n-1} E_k 
=: A + B.
$$
where $\xi_k \in [k\pi/(2n), (k+1)\pi/(2n)]$.
Write $A$ as
$$
A = \frac{\pi}{24n^2} \sum_{k=0}^{n-K-1} f''(\xi_k)\frac{\pi}{2n} =: \frac{\pi}{24n^2} A'
$$
Note that $A'$ is the Riemann sum of $\int_0^{\pi/2-\epsilon} f''(x)dx$. Also note that $f''(x)$ has a unique positive root $x_0$ in $(0,\pi/2)$ and $f''(x)$ is positive and increasing when $x\geq x_0$. We can upper bound
$$
\begin{aligned}
A' &\leq \int_0^{\pi/2-\epsilon} f''(x)dx + \frac{C_1}{n}\max_{x\in [0,x_0]}|f'''(x)| + \frac{C_2}{n}f''\left(\frac{\pi}{2}-\epsilon\right) \\
&\leq f'\left(\frac{\pi}{2}-\epsilon\right) + \frac{C_3}{n} + \frac{C_4}{n\epsilon^{2-p}} \\
&\lesssim \epsilon^{p-1} + \frac{1}{n\epsilon^{2-p}}.
\end{aligned}
$$
Next, we deal with the last term $B$. Invoke the integral estimation error from Theorem 3 of this paper, which states that, if $f'$ is absolutely continuous on $[a,b]$ and $f''\in L^\alpha(a,b)$ for some $\alpha\geq 1$, then
$$
\left|\frac{1}{b-a}\int_a^b f(x)dx - \frac{f(a)+f(b)}{2}\right| \leq C_\alpha (b-a)^{2-\frac{1}{\alpha}} \|f''\|_\alpha.
$$
Since $f''(\pi/2-\epsilon)\asymp 1/\epsilon^{2-p}$, $f''$ is $L^1$ integrable. It is clear that $E_k > 0$ when $k\geq n-K$, as $f''(\xi_k) > 0$  in this case. Applying the error bound above to $E_k$ ($k\geq n-K$), we obtain that
$$
B \lesssim \frac{1}{n^2}\int_{\pi/2-\epsilon}^{\pi/2} f''(x)dx \lesssim\frac{1}{n^2}\int_0^{\epsilon} \frac{1}{x^{2-p}}dx \lesssim \frac{\epsilon^{p-1}}{n^2}.
$$
Therefore we conclude that
$$
E \lesssim \frac{\epsilon^{p-1}}{n^2} + \frac{1}{n^3\epsilon^{2-p}}.
$$
Taking $\epsilon = \Theta(1/n)$ gives the desired result.

A "Fourier-analytic" approach, with the analysis of $n^{p+1}|S_n-\beta|$ as $n\to\infty$. Let $$
T_N(f):=\frac1N\left(\frac{f(0)+f(2\pi)}{2}+\sum_{k=1}^{N-1}f\Big(\frac{2k\pi}{N}\Big)\right),\\\Delta_N(f):=T_N(f)-\frac1{2\pi}\int_0^{2\pi}f(x)\,dx.$$ Suppose that $f(x)=\sum_{n\in\mathbb{Z}}c_n e^{inx}$ with $\sum_{n\in\mathbb{Z}}|c_n|<\infty$, then $$T_N(f)=\frac1N\sum_{k=0}^{N-1}\sum_{n\in\mathbb{Z}}c_n e^{2\pi ikn/N}=\sum_{d\in\mathbb{Z}}c_{Nd},$$ because $\sum_{k=0}^{N-1}e^{2\pi ikn/N}=0$ if $n$ is not a multiple of $N$; thus $\color{blue}{\Delta_N(f)=\sum_{d\neq 0}c_{Nd}}$. In particular, if $c_n=O(|n|^{-\alpha})$ as $n\to\pm\infty$ with $\alpha>1$, then $\Delta_N(f)=O(N^{-\alpha})$ as $N\to\infty$.

Take $f(x)=|\cos x|^p$ with $\color{blue}{p>0}$, then $c_n=0$ if $n$ is odd, and (see e.g. {1} or {2}) $$c_{2n}=\frac2\pi\int_0^{\pi/2}\cos^p x\cos 2nx\,dx=\frac{\Gamma(p+1)}{2^p\Gamma(p/2+1+n)\Gamma(p/2+1-n)},$$ so that, using the reflection formula for $\Gamma$ and that $\Gamma(x+a)/x^a\Gamma(x)\to1$ as $x\to\infty$, $$\lim_{n\to\infty}(-1)^{n-1}n^{p+1}c_{2n}=\lambda_p:=\frac1{2^p\pi}\Gamma(p+1)\sin\frac{p\pi}{2}.$$
Now, denoting $a_n:=n^{p+1}(S_n-\beta)=n^{p+1}\Delta_{2n}(f)$, we get easily $$\lim_{n\to\infty}a_{2n}=-2\lambda_p\zeta(p+1)=2\pi^p\zeta(-p);\\\lim_{n\to\infty}a_{2n+1}=-(1-2^{-p})\lim_{n\to\infty}a_{2n}.$$
