Developing an Audio System

From EQUIS Lab Wiki

Jump to: navigation, search

Contents

Developing an Audio System

Group Members

  • Ahmed

Introduction

Can we afford to ignore the importance of audio in our games? Would games be the same without sound? The answer is simply no. Gaming audio has significantly evolved over the last decade. From low bitrates, to stereo, surround sound, multi-channels until recently, high-definition, sound plays a major role in the new gaming era and players have higher sound expectations than ever.

Audio can dramatically help portray a gaming environment to the player. It helps connect the gamer emotionally and psychologically to the gaming world and bridges the gap between the “real” and “virtual” worlds. Sound can also enhance playability; for instance, when multiple channels are utilized, gamers can realize the location and direction of in-games characters as they approach the player's character from different places. Sound is one of the most cost effective ways of enhancing games and the outcome of providing well planned music and sound effects is, in many circumstances, humungous.

Life is Village does not have any sound capability, which makes the game somehow lacking and leaves gamers asking for more. The goal of this project is to develop a modular audio system.

Project Goals

The primary goal of this project is to build a modular audio system that will provide in-game audio and enable future developers and gamers to easily integrate their own sound and music files without any programming skills. Goals include:

  • Allow music to run in the background and loop for the duration of the game.
  • Enable the system to change the music based on the gaming environment and time of day.
  • Provide the player or developer with a system to add music easily without having to write or change any code.
  • Allow sound effects for different parts of the game such as chopping a tree, mining stone or walking.
  • Allow voice conversations that synchronize with the Quest and Crafting System currently being developed by Eric and Jeff.
  • If possible, build a menu system where the user can tune the sound properties and upload new music files.

How changes will appear to the player

The player will not notice any visual difference. The differences are purely audio ones. The player will hear different sounds and music and will therefore better interact with the gaming environment. If a GUI menu system is implemented as well, the player will have the ability of changing the sound and music settings, increasing or decreasing volume levels and choosing specific music files.

Models that will be required for the project

There are several possibilities for obtaining music and voice recordings. The Arts students have proposed to help develop a couple of sound and music recordings. Other possibilities include using Creative Commons (CC) music and sound effects, or purchasing stock sound. For the initial development phases any sound file is sufficient for testing and debugging.

Tools or technologies to be used

OpenAL will very likely be used. OpenAL is a 3D audio API appropriate for use with gaming applications and many other types of audio applications. OpenAL is open sources and freely available for download and apparently, it is the most recommended within the Ogre community. Other tools such as XML may be used as well.

Technological issues involved in the project

If OpenAL is used, its libraries must be included within the game and will have to be installed on all future game installations. Other than that, the planned functionalities should not have any limitations or problems.


Design & Implementation

Existing Sound

The previous version of OpenAL was installed on LIAV but never functioned properly. Here are some notes regarding that previous version version.

The OpenAL specification documents the interface.

  • Provides platform-independent rendering of 3d sound
  • Should probably be designed as a singleton manager which handles its own resources
  • Functions that we're interested in having:
    • Easy configuration (load settings from another config file?)
    • Move sound sources around each frame
    • Play a sound (also pause, stop, rewind, loop)
    • High-level data structure for a sound source (not just bare OpenAL handles to buffer objects)
  • Things in our game world that can be sound sources:
    • People (avatars and villagers)
    • Buildings and other user-created structures
    • Localised environmental sounds (e.g., waterfall)
    • Ambient sound (i.e., travels with the avatar, so another kind of avatar sound)
  • Possible future feature: implement directional sound sources with DIRECTION and CONE parameters

"Sound Ideas":

  • ambient wind sound gain is proportional to altitude, so that mountaintops are windy and valleys are not
  • ambient forest sound in forest areas: gain is proportional to forest density

