20.2 FMOD


20.2 FMOD

In this section we'll examine a method to play various media files like MP3 and the fantastic OGG format using the FMOD library.

FMOD is a cross-platform music and audio library. It's not free for commercial development, however, and the price varies depending on a developer's product and situation. The FMOD SDK can be downloaded for free from http://www.fmod.org/.

image from book
Figure 20.1

Some of FMOD's features and properties are listed below. Supported Platforms

  • Linux

  • Linux 64-bit (AMD64)

  • Macintosh OS8/9/X and OSX for x86

  • Microsoft Windows series

  • Microsoft Xbox

  • Microsoft Xbox 360

  • Nintendo GameCube

  • Nintendo Wii

  • Sony PlayStation 2

  • Sony PlayStation 3

  • Sony PlayStation Portable

Supported Audio File Formats

  • AIFF-Audio Interchange File Format

  • ASF-Advanced Systems Format

  • ASX-Advanced Stream Redirector playlist format

  • DLS-DownLoadable Sound format for MIDI playback

  • FLAC-Free Lossless Audio Codec

  • FSB-FMOD Sample Bank format generated by FSBank and FMOD designer tool

  • M3U (also known as MP3 URL)-Moving Picture Experts Group Audio Layer 3 Uniform Resource Locator playlist format

  • MID-MIDI (Musical Instrument Digital Interface) using operating system or custom DLS patches

  • MOD-Module file format

  • MP2-MPEG-1/2 Audio Layer 2

  • MP3-MPEG-1/2 Audio Layer 3

  • OGG-Ogg Vorbis format

  • PLS-Playlist format

  • RAW-Raw file format

  • S3M-ScreamTracker 3 sequenced MOD format

  • VAG-PS2/PSP format

  • WAV-Microsoft Waveform audio format

  • WAX-Windows Media Audio Redirector playlist format

  • WMA-Windows Media Audio format

  • XM-Extended Module format

  • XMA-Xbox compressed WMA format

20.2.1 Installing and Configuring

Once downloaded, FMOD is easy to install using the wizard, which installs FMOD to the computer. All the libraries and documentation will be stored in the FMOD folder. To use FMOD, the fmod.hpp file must be included in projects using the #include preprocessor directive; for example, #include<fmod.hpp>. For Visual Studio, the library fmodex_vc.lib should be linked, and for Code::Blocks and Dev C++, the libfmodex.a library should be linked.

20.2.2 Playing Sound and Music

The process of playing a sound file in FMOD is quite simple. The following sample program demonstrates how a sound file can be played.

      FMOD_RESULT result;      FMOD::Sound *sound;      FMOD::Channel *channel;      FMOD::System *system;      result = FMOD::System_Create(&system);      system->init(200, FMOD_INIT_NORMAL, 0);      system->createSound("sample.mp3", FMOD_DEFAULT, 0, &sound);      system->playSound(FMOD_CHANNEL_FREE, sound, false, 0); 

That's all there is to it. The above code creates two important objects: FMOD::Sound and FMOD::System. FMOD::System represents the actual sound playing hardware attached to the computer, and it acts like the media player controls on a stereo, allowing programmers to start, stop, and pause playback of music. The FMOD::Sound class encapsulates the actual music file, in this case sample.mp3. Naturally, this could be any other sound file in a valid format. Finally, the playSound method of FMOD::System requires a sound to play, a channel to play in, and a flag to determine whether the sound should be repeated.




Introduction to Game Programming with C++
Introduction to Game Programming with C++ (Wordware Game Developers Library)
ISBN: 1598220322
EAN: 2147483647
Year: 2007
Pages: 225
Authors: Alan Thorn

Similar book on Amazon
Beginning C++ Through Game Programming
Beginning C++ Through Game Programming
Beginning Game Programming
Beginning Game Programming
The Ultimate Guide to Video Game Writing and Design
The Ultimate Guide to Video Game Writing and Design

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net