Commit bd722d03 authored by jpbl's avatar jpbl
Browse files

added example03.cpp

parent 99231e55
...@@ -30,55 +30,62 @@ ...@@ -30,55 +30,62 @@
using namespace SFLAudio; using namespace SFLAudio;
int main(int, char* []) struct Info
{ {
ALenum format1; ALenum format;
ALvoid *data1; ALvoid *data;
ALsizei size1; ALsizei size;
ALsizei freq1; ALsizei freq;
ALboolean loop1; ALboolean loop;
};
ALenum format2;
ALvoid *data2;
ALsizei size2;
ALsizei freq2;
ALboolean loop2;
int main(int argc, char* argv[])
{
AudioLayer *layer = SFLAudio::AudioManager::instance().currentLayer(); AudioLayer *layer = SFLAudio::AudioManager::instance().currentLayer();
Device *device = layer->openDevice(); Device *device = layer->openDevice();
Context *context = device->createContext(); Context *context = device->createContext();
// Load test.wav ALbyte *files[] = {"test.wav", "test2.wav"};
alutLoadWAVFile("test.wav",&format1,&data1,&size1,&freq1,&loop1);
ALenum error = alGetError();
if (error != AL_NO_ERROR) {
std::cerr << "OpenAL: loadWAVFile : " << alGetString(error);
return 1;
}
// Load test2.wav
alutLoadWAVFile("test2.wav",&format2,&data2,&size2,&freq2,&loop2); Info *infos = new Info[argc-1];
error = alGetError(); ALenum error;
if (error != AL_NO_ERROR) {
std::cerr << "OpenAL: loadWAVFile : " << alGetString(error); for(int i = 0; i < 2; i++) {
return 1; // Load test.wav
alutLoadWAVFile(files[i],
&infos[i].format,
&infos[i].data,
&infos[i].size,
&infos[i].freq,
&infos[i].loop);
error = alGetError();
if (error != AL_NO_ERROR) {
std::cerr << "OpenAL: loadWAVFile : " << alGetString(error);
return 1;
}
i++;
} }
Source *source1 = context->createSource(format1, freq1); for(int i = 0; i < argc - 1; i++) {
source1->play(data1, size1); Source *source = context->createSource(infos[i].format, infos[i].freq);
Source *source2 = context->createSource(format2, freq2); source->play(&infos[i].data, infos[i].size);
source2->play(data2, size2); }
// Unload test.wav and test2.wav for(int i = 0; i < argc - 1; i++) {
alutUnloadWAV(format1, data1, size1, freq1); // Unload wav files
alutUnloadWAV(format2, data2, size2, freq2); alutUnloadWAV(infos[i].format,
infos[i].data,
infos[i].size,
infos[i].freq);
}
std::cin.get(); std::cin.get();
error = alGetError(); error = alGetError();
if (error != AL_NO_ERROR) { if (error != AL_NO_ERROR) {
std::cerr << "OpenAL: unloadWAV : " << alGetString(error); std::cerr << "OpenAL: unloadWAV : " << alGetString(error);
} }
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment