3f06749573
Added the ability for the user to provide a DataSourceFactory, which cAudio will use to get audio data. This interface can be overridden to provide cAudio the ability to read from zip archives, TCP streams, potentially any location. DataSourceFactories can also be prioritized. Made the existing FileSource a factory and registered it by default with the manager. If the user wishes to prevent cAudio from reading from disk, unRegister the "FileSystem" data source. Made tutorials conform with the changes to the API.
78 lines
2.1 KiB
C++
78 lines
2.1 KiB
C++
//****************************************************************
|
|
//cAudio 2.0 Tutorial 1
|
|
//Basic 2d Audio
|
|
//****************************************************************
|
|
|
|
#include <iostream>
|
|
#include <string>
|
|
|
|
//Include cAudio.h so we can work wtih cAudio
|
|
#include "../../include/cAudio.h"
|
|
|
|
using namespace std;
|
|
|
|
int main(int argc, char* argv[])
|
|
{
|
|
//Some fancy text
|
|
cout << "cAudio 1.7.1 Tutorial 1: 2DSound \n \n";
|
|
|
|
//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));
|
|
|
|
//Create a IAudio object and load a sound from a file
|
|
cAudio::IAudioSource* mysound = manager->create("bling","../../media/cAudioTheme1.ogg",true);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
//Delete all IAudio sounds
|
|
manager->releaseAllSources();
|
|
//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;
|
|
}
|