2011-05-19 06:24:29 +02:00
|
|
|
//****************************************************************
|
2011-05-19 06:36:14 +02:00
|
|
|
//cAudio 2.2.0 Tutorial 1
|
2011-05-19 06:24:29 +02:00
|
|
|
//Basic 2d Audio
|
|
|
|
//****************************************************************
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
//Include cAudio.h so we can work wtih cAudio
|
|
|
|
#include "cAudio.h"
|
2011-05-29 11:47:42 +02:00
|
|
|
#ifdef CAUDIO_PLATFORM_WIN
|
|
|
|
# define AUDIO_FILE(_soundName_) CAUDIO_MEDIA_ROOT##_soundName_
|
|
|
|
#else
|
|
|
|
# define AUDIO_FILE(_soundName_) CAUDIO_MEDIA_ROOT#_soundName_
|
|
|
|
#endif
|
2011-05-19 06:24:29 +02:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
//Some fancy text
|
2011-05-19 06:36:14 +02:00
|
|
|
cout << "cAudio 2.2.0 Tutorial 1: Basic 2D Audio. \n \n";
|
2011-05-19 06:24:29 +02:00
|
|
|
|
|
|
|
//Create an uninitialized Audio Manager
|
|
|
|
cAudio::IAudioManager* manager = cAudio::createAudioManager(false);
|
|
|
|
|
|
|
|
if(manager)
|
|
|
|
{
|
|
|
|
//Allow the user to choose a playback device
|
|
|
|
cout << "\nAvailable Playback Devices: \n";
|
2011-06-05 19:02:47 +02:00
|
|
|
cAudio::IAudioDeviceList* pDeviceList = cAudio::createAudioDeviceList();
|
|
|
|
unsigned int deviceCount = pDeviceList->getDeviceCount();
|
|
|
|
cAudio::cAudioString defaultDeviceName = pDeviceList->getDefaultDeviceName();
|
2011-05-19 06:24:29 +02:00
|
|
|
for(unsigned int i=0; i<deviceCount; ++i)
|
|
|
|
{
|
2011-06-05 19:02:47 +02:00
|
|
|
cAudio::cAudioString deviceName = pDeviceList->getDeviceName(i);
|
2011-05-19 06:24:29 +02:00
|
|
|
if(deviceName.compare(defaultDeviceName) == 0)
|
2011-06-05 19:02:47 +02:00
|
|
|
cout << i << "): " << deviceName.c_str() << " [DEFAULT] \n";
|
2011-05-19 06:24:29 +02:00
|
|
|
else
|
2011-06-05 19:02:47 +02:00
|
|
|
cout << i << "): " << deviceName.c_str() << " \n";
|
2011-05-19 06:24:29 +02:00
|
|
|
}
|
|
|
|
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
|
2011-06-05 19:02:47 +02:00
|
|
|
manager->initialize(pDeviceList->getDeviceName(deviceSelection).c_str());
|
|
|
|
CAUDIO_DELETE pDeviceList;
|
|
|
|
pDeviceList = 0;
|
2011-05-19 06:24:29 +02:00
|
|
|
|
|
|
|
//Create a IAudio object and load a sound from a file
|
2011-05-29 11:47:42 +02:00
|
|
|
#ifdef CAUDIO_PLATFORM_WIN
|
|
|
|
cAudio::IAudioSource* mysound = manager->create("bling", AUDIO_FILE("cAudioTheme1.ogg"),true);
|
|
|
|
#else
|
|
|
|
cAudio::IAudioSource* mysound = manager->create("bling", AUDIO_FILE(cAudioTheme1.ogg),true);
|
|
|
|
#endif
|
2011-06-24 23:29:18 +02:00
|
|
|
|
|
|
|
for (size_t i=0; i<10; i++)
|
|
|
|
{
|
|
|
|
#ifdef CAUDIO_PLATFORM_WIN
|
|
|
|
manager->play2D(AUDIO_FILE("bling.ogg"));
|
|
|
|
#else
|
|
|
|
manager->play2D(AUDIO_FILE(bling.ogg));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-05-19 06:24:29 +02:00
|
|
|
if(mysound)
|
|
|
|
{
|
|
|
|
mysound->setVolume(0.5);
|
|
|
|
//Set the IAudio Sound to play2d and loop
|
|
|
|
mysound->play2d(false);
|
|
|
|
|
|
|
|
//Wait for the sound to finish playing
|
|
|
|
while(mysound->isPlaying())
|
|
|
|
cAudio::cAudioSleep(10);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//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;
|
|
|
|
}
|