Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Events
Videos
Audiobooks
Packt Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Getting Started with C++ Audio Programming for Game Development
Getting Started with C++ Audio Programming for Game Development

Getting Started with C++ Audio Programming for Game Development: Written specifically to help C++ developers add audio to their games from scratch, this book gives a clear introduction to the concepts and practical application of audio programming using the FMOD library and toolkit.

Arrow left icon
Profile Icon David da L Gouveia
Arrow right icon
$24.29 $26.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.8 (4 Ratings)
eBook Aug 2013 116 pages 1st Edition
eBook
$24.29 $26.99
Paperback
$36.79 $45.99
eBook + Subscription
$24.99 Monthly
Arrow left icon
Profile Icon David da L Gouveia
Arrow right icon
$24.29 $26.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.8 (4 Ratings)
eBook Aug 2013 116 pages 1st Edition
eBook
$24.29 $26.99
Paperback
$36.79 $45.99
eBook + Subscription
$24.99 Monthly
eBook
$24.29 $26.99
Paperback
$36.79 $45.99
eBook + Subscription
$24.99 Monthly

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Getting Started with C++ Audio Programming for Game Development

Chapter 1. Audio Concepts

Programming the audio component of a game is a lot easier these days, thanks to all the powerful audio libraries that are available. These libraries ease the burden on the developers by taking care of most of the low-level implementation details. While this is a good thing, it also makes it easier to dismiss the need to understand sound theory. For instance, we can easily play a sound file without knowing anything about its representation in memory.

However, even when we are using an audio library, there are still situations that will require some theoretical knowledge. For instance, we will often find parameters and function names related to the theory, such as the frequency of a sound, or the bit depth of an audio buffer. Knowing the meaning of these concepts is important to ensure that we are using them properly.

The goal of this chapter is to serve as a light introduction to the concepts that we will need the most during the course of this book.

Sound waves


Sound is created from the vibrations of objects. These vibrations produce variations in the atmospheric pressure which propagate away from the objects in the form of sound waves. Our ears are capable of detecting incoming sound waves and converting them into nerve signals that our brain interprets as sound.

One way to visualize sound is to draw a graph of the variations in the atmospheric pressure at each moment in time. However, understanding how those graphs relate to what we hear can be extremely complex. For that reason, we usually start by studying the simplest type of wave, the sine wave.

The sine wave is interesting for educational purposes, because we can easily identify two of the main properties of sound from it: volume and pitch. Most audio libraries allow us to control both of these properties for any sounds that we play.

  • Volume: This property corresponds to how loud or quiet the sound is. It depends directly on the amplitude (or the height) of the sound wave, as measured on the vertical axis. The main unit of volume is the decibel (dB), but most audio libraries use a scale between zero (silence) and one (full volume).

  • Pitch: This property determines how high or low the sound is. It depends on the frequency of the sound wave, which is the number of times that it repeats every second. The unit of frequency is the hertz (Hz). Two things that you should know about frequency are that the human ear can only hear frequencies within the 20 Hz and 20,000 Hz range, and that most sounds that you hear are actually a combination of several different frequencies.

Analog and digital audio


Now that we know what sound is, let us turn our thoughts towards recording the sound and storing it on a computer. The first step in this process is to convert the sound wave into an electrical signal. When we use a continuous signal to represent another signal of a different quantity, we call it an analog signal or in the case of a sound wave, an analog audio signal. You are probably already familiar with the devices that perform this conversion:

  • Microphones: These are devices that convert sound waves into electrical signals

  • Speakers: These are devices that convert electrical signals into sound waves

Analog signals have many uses, but most computers cannot work with them directly. Computers can only operate on sequences of discrete binary numbers, also known as digital signals. We need to convert the analog signal recorded by the microphone into a digital signal, that is, digital audio, before the computer can understand it.

The most common method used to represent analog signals digitally is pulse code modulation (PCM). The general idea of PCM is to sample (or measure) the amplitude of the analog signal at fixed time intervals, and store the results as an array of numbers (called samples). Since the original data is continuous, and numbers on a computer are discrete, samples need to be rounded to the nearest available number, in a process known as quantization. Samples are usually stored as integer numbers, but it is also possible to use floating-point numbers as shown in the following example:

