Book Image

Libgdx Cross-platform Game Development Cookbook

Book Image

Libgdx Cross-platform Game Development Cookbook

Overview of this book

Table of Contents (20 chapters)
Libgdx Cross-platform Game Development Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Audio streaming for background music


The Sound interface gives us a great deal of flexibility. However, it's not suitable for all needs due to one fundamental reason: sounds are fully loaded in memory before playback can start. This is not a problem for short effects, but it rapidly becomes one if we try to use it to play our soundtracks, especially in memory-limited devices such as phones. While effects lie around the order of tens to hundreds of KB, reasonably decent-quality song files can take up around 10 MB, even if they are not very long.

How do we solve this dire situation? Streaming is the answer. This technique only needs to keep in memory the next chunk of file that needs to be played, which makes for an epic win. However, not everything is happiness. Streaming means we need to decode the audio files as we go, rather than at load time. This inevitably has a CPU-wise performance impact that we did not suffer from with SFX. Still, streaming is the preferable way when it comes to playing...