Adding Sound to OGRE in 2 seconds: Tutorial

Problems building or running the engine, queries about how to use features etc.
Rohit Chauhan
Halfling
Posts: 46
Joined: Sun Mar 05, 2006 8:01 pm
Location: India,Shimla
Contact:

Adding Sound to OGRE in 2 seconds: Tutorial

Post by Rohit Chauhan »

I seem to be on a Tutorial spree last couple of days . :)
Here is , how you can integrate OGRE with “audiere”, an excellent cross-platform audio library in few seconds.

Setting up OGRE and audiere on Anjuta(Linux):
Make C++ Project(Generic/Terminal)
1)Add /usr/local/include/OGRE to “Settings->CompilerAndLinkerSetting->include”
2)Add “/usr/local/lib” to lib path
3)Add OgreMain and audiere to Libraries.
4)To OPTIONS->CFLAGS add –DEXT_HASH
5)Replace the code in main.cc by following code

#include "ExampleApplication.h"
#include “audiere.h”
using namespace audiere;

AudioDevicePtr device(OpenDevice());
OutputStreamPtr song(OpenSound(device,”songname.mp3orwhatever”,false));

class Game : public ExampleApplication
{
void createScene()
{
Entity *robo;
robo = mSceneMgr->createEntity( "Robot", "robot.mesh" );

SceneNode *node1;
node1= mSceneMgr->getRootSceneNode()->createChildSceneNode( "RobotNode" );

node1->attachObject( robo );

song->setVolume(0.5f);
song->play();
}
};

int main()
{
Game mygame;
mygame.go();
return 0;
}


Remember : audiere.h and libaudiere.a(audiere.dll in windows) should be in the same directory in which main.cc is (or in the path).Though I prefer former.
And all the usual stuff (ExampleApplication.h ExampleFrameListener.h plugins.cfg resources.cfg(with absolute paths and not relative) should be in your source folder or in the PATH.
Type say speedofsound.mp3 or .wav or .ogg or flac or(full music filename) I love ColdPlay :P

Build and Execute.
You should see robot dancing to music.
GoodBye !!!
:twisted:


Personally I like using Class ExampleApplication.h , because one of the main powers of C++ is "Code Reusability" which results from the cornerstone of ObjectOrientedProgramming , i.e. Inheritance 8)

For Fuller introduction to Audiere , see my tutorial here : ---

http://one.fsphost.com/ogre3d/
Last edited by Rohit Chauhan on Tue Mar 14, 2006 8:24 pm, edited 1 time in total.
O Draconian Devil ! O Lame Saint !
So Dark the Con of Man !
http://one.fsphost.com/ogre3d/
Rohit Chauhan
Halfling
Posts: 46
Joined: Sun Mar 05, 2006 8:01 pm
Location: India,Shimla
Contact:

Post by Rohit Chauhan »

For Adding Physics and having a Full Blown Game Engine
.i.e OGRE for Rendering , Newton for Physics and Audiere for sound ,
Continue my another tutorial here,

http://www.ogre3d.org/phpBB2/viewtopic.php?t=18204
O Draconian Devil ! O Lame Saint !
So Dark the Con of Man !
http://one.fsphost.com/ogre3d/
jelle
Halfling
Posts: 80
Joined: Wed Feb 23, 2005 12:42 pm

Post by jelle »

hi,

thx for the tutorial, i was looking for an easy way to use an open source sound library.

however, i'm using visual c++ 2005 express and im getting these linking errors:

Toewie.cpp
ToewieSensorSDK.cpp
Generating Code...
Linking...
Toewie.obj : error LNK2019: unresolved external symbol __imp__AdrOpenDevice@8 referenced in function "class audiere::AudioDevice * __cdecl audiere::OpenDevice(char const *,char const *)" (?OpenDevice@audiere@@YAPAVAudioDevice@1@PBD0@Z)
Toewie.obj : error LNK2019: unresolved external symbol __imp__AdrOpenSampleSource@8 referenced in function "class audiere::SampleSource * __cdecl audiere::OpenSampleSource(char const *,enum audiere::FileFormat)" (?OpenSampleSource@audiere@@YAPAVSampleSource@1@PBDW4FileFormat@1@@Z)
Toewie.obj : error LNK2019: unresolved external symbol __imp__AdrOpenSound@12 referenced in function "class audiere::OutputStream * __cdecl audiere::OpenSound(class audiere::RefPtr<class audiere::AudioDevice> const &,class audiere::RefPtr<class audiere::SampleSource> const &,bool)" (?OpenSound@audiere@@YAPAVOutputStream@1@ABV?$RefPtr@VAudioDevice@audiere@@@1@ABV?$RefPtr@VSampleSource@audiere@@@1@_N@Z)
..\..\bin\Debug/Toewie.exe : fatal error LNK1120: 3 unresolved externals
Build log was saved at "file://c:\OgreSDK\samples\obj\Debug\BuildLog.htm"
Toewie - 4 error(s), 2 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

