Book Image

Getting Started with C++ Audio Programming for Game Development

By : David da L Gouveia
Book Image

Getting Started with C++ Audio Programming for Game Development

By: 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

Positional audio in FMOD


Using positional audio in FMOD is not too different from what we have done so far. In fact, we have already used all the classes required for positional audio on the previous chapters; the FMOD::Channel class already works as an audio source, while the FMOD::System class controls all the audio listeners in the scene. Let us break down the entire process into steps.

Creating an audio source

The first point that we have to remember is to create our sounds using the FMOD_3D flag; otherwise, the 3D audio engine will not process them:

system->createSound("explosion.wav", FMOD_3D, 0, &sound);

Then we simply need to play the sounds as usual, storing a reference to the channel handle so that we can modify the 3D properties of the sound.

Setting the audio source's position and velocity

Once we play the sound and get back a channel handle, we can use it to set the position and velocity of the audio source with the set3DAttributes method:

FMOD_VECTOR position = { 3.0f, 4.0f...