An exact solution to compute the band gap in phononic crystals