Fixes to audio attenuation jumps and better sample loop script

coding standard: split onto multiple lines. - **3.4.2. The conditional should be put on a separate line and wrapped in braces. **