For watching movies, listening to music and playing games, sound output from the speaker and the headphone unit is excessively affected sadly by one thing: WiFi.
Wifi sizzles through headphoens, line out docks, and the speakers, distorting output. It isn't horrid if you are playing games, especially if games require internet connection, but to be honest, for music and movies, WiFi is one of the worst ways to affect output of any.
When I listen to music, I turn off WiFi, keep anything like push and notifications off, and keep the screen off as that can affect the output by letting in screen sizzle.
I am very careful when it comes to listening to music on my iDevice, of course.