LinuxDevCenter.com

oreilly.comSafari Books Online.Conferences.

We've expanded our Linux news coverage and improved our search! Search for all things Linux across O'Reilly!

Search
Search Tips

advertisement

Listen Print Subscribe to Linux Subscribe to Newsletters

OpenAL Development: The Programmer's View
Pages: 1, 2, 3

An example: coding an object for movement and sound, part 2

The xldemo program illustrates the basic use of OpenAL. A scene is created that includes two stationary objects (houses), two moving objects with fixed paths (a car and a van), and one freely moving object (the listener, i.e., you). The Linux version of the xldemo program is built from the Linux-specific sources in openal/demos/XLDEMO/linux and the shared sources in the openal/demos/XLDEMO/COMMON directory. Let's take a closer look into those sources to watch OpenAL at work.



Note: Code comments preceded by "tsao" are by Joseph I. Valenzuela. The author is especially indebted to Mr. Valenzuela for his assistance with this section.

In the Linux directory, xlmain.cpp sets up OpenGL/OpenAL and starts the main program loop. Looking into the code, we first see some standard includes (such as stdlib.h and sys/time.h) declared along with these files:

#include "GL/glut.h"  
  // sets up OpenGL 
#include "../COMMON/common.h"
  // defines the AVEnvironment class
#include "../COMMON/audioenv.h"
  // defines the audio environment class

The AVEnvironment class includes items such as window height and width, camera/listener angles and positions, and the named objects in the virtual environment (Sky, Ground, CarList, etc). It also references functions such as PlaceCamera and ChangeView (both found in xlmain.cpp). The audio environment class contains functions for loading and playing sound files, starting and stopping playback, and managing the positions of Sources and Listener.

Both common.h and audioenv.h include xlheader.h, which in turn calls the OpenAL headers -- view this section of code here.

Now let's look at audioenv.cpp in the openal/demos/XLDEMO/COMMON directory. View that code here.

These code fragments include most of the OpenAL calls used in the xldemo program. As you can see, quite a lot gets done by not a lot of code. The OpenAL API functions take care of the gritty details, freeing the programmer from considerable tedious calculations. Furthermore, both OpenGL and OpenAL share the same mechanisms for determining the camera/listener position, velocity, angle, etc., all of which get updated simultaneously for visuals and audio, but I leave that investigation to the motivated reader. More examples of interesting OpenAL code can be found in the sources to the Chromium BSU game and the excellent tutorial by Fotis Hadginikos.

Dave Phillips maintains the Linux Music & Sound Applications Web site and has been a performing musician for more than 30 years.


Discuss this article in the O'Reilly Network Linux Forum.

Return to the Linux DevCenter.

 




Tagged Articles

Be the first to post this article to del.icio.us

Sponsored Resources

  • Inside Lightroom
Advertisement

Sponsored by:

O'Reilly Media

©2009, O'Reilly Media, Inc.
(707) 827-7000 / (800) 998-9938
All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.
About O'Reilly
Academic Solutions
Authors
Contacts
Customer Service
Jobs
Newsletters
O'Reilly Labs
Press Room
Privacy Policy
RSS Feeds
Terms of Service
User Groups
Writing for O'Reilly
Content Archive
Business Technology
Computer Technology
Google
Microsoft
Mobile
Network
Operating System
Digital Photography
Programming
Software
Web
Web Design
More O'Reilly Sites
O'Reilly Radar
Ignite
Tools of Change for Publishing
Digital Media
Inside iPhone
O'Reilly FYI
makezine.com
craftzine.com
hackszine.com
perl.com
xml.com

Partner Sites
InsideRIA
java.net
O'Reilly Insights on Forbes.com