There are two ways to control the quality of the sampled audio:

  • Sampling rate: Also known as the sampling frequency, it is the amount of samples taken for each second of audio. According to the Nyquist sampling theorem, the sampling rate should be at least twice as high as the highest frequency of the analog signal, in order to allow a proper reconstruction. You will usually work with values of 44,100 Hz or 48,000 Hz. The following figure compares sampling at different rates:

  • Bit depth: Also known as the resolution, it is the amount of bits used to represent a single sample. This controls the number of possible discrete values that each sample can take, and needs to be high enough to avoid quantization errors. You will usually work with bit depths of 16 bits or 24 bits, stored as integer numbers, or 32 bits stored as floating-point numbers. The following figure compares sampling at different resolutions:

Multi-channel audio


Another aspect that we should talk about is that many audio systems have more than one output. By sending different audio signals to separate outputs (called channels), it is possible to produce the illusion of directionality and space. The number of channels on these systems can vary from one (mono) or two (stereo), to several more on surround sound systems.

The PCM format described earlier can store audio for multiple channels at once, by interleaving one sample from each channel in the correct order. The following figure shows an example of this for a stereo system:

Besides volume and pitch, which we have examined earlier, there is another property that you will usually find in every audio library, called panning. Panning applies to stereo systems, and allows you to simulate the position of the sound, placing it anywhere between the left and the right channels. For positioning in configurations with more than two channels, you normally use other advanced features, such as 3D sound.

Audio file formats


There are so many different file formats for storing audio on a computer that it is easy to feel overwhelmed at first. Thankfully, you will only use a couple of them in your games, most of the time. Audio file formats usually fall into one of the following categories:

  • Uncompressed audio files: These are audio files where the data is stored in its original state (normally PCM). This means that their data is already prepared for playback without any further processing. The downside is that they take up a lot of space on disc (approximately 10 MB for one minute of audio). For example, WAV and AIFF.

  • Lossless compression: These are audio files where the data is encoded using compression algorithms that only perform reversible changes, so that no information is permanently lost. These files can be up to half the size of the uncompressed formats, but need the computer to decode them before playback. For example, FLAC and APE.

  • Lossy compression: These are the audio files where the data is encoded using compression algorithms where some loss of the information is acceptable. These algorithms use heuristics to determine which parts of the data are less likely to be audible, in order to discard them. File sizes can be as small as 10 percent of the original size, although sound quality can suffer considerably if the compression is too strong. For example, MP3, WMA, and OGG.

  • Sequenced music : There are some formats that do not fit into any of the earlier mentioned categories. For example, MIDI files only store information about how the music should be played, but do not contain any sound data, leaving it to the computers to decide how they should be interpreted. For this reason, they are extremely small, but sound quality is limited, and varies from system to system. There are also hybrid formats such as MOD files (also known as module or tracker files), which are in many ways similar to MIDI files, but also contain any sound data that is required to play them (known as instruments).

