How can I calculate the following trigonometric integrals with the methods of contour integrals? 
How can I calculate the integrals $$\int_0^\pi \frac{dx}{a+b\sin(x)}$$
  and $$\int_0^\pi \frac{dx}{a+b\cos(x)}$$
  using contour integrals ?

I know the residue theorem , and my idea is to choose the line from $0$ to $\pi$ on the $x$-axis followed by the upper half-circle connecting the points $(\pi/0)$ and $(0/0)$. 
But I do not know the singularities of the functions $f(z)=\frac{1}{a+b\sin(z)}$ and $g(z)=\frac{1}{a+b\cos(z)}$.
The other problem is that I do not know whether the integral over the half-circle can be calculated by hand. 
Is there a way, or must I begin with a substitution, for example $t=\tan(\frac{x}{2})$ ?
 A: The integral over the sine is a bit tricky because the integration region cannot be extended to $2 \pi$, so if you want to used the residue theorem, a unit circle is out.  Rather, we use a semicircle.  Thus consider the complex integral
$$\oint_C \frac{dz}{b z^2+i 2 a z-b} $$
where $C$ is the unit semicircle in the upper half-plane along with the diameter along the real axis.  Thus, the contour integral is equal to
$$\frac12 \int_0^{\pi} \frac{d\theta}{a+b \sin{\theta}} + \int_{-1}^1 \frac{dx}{b x^2+i 2 a x-b}$$
The contour integral is also equal to $i 2 \pi$ times the sum of the residues of the poles inside $C$.  In this case, let's assume $a \gt b \gt 0$; the poles are at 
$$z_{\pm}=-i \frac{a}{b} \pm i \sqrt{\frac{a^2}{b^2}-1} $$
Note that both poles are outside of the interior of the contour $C$; thus, the contour integral is zero.  Accordingly,
$$\begin{align} \int_0^{\pi} \frac{d\theta}{a+b \sin{\theta}} &= -2 \int_{-1}^1 \frac{dx}{b x^2+i 2 a x-b} \\ &= -\frac{2}{b} \frac1{z_+-z_-} \int_{-1}^1 dx \left (\frac1{x-z_+} - \frac1{x-z_-} \right ) \\ &= - \frac{2}{i 2 \sqrt{a^2-b^2}} \left [\log{\left (\frac{1-z_+}{-1-z_+} \right )} - \log{\left (\frac{1-z_-}{-1-z_-} \right )} \right ]\\ &= - \frac{2}{i 2 \sqrt{a^2-b^2}} \left [\log{\left (\frac{1-z_+}{1+z_+} \right )} - \log{\left (\frac{1-z_-}{1+z_-} \right )} \right ]\\ &= - \frac{2}{i 2 \sqrt{a^2-b^2}} i 2 \left [ \arctan{\left ( \frac{a}{b} - \sqrt{\frac{a^2}{b^2}-1}\right )} - \arctan{\left ( \frac{a}{b} + \sqrt{\frac{a^2}{b^2}-1}\right )} \right ] \\ &= \frac{2}{\sqrt{a^2-b^2}} \arctan{\left (\frac{\sqrt{a^2-b^2}}{b} \right )} \end{align}$$ 
Things work out similarly when $b \lt a$.  Accordingly, when $a \gt 0$ and $b \gt 0$,

$$\int_0^{\pi} \frac{d\theta}{a+b \sin{\theta}} = \begin{cases}\frac{2}{\sqrt{a^2-b^2}} \arctan{\left (\frac{\sqrt{a^2-b^2}}{b} \right )} & a \gt b \\ \frac{1}{\sqrt{b^2-a^2}} \log{\left (\frac{b+\sqrt{b^2-a^2}}{b-\sqrt{b^2-a^2}} \right )} & a \lt b \end{cases}$$

