6b3e9c5a9d
Updated logger to allow a user to create callbacks to receive log messages Logger also gives more information, time the message was sent, the source, the importance, and the message itself. User can now query playback devices and specify the device for the audio manager to use. The audio manager is no longer a singleton, although creating multiple managers is not advised. Clean up and optimization of manager initialization code. IAudioCapture can now be told which device to capture audio from. The user can also create multiple IAudioCaptures to capture audio from multiple sources at the same time. Added additional error checking. A seperate thread is used to capture audio now. Defines added to allow a user to remove support for default codecs.
115 lines
3.4 KiB
C++
115 lines
3.4 KiB
C++
//****************************************************************
|
|
//cAudio 1.7.1 Tutorial 2
|
|
//Basic 3d Audio. Moving Audio source. Must be mono sound source
|
|
//****************************************************************
|
|
|
|
#include <iostream>
|
|
#include <math.h>
|
|
//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"
|
|
//Include The cAudio vector class
|
|
#include "../../include/cVector3.h"
|
|
//Include our version of Sleep to free CPU usage
|
|
#include "../../include/cAudioSleep.h"
|
|
|
|
using namespace std;
|
|
|
|
int main(int argc, char* argv[])
|
|
{
|
|
//Some fancy text
|
|
cout << "cAudio 1.7.1 Tutorial 2: 3dSound \n \n";
|
|
//Hold audio source x position
|
|
float rot = 0;
|
|
|
|
//Create an uninitialized Audio Manager
|
|
cAudio::IAudioManager* manager = cAudio::createAudioManager(false);
|
|
|
|
if(manager)
|
|
{
|
|
//Allow the user to choose a playback device
|
|
cout << "Available Playback Devices: \n";
|
|
unsigned int deviceCount = manager->getAvailableDeviceCount();
|
|
std::string defaultDeviceName = manager->getDefaultDeviceName();
|
|
for(unsigned int i=0; i<deviceCount; ++i)
|
|
{
|
|
std::string deviceName = manager->getAvailableDeviceName(i);
|
|
if(deviceName.compare(defaultDeviceName) == 0)
|
|
cout << i << "): " << deviceName << " (DEFAULT) \n";
|
|
else
|
|
cout << i << "): " << deviceName << " \n";
|
|
}
|
|
cout << std::endl;
|
|
cout << "Choose a device by number: ";
|
|
unsigned int deviceSelection = 0;
|
|
cin >> deviceSelection;
|
|
cout << std::endl;
|
|
|
|
//Initialize the manager with the user settings
|
|
manager->initialize(manager->getAvailableDeviceName(deviceSelection));
|
|
|
|
//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();
|
|
|
|
//Create a IAudio object and load a sound from a file
|
|
cAudio::IAudio* mysound = manager->createFromFile("bling","../../media/bling.ogg",true);
|
|
|
|
//Set the IAudio Sound to play3d and loop
|
|
//play3d takes 4 arguments play3d(toloop,x,y,z,strength)
|
|
if(mysound && listener)
|
|
{
|
|
listener->setPosition(cAudio::cVector3(0,0,0));
|
|
mysound->play3d(cAudio::cVector3(0,0,0),1.0f,true);
|
|
mysound->setVolume(1.0);
|
|
|
|
//Play for 10 seconds
|
|
const int ticksToPlay = 10000;
|
|
int currentTick = 0;
|
|
int currentSecTick = 0;
|
|
|
|
while(mysound->playing() && currentTick < ticksToPlay)
|
|
{
|
|
//Figure out the location of our rotated sound
|
|
rot+=0.1f * 0.017453293f; //0.1 degrees a frame
|
|
|
|
//Sound "starts" at x=2.5, y=0, z=0
|
|
float x = 2.5f * cosf(rot) - 0.0f * sinf(rot);
|
|
float z = 0.0f * cosf(rot) + 2.5f * sinf(rot);
|
|
mysound->setPosition(cAudio::cVector3(x,0.0,z));
|
|
|
|
++currentTick;
|
|
|
|
if(currentTick/1000 > currentSecTick)
|
|
{
|
|
++currentSecTick;
|
|
std::cout << ".";
|
|
}
|
|
|
|
//Sleep for 1 ms to free some CPU
|
|
cAudio::cAudioSleep(1);
|
|
}
|
|
}
|
|
|
|
std::cout << std::endl;
|
|
|
|
//Delete all IAudio sounds
|
|
manager->release();
|
|
//Shutdown cAudio
|
|
manager->shutDown();
|
|
|
|
cAudio::destroyAudioManager(manager);
|
|
}
|
|
else
|
|
{
|
|
std::cout << "Failed to create audio playback manager. \n";
|
|
}
|
|
|
|
std::cout << "Press any key to quit \n";
|
|
std::cin.get();
|
|
std::cin.get();
|
|
|
|
return 0;
|
|
}
|