Be aware that despite its popularity, the MP3 is a patented format, and you cannot use it commercially without paying royalties (refer to http://mp3licensing.com/ for more information). For this book, we will be using OGG files for long sounds, and WAV files for small sound effects.

Summary


In this chapter, we have seen that sound is a series of variations in atmospheric pressure, travelling in the form of sound waves. We also saw that sound waves have properties such as amplitude and frequency, which control how loud or high it is and that you can represent a sound wave using electrical signals (analog audio) and a series of numbers (digital audio). We learned that when converting an analog signal to a digital signal, you need to control the sampling rate and the bit depth. Finally, we saw that many audio systems have more than one output and that there are many different types of audio file formats.

Left arrow icon Right arrow icon

Key benefits

  • Add audio to your game using FMOD and wrap it in your own code
  • Understand the core concepts of audio programming and work with audio at different levels of abstraction
  • Work with a technology that is widely considered to be the industry standard in audio middleware

Description

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.

Who is this book for?

This book is perfect for C++ game developers who have no experience with audio programming and who would like a quick introduction to the most important topics required to integrate audio into a game.

What you will learn

  • Design complex generative /interactive sounds
  • Simulate an environment with 3D audio and effects
  • Load and play audio files in several formats
  • Control audio playback and many sound parameters
  • Adapt an audio API to fit the needs of a game

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Aug 26, 2013
Length: 116 pages
Edition : 1st
Language : English
ISBN-13 : 9781849699105
Languages :
Concepts :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Aug 26, 2013
Length: 116 pages
Edition : 1st
Language : English
ISBN-13 : 9781849699105
Languages :
Concepts :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 123.97 154.97 31.00 saved
OpenGL Development Cookbook
$46.39 $57.99
Getting Started with C++ Audio Programming for Game Development
$36.79 $45.99
SDL Game Development
$40.79 $50.99
Total $ 123.97 154.97 31.00 saved Stars icon

Table of Contents

6 Chapters
Audio Concepts Chevron down icon Chevron up icon
Audio Playback Chevron down icon Chevron up icon
Audio Control Chevron down icon Chevron up icon
3D Audio Chevron down icon Chevron up icon
Intelligent Audio Chevron down icon Chevron up icon
Low-level Audio Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.8
(4 Ratings)
5 star 75%
4 star 25%
3 star 0%
2 star 0%
1 star 0%
L. R. Nov 12, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is the perfect book to everyone that wants to start using sounds within an application. It provides you with very important data in order to understand how to exploit the sound capabilities. It is performed step by step and through examples. It starts with all the basic data about sound theory like volume, pitch, channels, etc. Then it shows you the data file formats and how to start a first app using sound management playing sounds from a file using FMOD as sound engine.In general the book examples are based on C++ and considers the use of the FMOD sound engine for them. The book also explains the FMOD EX API and Design tools and how to exploit them practically in all the possibilities. It covers also the use of file in memory or as stream, how to load, play and manage the sound, how to exploit the channels, pitch, volume and panning, mono, stereo and 3d sound simulation, how to simulate an environment with obstruction for the sounds.Personally I selected this book because I'm involved in a personal project that aims to create an application for kids with learning disabilities. This book has helped me to understand how to manipulate the sounds in a manner that enables me to adapt the sound of my app to kids with sensory disorders. So this book is not only for game development then I consider this book very relevant to everyone that has a project that requires to exploit the sound capabilities within a software application in different ways.I strongly recommend this book to every developer experienced or beginner that aims to create software using sound.
Amazon Verified review Amazon
Corey Blackburn Nov 07, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Overall this book is exactly as the title suggests, an introduction to audio for game development with C++. It assumes that you are at least familiar with C++ and jumps right into audio. It should be noted that this book uses the FMOD audio engine.The first chapter serves as an introduction to the core concepts of audio. It's short, sufficient and has good visuals to explain each topic. We learn of sound waves and their properties volume and pitch. Then we moved on to representing a sound wave as either analog or digital and using sampling rate and bit depth when converting from analog to digital to control the quality. Last we saw that audio systems can have more than one output and various file formats.For the second and third chapter we get started with FMOD, audio playback and audio control. First we get an overview of FMOD and how to set up the Programmer's API with a Visual Studio project. Once that is setup we are ready to start! We learn to create and manage the FMOD audio system, how to load sounds both for streaming and into memory and then how to play them. Next we get into checking for errors to make sure everything is running as it should. Finally we're ready to create our own audio manager class. Now that we can load and play audio files the author goes into how to ways in which we can control the playback. The author then expands on our audio manager class after going over how to control the playback, volume, pitch, panning and channel grouping.Next in the fourth chapter the author gets into some more advanced features. We start off with 3D audio learning positional audio dealing with different audio soucres coming from specific locations. The author then explains how we simulate how the audio interacts with the environment through a technique called reverberation. Naturally most environments aren't empty so we get into how to handle obstruction and occlusion from objects. The last couple of pages in this section go over DSP effects(digital signal processing) giving us two quick samples.In the fifth chapter we get to learn about FMOD Designer and how to use sound events vs. audio files like we have been using. We start off learning to create simple events and how to avoid repetitive sound effects. The author goes over a few examples: a footstep sound loop, breaking glass sound effect and and an ambient track of singing birds. We then move on to multi-track events, these are a significantly more powerful. Expanding on our previous examples we make the footstep loop interactive allowing it to be more versatile. The singing birds turns into a complex forest with different animals that can also change based on the time of day in your simulation. I thought these were some pretty cool and useful examples that show off how powerful this tool really is.The fourth and fifth chapters contain code snippets but there is no demo project in the downloadable source code. As this book is a getting started guide and these chapters cover more advanced topics i'm okay with this. Unfortunately there is a shortage of books covering audio for games, but it would be nice to have these topics covered in more detail in a later book.Finally in the last chapter we dive deep into the low-level audio. Here we work with the bits and bytes of audio data and learn to code much of what FMOD already does for us. We will learn to load a WAV file, play and control the audio data, implement a basic delay effect and synthesize some basic sound waves. Although FMOD already handles everything we recreate in this chapter its a great learning experience to take a look at the underpinnings and see how they work and would be implemented.All of the source code compiled cleanly and ran as expected. You'll have to download FMOD Ex and SFML yourself. The author uses Visual Studio 2010. and make sure the project properties are set up (Additional Include Directories, Lib and Post-Build Event to copy the dll's to your output directory).This book was pretty short and to the point. It was easy to read, contained good examples and covers exactly what you would expect when reading the title. If you're looking to add some audio to your game and aren't already using an engine or framework that already has audio functionality included I would recommend this book as a great starting point.
Amazon Verified review Amazon
Amazon Customer Mar 04, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I would recommend this book as the best place for any beginner to start learning about audio programming. I have other books on audio programming, but this one is the most clear and concise allowing for quick integration into your software.
Amazon Verified review Amazon
A.K. Nov 04, 2013
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
This is an introductory book for [intermediate] C++ developers who want to start in audio programming, mainly using FMOD. The author starts by presenting some universal audio concepts in the first chapter such as volume, pitch, frequency, bit depth and audio file formats. Then he introduces FMOD and explains how to add it to a [Visual Studio C++] project, initialize FMOD, load/stream/play sounds, and check for errors. After this FMOD introduction, there is a project to build a simple C++ class audio manager. In Chapter 3, the author expands the manager to include audio control (playback, volume, pitch, panning, channel grouping).With the audio basics covered, the author explains 3D audio and how to work with positional audio, reverb and effects in FMOD. When working with positional audio, the developer must deal with occlusion and obstacles that affect the way audio is perceived by the player. This is a topic that could be further explored by the author, as it is touched in a couple of pages only. The same goes for DSP effects, which is presented in the last 3 pages of the same 3D audio chapter.The FMOD Designer tool is also introduced, which is a great tool from Firelight Technologies (developer of FMOD) for those who are more design-oriented. The author explains how to create simple sound events (such as footsteps and breaking glass SFX), multi-track events (e.g. interactive footsteps, car engine) and interactive music, and how to call these via code. For bigger projects or projects that need something more than basic audio control, this tool is a must.The final chapter involves low-level audio programming, i.e. how to work with the bytes of a digital sound file - loading, playbacking, changing properties, etc. Even though it still uses FMOD for audio control, the reader gets an 'under the hood' insight of the higher level audio APIs.At ~100 pages, this is a good introductory book for developers who are not familiar with audio programming, especially since there are not many books on the topic (there are some that focus on DirectSound/XACT programming, but these technologies seems to be pretty much dead -or are dying- and are MS-only). It is targeted at C++, but developers from other languages (e.g. C#) might benefit from the book as well, as FMOD supports other languages. The author's decision on FMOD is a good one too: FMOD is a multi-platform technology, supports many audio formats, and has been adopted by many successful games, companies and game engines (e.g. Unity, UE3). Previously I worked on a multi-platform game using FMOD for audio and the results were very nice.To get you started with audio programming, I think the contents and length of the book are OK, although the author could go deeper into the 3D audio and DSP effects section (and include 3D audio code in the audio manager as well; source-code is provided for chapters 2, 3 and 6 only).It is worth mentioning that FMOD Studio is not covered in the book, and for anything that is not audio-related (window, render and input management), the author uses SFML (Simple and Fast Multimedia Library).I would like to see another book from the author/publisher that deals with more advanced audio programming, such as more details on how to work with 3D audio (and the implications associated with it), real-time DSP effects, dynamic audio, and performance. Would also be good to see a project dealing with FMOD Designer (or FMOD Studio) and code, and not just examples.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.

Modal Close icon
Modal Close icon