these are the parts of my code that matter:

#include "ExampleApplication.h"
#include <stdio.h>
#include <math.h>
#include "ToewieSensorSdk.h"


#include <deque>
//#include <Windows.h>

#include "audiere.h"

using namespace std;

... and then further on, where i create my scene:

audiere::AudioDevicePtr device(audiere::OpenDevice());
audiere::OutputStreamPtr song(OpenSound(device,"songname.mp3orwhatever",false));
song->setVolume(0.5f);
song->play();

I'm quite new to this express edition but I THINK i got all the right settings, and i also copied the audiere.dll to OgreSDK\bin\debug




can someone help me out with this?

thx,
Jelle
marlboro
Kobold
Posts: 28
Joined: Fri Feb 24, 2006 11:58 am

Post by marlboro »

have you made sure that your linking to the audiere library??
User avatar
raicuandi
Gargoyle
Posts: 1092
Joined: Wed Nov 09, 2005 12:56 pm
Location: Adelaide, Australia
Contact:

Post by raicuandi »

Can I use Audiere in C#?
Is there a wrapper somewhere?
Or there is another good sound engine for .NET...

Someone, please? :cry:

/edit:
I've found BASS. And its for .NET2.0! Unfortunetely, its not for Linux :cry:
A cruel world...
Last edited by raicuandi on Sun Mar 12, 2006 2:12 pm, edited 1 time in total.
jelle
Halfling
Posts: 80
Joined: Wed Feb 23, 2005 12:42 pm

Post by jelle »

under Tools>>Options>>Projects and Solutions>>VC++ Directories>>Library Files

i've added C:\audiere-1.9.4-win32\lib



under Project>>Settings>>Linker>>General>>Additional Library Directories

i've also added that directory


am i forgetting anything?
could the problem be something else?
Spudder
Halfling
Posts: 54
Joined: Fri Mar 04, 2005 11:25 am

Post by Spudder »

You also need to add in the name of the audiere .lib file (I'm not sure what it's called) under Project Properties -> Linker -> Input -> Additional Dependencies
marlboro
Kobold
Posts: 28
Joined: Fri Feb 24, 2006 11:58 am

Post by marlboro »

under Project>>Settings>>Linker>>input>>Additional Directories

have you added audiere.lib ??
jelle
Halfling
Posts: 80
Joined: Wed Feb 23, 2005 12:42 pm

Post by jelle »

ok, thx, it compiles now without errors, but when i try to run it, it crashes without telling me what the error is (the well known microsoft error window where you could send a report to microsoft)

this is my audiere code:

audiere::AudioDevicePtr device(audiere::OpenDevice());
audiere::OutputStreamPtr song(OpenSound(device,"C:\\OgreSDK\\bin\\debug\\main.mp3",false));
song->setVolume(0.5f);
song->play();

and it crashes because of the third line.
i guess my mp3 file doesnt get loaded properly or something like that?
marlboro
Kobold
Posts: 28
Joined: Fri Feb 24, 2006 11:58 am

Post by marlboro »

I had this problem but i just converted the mp3 to ogg and it worked great
Rohit Chauhan
Halfling
Posts: 46
Joined: Sun Mar 05, 2006 8:01 pm
Location: India,Shimla
Contact:

Post by Rohit Chauhan »

Paste this instead. You are using 2 "\\" there


audiere::AudioDevicePtr device(audiere::OpenDevice());
audiere::OutputStreamPtr song(OpenSound(device,"C:\OgreSDK\bin\debug\main.mp3",false));
song->setVolume(0.5f);
song->play();

and ensure that there is some sort of Music file name "main.mp3"
in the directory where your executable ultimately gets created or as you specified in the path :P
Here i see that it is the debug folder
Last edited by Rohit Chauhan on Sun Mar 12, 2006 4:17 pm, edited 2 times in total.
O Draconian Devil ! O Lame Saint !
So Dark the Con of Man !
http://one.fsphost.com/ogre3d/
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Post by jacmoe »

Wrong, Rohit Chauhan. Two "\\" are needed, because \ is an escape character. If you want the "\" character you will need to escape it, like this: "\\".
So the above path is valid. :wink:
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
Rohit Chauhan
Halfling
Posts: 46
Joined: Sun Mar 05, 2006 8:01 pm
Location: India,Shimla
Contact:

Post by Rohit Chauhan »

why escape sequences ?
You have to specify path to the Music file and you mention the path ,
thats it ! :P
O Draconian Devil ! O Lame Saint !
So Dark the Con of Man !
http://one.fsphost.com/ogre3d/
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Post by jacmoe »

An escape character changes the meaning of the character that follows it. For example, normally the character n means the letter n, but when it is preceded by the escape character (\) it means new line.

Code: Select all

\a
 Bell (alert)
 
\b
 Backspace
 
