Book Image

Getting Started with C++ Audio Programming for Game Development

By : David Gouveia, David da L Gouveia
Book Image

Getting Started with C++ Audio Programming for Game Development

By: David Gouveia, David da L Gouveia

Overview of this book

Audio plays a fundamental role in video games. From music to sound effects or dialogue, it helps to reinforce the experience, convey the mood, and give feedback to the player. Presently, many games have achieved commercial success by incorporating game sounds that have enhanced the user experience. You can achieve this in your games with the help of the FMOD library. This book provides you with a practical guide to implementing the FMOD toolkit in your games. Getting Started with C++ Audio Programming for Game Developers is a quick and practical introduction to the most important audio programming topics that any game developer is expected to know. Whether you need to play only a few audio files or you intend to design a complex audio simulation, this book will help you get started enhancing your game with audio programs. Getting Started with C++ Audio Programming for Game Developers covers a broad range of topics – from loading and playing audio files to simulating sounds within a virtual environment and implementing interactive sounds that react to events in the game. The book starts off with an explanation of the fundamental audio concepts, after which it proceeds to explain how to use the FMOD Ex library, how to implement a 3D audio simulation, how to use the FMOD Designer toolkit, and how best to work with multi-layered sounds with complex behaviors attached to them. The final part of the book deals with working with audio at a much lower level by manipulating audio data directly. This book will provide you with a good foundation so that you can successfully implement audio into your games and begin pursuing other advanced topics in audio programming with confidence.
Table of Contents (13 chapters)
Getting Started with C++ Audio Programming for Game Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Controlling the playback


We already know how to play audio files, but it is also important to know how to stop them from playing. This is particularly important for looping sounds, because otherwise they would keep repeating forever. Usually, all we have to do is call the stop() method on the channel handle:

channel->stop();

When a sound stops playing—because it reached the end and it is not set to loop, or because we stopped it ourselves—its channel becomes free for other sounds to use. This means that once we stop a sound there is no way to resume it. If we need to stop a sound temporarily, and resume it at a later time, we need to use the setPaused() method:

// Pause the sound
channel->setPaused(true);
// Resume the sound
channel->setPaused(false);

Most methods that start with set are accompanied by an equivalent get method, such as getPaused(), that we can use to check the current value of that property. The following is a function that uses both methods in conjunction with each...