2009-06-21 05:24:30 +02:00
|
|
|
//****************************************************************
|
|
|
|
//cAudio 1.7.1 Tutorial 2
|
|
|
|
//Basic 3d Audio. Moving Audio source. Must be mono sound source
|
|
|
|
//****************************************************************
|
|
|
|
|
|
|
|
#include <iostream>
|
2009-08-08 07:51:32 +02:00
|
|
|
#include <math.h>
|
2009-06-21 05:24:30 +02:00
|
|
|
//Include IAudioManager so we can easily work with cAudio
|
|
|
|
#include "../../include/IAudioManager.h"
|
|
|
|
//Include IAudio so we can create cAudio objects
|
|
|
|
#include "../../include/IAudio.h"
|
2009-08-26 04:55:02 +02:00
|
|
|
//Include The cAudio vector class
|
|
|
|
#include "../../include/cVector3.h"
|
2009-06-21 05:24:30 +02:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
//To make visual studio happy
|
|
|
|
cAudio::IAudio* mysound;
|
|
|
|
//Some fancy text
|
2009-08-08 07:51:32 +02:00
|
|
|
cout << "cAudio 1.7.1 Tutorial 2: 3dSound \n";
|
2009-06-21 05:24:30 +02:00
|
|
|
//Hold audio source x position
|
|
|
|
float x = 0;
|
|
|
|
//Grap the cAudioManager
|
|
|
|
cAudio::IAudioManager* manager = cAudio::getAudioManager();
|
|
|
|
//Init the cAudio Engine
|
|
|
|
manager->init(argc,argv);
|
2009-08-08 07:51:32 +02:00
|
|
|
|
|
|
|
//Grab the listener object, which allows us to manipulate where "we" are in the world
|
|
|
|
//It's useful to bind this to a camera if you are using a 3d graphics engine
|
|
|
|
cAudio::IListener* listener = manager->getListener();
|
|
|
|
|
2009-06-21 05:24:30 +02:00
|
|
|
//Create a IAudio object and load a sound from a file
|
2009-08-08 07:51:32 +02:00
|
|
|
mysound = manager->createFromFile("bling","../../bin/bling.ogg",true);
|
|
|
|
|
2009-06-21 05:24:30 +02:00
|
|
|
//Set the IAudio Sound to play3d and loop
|
|
|
|
//play3d takes 4 arguments play3d(toloop,x,y,z,strength)
|
2009-08-08 07:51:32 +02:00
|
|
|
if(mysound && listener)
|
|
|
|
{
|
2009-08-26 04:55:02 +02:00
|
|
|
listener->setPosition(cAudio::cVector3(0,0,0));
|
|
|
|
mysound->play3d(cAudio::cVector3(0,0,0),0.1,true);
|
2009-06-21 05:24:30 +02:00
|
|
|
|
2009-08-08 07:51:32 +02:00
|
|
|
while(mysound->playing())
|
|
|
|
{
|
|
|
|
//Playback sound
|
|
|
|
x+=0.001f * 0.017453293f; //0.001 degrees a frame
|
|
|
|
float realX = sinf(x)*10.f;
|
2009-08-26 04:55:02 +02:00
|
|
|
mysound->setPosition(cAudio::cVector3(realX,0.0,-5.0));
|
2009-08-08 07:51:32 +02:00
|
|
|
manager->update();
|
|
|
|
}
|
|
|
|
}
|
2009-06-21 05:24:30 +02:00
|
|
|
|
|
|
|
//Delete all IAudio sounds
|
|
|
|
manager->release();
|
|
|
|
//Shutdown cAudio
|
|
|
|
manager->shutDown();
|
|
|
|
return 0;
|
|
|
|
}
|