\f
 Form feed
 
\n
 New line
 
\r
 Carriage return
 
\t
 Tab
 
\v
 Vertical tab
 
\'
 Single quote
 
\"
 Double quote
 
\?
 Question mark
 
\\
 Backslash
 
\000
 Octal notation
 
\xhhh
 Hexadecimal
 
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
Rohit Chauhan
Halfling
Posts: 46
Joined: Sun Mar 05, 2006 8:01 pm
Location: India,Shimla
Contact:

Post by Rohit Chauhan »

thats all in the first chapter of any c++ book :P
But , can you please explain me(in simpler language) why do we need to have 2 "\\" here ?
O Draconian Devil ! O Lame Saint !
So Dark the Con of Man !
http://one.fsphost.com/ogre3d/
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Post by jacmoe »

In short:
"\bin\debug" becomes system bell + "in\debug".

So "C:\OgreSDK\bin\debug\main.mp3" becomes:
"C:OgreSDKindebugmain.mp3", IIRC. :wink:

To avoid confusion, we can use Unix path separators instead:
"C:/OgreSDK/bin/debug/main.mp3".
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Post by jacmoe »

Here is an example from PHP:
Zend docs wrote:These escape sequences mean that backslash has a special meaning in strings. To include a backslash itself in a string, you need to escape the backslash with a backslash. For example:

Code: Select all

$file = "c:\windows\system.ini";
echo $file;   // prints c:windowssystem.ini

$file = "c:\\windows\\system.ini";
echo $file;   // prints c:\windows\system.ini
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
Snuttan
Gnoblar
Posts: 16
Joined: Wed Feb 15, 2006 1:45 am

Post by Snuttan »

Simply because the string
"C:\OgreSDK\bin\debug\main.mp3"

will be interpreted as the following sequence of characters
{'C',':','\O','g','r','e','S','D','K','\b','i','n','\d','e','b','u','g','\m','a','i','n','.','m','p','3'}

Or so I think, don't really know what happens when '\O' is found.
It looked like a sphere, only smaller and upside down
Rohit Chauhan
Halfling
Posts: 46
Joined: Sun Mar 05, 2006 8:01 pm
Location: India,Shimla
Contact:

Post by Rohit Chauhan »

Thats in Python too and maybe in other scripting languages ,
but i never saw this in any of the 3 C++ books i have :shock:
May be its VStudio peculiarity
Update:
Oh Sorry ! Its because most of the time i use Linux and i thought
"/" here(Fedora) , then simply " \" there (windows)
u r right!
Last edited by Rohit Chauhan on Sun Mar 12, 2006 5:01 pm, edited 1 time in total.
O Draconian Devil ! O Lame Saint !
So Dark the Con of Man !
http://one.fsphost.com/ogre3d/
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Post by jacmoe »

No, it is standard C++.
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
Aladrin
Orc
Posts: 465
Joined: Fri Mar 10, 2006 10:22 pm

Post by Aladrin »

Nah, it's a generic C thing. All C/C++ compilers use this convention.

http://www.scit.wlv.ac.uk/cbook/chap1.strings.html
Rohit Chauhan
Halfling
Posts: 46
Joined: Sun Mar 05, 2006 8:01 pm
Location: India,Shimla
Contact:

Post by Rohit Chauhan »

Thank you all !
Back to basics ! :P
O Draconian Devil ! O Lame Saint !
So Dark the Con of Man !
http://one.fsphost.com/ogre3d/
Rohit Chauhan
Halfling
Posts: 46
Joined: Sun Mar 05, 2006 8:01 pm
Location: India,Shimla
Contact:

Post by Rohit Chauhan »

It seems to be a bug in the MP3 decoder in 1.9.4 (not sure)
Try audiere 1.9.3 from here if mp3 wont work

http://sourceforge.net/project/showfile ... p_id=32783

I had built a small MP3 player with 1.9.3 and it played perfectly.
O Draconian Devil ! O Lame Saint !
So Dark the Con of Man !
http://one.fsphost.com/ogre3d/
jelle
Halfling
Posts: 80
Joined: Wed Feb 23, 2005 12:42 pm

Post by jelle »

using the .3 version of audiere did not work for me, strange...

converting my soundfile to .ogg solved the case.

thx alot!
Rohit Chauhan
Halfling
Posts: 46
Joined: Sun Mar 05, 2006 8:01 pm
Location: India,Shimla
Contact:

Post by Rohit Chauhan »

In Linux I just write

"/home/rohit/mymusic/song.mp3" so was the whole confusion !


Its just a sort of(Overloading :P ) in Windows that you have
one same sign "\" for escape and path separation :P

(thats perfect eg of Polymorphism :roll: )
***just kidding function and operator overloading are completely different
concepts***
O Draconian Devil ! O Lame Saint !
So Dark the Con of Man !
http://one.fsphost.com/ogre3d/
Post Reply