OGRE Wiki
Support and community documentation for Ogre3D
Ogre Forums
ogre3d.org
Log in
Username:
Password:
CapsLock is on.
Remember me (for 1 year)
Log in
Home
Tutorials
Tutorials Home
Basic Tutorials
Intermediate Tutorials
Mad Marx Tutorials
In Depth Tutorials
Older Tutorials
External Tutorials
Cookbook
Cookbook Home
CodeBank
Snippets
Experiences
Ogre Articles
Libraries
Libraries Home
Alternative Languages
Assembling A Toolset
Development Tools
OGRE Libraries
List of Libraries
Tools
Tools Home
DCC Tools
DCC Tutorials
DCC Articles
DCC Resources
Assembling a production pipeline
Development
Development Home
Roadmap
Building Ogre
Installing the Ogre SDK
Setting Up An Application
Ogre Wiki Tutorial Framework
Frequently Asked Questions
Google Summer Of Code
Help Requested
Ogre Core Articles
Community
Community Home
Projects Using Ogre
Recommended Reading
Contractors
Wiki
Immediate Wiki Tasklist
Wiki Ideas
Wiki Guidelines
Article Writing Guidelines
Wiki Styles
Wiki Page Tracker
Ogre Wiki Help
Ogre Wiki Help Overview
Help - Basic Syntax
Help - Images
Help - Pages and Structures
Help - Wiki Plugins
Toolbox
Freetags
Categories
List Pages
Structures
Trackers
Statistics
Rankings
List Galleries
Ogre Lexicon
Comments
History: FMOD SoundManager
View page
Source of version: 12
(current)
{maketoc} !Introduction The class presented here may be used as a Sound Manager based on the FMODlibrary [http://www.fmod.org/]. FMOD Ex Version 4.02 was used to create this manager. Sounds may be loaded from seperate files, or may be grouped together in one or more zip files. %info% For discussion use this [url=http://www.ogre3d.org/phpBB2/viewtopic.php?t=17181|forum thread]. ((Mogre)) users look [https://www.ogre3d.org/addonforums/viewtopic.php?f=8&t=12064|here] for a .NET wrapper. !Source code Here are the source code files for this manager. * ((File SoundManager.h|SoundManager.h)) * ((File SoundManager.cpp|SoundManager.cpp)) !Sample code A sample application is provided here to demonstrate simple usage of the SoundManager. The zip file includes all source, DLLs, LIBs, and data to run the sample. * [https://web.archive.org/web/20070118233341/http://www.greygames.com/Ogre/SoundMgrSample.zip|SoundMgrSample.zip (4.4MB)] And here is just the source to the sample: * ((File SoundMgrSample.cpp|SoundMgrSample.cpp)) Requires API sources files such as fmod.hpp. Download install from [http://www.fmod.org.] !Additional Info on non-Microsoft compilers The version linked below is a modyfied version of the FMOD based SoundManager I got from here. __Important note:__ This version works with non-Microsoft compilers, too! The normal version - and the version of FMOD of course - has to be compiled with a Visual Studio compiler. We modified the Soundmanager code so that it uses the standard C header file fmod.h, instead of the c++ headerfile fmod.hpp. This way it can be compiled without any problems for example with MingW. [http://www.microforge.de/project-c/cvs/SoundManager_nonMS.zip|non-Microsoft SoundManager Archive] {ATTACH(id=>52, icon=>1, showdesc=>1, dls=>1)} {ATTACH} For more information in this topic take a look at this: [http://www.fmod.org/forum/viewtopic.php?t=4090&postdays=0&postorder=asc&start=15|non-MS Compiling FMOD Forum Entry] Greets, MicroForge-Team :) !Usage Refer to the FMOD documentation for detailed explainations of terms. As a quick explaination, a 'sound' is created once per wav (mp3,ogg...). A 'channel' is created once per playback instance of a sound. So, there may be multiple channels all based on the same sound. The SoundManager returns ints as 'handles' to the sounds and channels created. All the variations of SoundManager::CreateSound() will not create duplicate sounds based on the same fileName. If a repeated fileName is passed in, the handle to the already created sound will be returned. The first thing that must be done after creating the SoundManager is to Initialize it: {CODE(wrap="1", colors="c++")} SoundManager *soundMgr; soundMgr = new SoundManager; soundMgr->Initialize();{CODE} To create a single-shot 3D (positional) sound: {CODE(wrap="1", colors="c++")} int soundFireGun; soundFireGun = soundMgr->CreateSound(String("FireGun.wav"));{CODE} To play this sound: {CODE(wrap="1", colors="c++")} int channelFireGun; soundMgr->PlaySound(soundFireGun, sceneNode, &channelFireGun);{CODE} PlaySound will return a channel number in channelFireGun, but since this is a short single-shot sound, we don't need to save it, and it may be a stack variable. The variable 'sceneNode' passed in to PlaySound is the Ogre::SceneNode that the sound should be attached to. To change a channels volume: {CODE(wrap="1", colors="c++")} FMOD::Channel *channel= soundMgr->GetSoundChannel(&channelFireGun); channel->setVolume(0.5); // Set volume to half of maximum{CODE} Looping channels are a little different. After you create one, FMOD may decide it's no longer needed because the camera is far away from it, and discard it. Therefore, loooping channels should be created when the camera is nearby. Create the sound, and initialize the channel to INVALID_SOUND_CHANNEL (done once): {CODE(wrap="1", colors="c++")} int soundWalk; // Entity's member variable int channelWalk; // Entity's member variable soundWalk = soundMgr->CreateLoopedSound(String("BattleDroidWalk.wav")); channelWalk = INVALID_SOUND_CHANNEL;{CODE} In the Entity's tick() function (or your equivalent): {CODE(wrap="1", colors="c++")} // The sound manager may kill our walk sound if it needs the channel. // So, here we'll make sure it's playing by calling PlaySound if the camera is close by. // If our sound is already playing, PlaySound will just return. if (isWalking) { if (distToCameraSquared < 2500) soundMgr->PlaySound(soundWalk, sceneNode, &channelWalk); else if (channelWalk != INVALID_SOUND_CHANNEL) soundMgr->StopSound(&channelWalk); }{CODE} And most importantly, the function {MONO()}SoundManager::FrameStarted(){MONO} must be called every frame. This function updates all the positional information for the sounds, and also allows the FMOD library to update its data. The variable 'listenerNode' should be the Ogre::SceneNode that the camera is attached to. This is where the system's "ears" will be. The variable 'timeElapsed' may be retrieved from a listener's FrameStarted event ({MONO()}evt.timeSinceLastFrame{MONO}). --- Alias: (alias(FMOD_SoundManager))
Search by Tags
Search Wiki by Freetags
Latest Changes
One Function Ogre
IDE Eclipse
FMOD SoundManager
HDRlib
Building Ogre V2 with CMake
Ogre 2.1 FAQ
Minimal Ogre Collision
Artifex Terra
OpenMB
Advanced Mogre Framework
...more
Search
Find
Advanced
Search Help
Online Users
136 online users