Implementation notes:

  • singleton design
  • my implementation uses the non-standard STL hash_map container to map sound names onto sound source ID values. If your compiler does not include this container (MSVC7 does), you can download it from the SGI STL site.
  • sound manager needs to handle the following additional properties:
    • Doppler effect
    • distance attenuation model
    • distance attenuation clamping?
    • distance culling
    • list of all sources so that sources can be deallocated by the sound manager on program exit (i.e., CAXSoundSource doesn't actually own the OpenAL sound source object; however, the CAXSoundSource constructor is the only way to create a new OpenAL sound source, and the CAXSoundSource destructor asks the SoundManager to kill the corresponding sound source).
    • sound context
    • sound device

Sound Manager config file:

  • list of sound clips:
    • WAV filename (required)
    • sound clip name (required)
  • attenuation parameters
  • preferred device settings (optional) -- autodetect if not present
  • ambient and environmental sound sources defined

OpenAL

OpenAL is an audio version of OpenGL. Some of its features include:

  • Cross-platform 3D audio Application Programming Interface (API)
  • Allows application to position audio sources in 3D space around a listener
  • Released in 2000; Hardware acceleration in 2001

OpenAL is based on three main components:

  • Source objects
  • Buffers
  • A single listener

Source objects can be attached onto ogre objects in the environment. They contain a pointer to the buffer and can include additional parameters such as the intensity and direction of the sound

The buffer is where the sound file is loaded and stored. It contains audio data in PCM format, either 8- or 16-bit, in either monaural or stereo format.

The listener object contains the velocity, position and direction of the listener, and the general gain applied to all sound.


File:Http://ahsntc.trlab.ca/liav/openal1.jpg


The outcome of using OpenAL to the LIAV gamer is that sounds behave quite naturally as the user moves through the three-dimensional space of the virtual world. Furthermore, any person with no programming skills will be able to change sound files.

OpenAL has a multitude of other features. Here are some features quoted from openal.org:

“Unlike the OpenGL specification, the OpenAL specification includes two subsections of the API; The core consisting of the actual OpenAL function calls, and the ALC API which is used to manage rendering contexts, resource usage and locking in a cross platform manner. There is also an 'ALUT' library that provides higher level 'convenience' functions — exactly analogous to OpenGL's 'GLUT'.”

“In order to provide additional functionality in the future, OpenAL utilizes an extension mechanism. Individual vendors are thereby able to include their own extensions into distributions of OpenAL, commonly for the purpose of exposing additional functionality on their proprietary hardware. Extensions can be promoted to ARB (Architecture Review Board) status, indicating a standard extension which will be maintained for backwards compatibility. ARB extensions have the prospect of being added” to the core API after a period of time.”

Steps needed to add sound:

  • Initialize a device (e.g., speakers)
  • Generate BUFFERs to hold audio files
  • Generate SOURCEs and set their properties
  • Set properties of LISTENER (only 1 per context)
  • Attach BUFFERs to SOURCEs
  • Dynamically update SOURCEs and LISTENER properties


Here is how code should be inserted:

Adding background sound:

OgreAL::SoundManager *soundManager; 
soundManager = new OgreAL::SoundManager();
OgreAL::Sound *bgSound = soundManager->createSound(i->first, i->second, true);
bgSound->setRelativeToListener(true);
bgSound->play();


Iterating through configuration file:

void CAXApplication::setupSound()
{
   // Load sounds files from config file
   ConfigFile cf;
   cf.load("sounds.cfg");
   // Go through all sections & settings in the file
   ConfigFile::SectionIterator seci = cf.getSectionIterator();
   String secName, typeName, archName;
   while (seci.hasMoreElements())
   {
       secName = seci.peekNextKey();
       ConfigFile::SettingsMultiMap *settings = seci.getNext();
       ConfigFile::SettingsMultiMap::iterator i;
       for (i = settings->begin(); i != settings->end(); ++i)
       {
           typeName = i->first;
           archName = i->second;
           OgreAL::SoundManager *soundManager;
           soundManager = new OgreAL::SoundManager();
           OgreAL::Sound *bgSound = soundManager->createSound(i->first, i->second, true);
           bgSound->setRelativeToListener(true);
           bgSound->play();
       }
   }
}

Configuration File

Configuration file should be

  • as simple as possible
  • Placed in Bin (Release and Debug)
# Sound files are defined here
[backgroundsound]
SoundName=mario.wav


How to run LIAV with sound - Installation

How to install OpenAL sound libraries on future LIAV Installations

To make it easy for developers working on LIAV to run my sound implementation here are detailed instructions of the steps that need to be followed to install OpenAL

Download and install a copy of LIAV with all the sound classes and modifications made. This by itself will not run sound since OpenAL must be installed on your computer in order to do so.

Now you need to install OpenAL libraries. Plase follow the following step in the exact same order. There are a few steps to this setup, but there's nothing too complicated.

  • Download https://sourceforge.net/projects/ogreal/
  • Go to OpenAL Download Page and download the OpenAL SDK installer and the freealut Binary package from http://www.openal.org/downloads.html
  • Run the OpenAL SDK installer and unzip the freealut package. You can put them where ever you like on your system since we'll reference them later with system variables.
  • The next step is to create two environment variables.

1. OPENAL_SDK - This should point to where ever you chose to install the SDK. 2. ALUT_BIN - This should point to where ever you unzipped the freealut package.

  • Next you need to download libogg and libvorbis. You can download them from the xiph.org download page.
  • Unzip these right next to OgreAL and rename the libogg-1.1.3 folder to ogg and the libvorbis-1.1.2 folder to vorbis. When you have all this done it should look like this:

Code: Develpment

   |--OgreAL 
   |--ogg 
   |--vorbis
  • Now go into the ogg folder and build both the release and debug builds by double clicking on the ogg/win32ogg.dsw workspace. It'll open up in Visual Studio and you just need to build it.
  • Then do the same thing with the vorbis/win32/vorbis.dsw
  • After all that you can open the OgreAL solution and build it.
  • The last thing you'll need to do to run the demos is modify the Plugins.cfg in the OgreAL/Demos/bin/{Debug|Release} folders. There is a line that says

Code: PluginFolder=Path/to/your/ogrenew/Samples/Common/bin/{Debug|Release} Modify that to point to the OgreSDK/bin/{Debug|Release} directory which is where the dll's for Ogre and its dependencies live.

  • Now go open LIAV solution and build it. It should build without any problems. Once the build is successful run the program.

Future Work

Add voice to Villagers Enable villager voices to be set through a configuration file

Integrate with the Quest Mod Allow the villagers to speak in a Quest