diff --git a/src/audio/OpenAL/Makefile.am b/src/audio/OpenAL/Makefile.am index 1b04bc25bbefcf4749134061de95d608c1b35639..5871378bf17447109e07b491352cb4bb966a1a1b 100644 --- a/src/audio/OpenAL/Makefile.am +++ b/src/audio/OpenAL/Makefile.am @@ -1,5 +1,5 @@ if MAINTENER_CODE -noinst_PROGRAMS = example01 example02 +noinst_PROGRAMS = example01 example02 example03 noinst_LTLIBRARIES = libsflaudio.la libsflaudio_la_SOURCES = \ @@ -29,5 +29,6 @@ LDADD = libsflaudio.la $(PORTAUDIO_LIBS) -lopenal -lportaudio example01_SOURCES = example01.cpp example02_SOURCES = example02.cpp +example03_SOURCES = example03.cpp endif diff --git a/src/audio/OpenAL/NullSource.hpp b/src/audio/OpenAL/NullSource.hpp index d5f51efea1b72ff2f1b5f7f9eb5f96a9dd7d8516..4b0c24f3b87c8448f88158855228fcffce18f9af 100644 --- a/src/audio/OpenAL/NullSource.hpp +++ b/src/audio/OpenAL/NullSource.hpp @@ -33,6 +33,7 @@ namespace SFLAudio virtual bool isNull() {return true;}; virtual bool isPlaying(); virtual void play(void *data, int size); + virtual void stop(); }; } diff --git a/src/audio/OpenAL/OpenALSource.cpp b/src/audio/OpenAL/OpenALSource.cpp index ff91892bda5a83595c03201acfbccca9cb835f13..8f5a90a7d18c5f12f504fc0340f991c973bddb4a 100644 --- a/src/audio/OpenAL/OpenALSource.cpp +++ b/src/audio/OpenAL/OpenALSource.cpp @@ -170,6 +170,8 @@ SFLAudio::OpenALSource::play(void *data, int size) { ALboolean loop; + alGetError(); + // Copy test.wav data into AL Buffer 0 alBufferData(mBuffer, getFormat(), data, size, getFrequency()); ALenum error = alGetError(); @@ -179,3 +181,9 @@ SFLAudio::OpenALSource::play(void *data, int size) alSourcePlay(mSource); } + +void +SFLAudio::OpenALSource::stop() +{ + alSourceStop(mSource); +} diff --git a/src/audio/OpenAL/OpenALSource.hpp b/src/audio/OpenAL/OpenALSource.hpp index 051f95492f3813f4941088dcd22831d3cbdaef43..c3d30b6b5bcb8d2579b357852cac0fdcd172043a 100644 --- a/src/audio/OpenAL/OpenALSource.hpp +++ b/src/audio/OpenAL/OpenALSource.hpp @@ -42,6 +42,7 @@ namespace SFLAudio // Source functions virtual bool isPlaying(); virtual void play(void *data, int size); + virtual void stop(); private: static bool genBuffer(ALuint &buffer); diff --git a/src/audio/OpenAL/README.txt b/src/audio/OpenAL/README.txt index 6ed8af5f60b0034b30cd2cef07bcb474c0c054d7..fc595d4d2db99566a35b98b4154cda359a5f96e0 100644 --- a/src/audio/OpenAL/README.txt +++ b/src/audio/OpenAL/README.txt @@ -1 +1,3 @@ -example01.cpp: This is an enumeration of device example. \ No newline at end of file +example01.cpp: This is an enumeration of device example. +example02.cpp: A simple WAV player. +example03.cpp: A simple WAV player, with 2 files playing at the same time. \ No newline at end of file diff --git a/src/audio/OpenAL/Source.hpp b/src/audio/OpenAL/Source.hpp index 234167b69a35eee1271ed753cdceb35740abcff2..862bce2e44754a3c14582b3af84f5da47ae19c01 100644 --- a/src/audio/OpenAL/Source.hpp +++ b/src/audio/OpenAL/Source.hpp @@ -34,6 +34,7 @@ namespace SFLAudio virtual bool isNull() {return false;} virtual bool isPlaying() = 0; virtual void play(void *data, int size) = 0; + virtual void stop() = 0; int getFrequency() {return mFreq;} int getFormat() {return mFormat;} diff --git a/src/audio/OpenAL/example02.cpp b/src/audio/OpenAL/example02.cpp index 00ca61a6f9232e072ea67ad09b988bff540fc136..785eda71cc3c085971cc16b03b987d81cdaaa8e8 100644 --- a/src/audio/OpenAL/example02.cpp +++ b/src/audio/OpenAL/example02.cpp @@ -39,12 +39,8 @@ int main(int, char* []) ALboolean loop; AudioLayer *layer = SFLAudio::AudioManager::instance().currentLayer(); - std::cout << "Layer: " << layer->getName() << std::endl; - Device *device = layer->openDevice(); - std::cout << " Device: " << device->getName() << std::endl; Context *context = device->createContext(); - std::cout << " Context is null: " << (context->isNull() ? "true" : "false") << std::endl; // Load test.wav alutLoadWAVFile("test.wav",&format,&data,&size,&freq,&loop); @@ -55,17 +51,16 @@ int main(int, char* []) } Source *source = context->createSource(format, freq); - std::cout << " Source is null: " << (source->isNull() ? "true" : "false") << std::endl; source->play(data, size); - std::cout << "Unloading test.wav" << std::endl; // Unload test.wav alutUnloadWAV(format, data, size, freq); + std::cin.get(); error = alGetError(); + if (error != AL_NO_ERROR) { std::cerr << "OpenAL: unloadWAV : " << alGetString(error); } - std::cin.get(); } diff --git a/src/audio/OpenAL/example03.cpp b/src/audio/OpenAL/example03.cpp new file mode 100644 index 0000000000000000000000000000000000000000..603f5501fe8e7830b16944ed79151d7f78b6afeb --- /dev/null +++ b/src/audio/OpenAL/example03.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2004-2005 Savoir-Faire Linux inc. + * Author: Jean-Philippe Barrette-LaPierre + * <jean-philippe.barrette-lapierre@savoirfairelinux.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include <iostream> +#include <list> +#include <string> + +#include <AL/al.h> +#include <AL/alc.h> +#include <AL/alut.h> + +#include "SFLAudio.hpp" + +using namespace SFLAudio; + +int main(int, char* []) +{ + ALenum format1; + ALvoid *data1; + ALsizei size1; + ALsizei freq1; + ALboolean loop1; + + ALenum format2; + ALvoid *data2; + ALsizei size2; + ALsizei freq2; + ALboolean loop2; + + AudioLayer *layer = SFLAudio::AudioManager::instance().currentLayer(); + Device *device = layer->openDevice(); + Context *context = device->createContext(); + + // Load test.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); + error = alGetError(); + if (error != AL_NO_ERROR) { + std::cerr << "OpenAL: loadWAVFile : " << alGetString(error); + return 1; + } + + Source *source1 = context->createSource(format1, freq1); + source1->play(data1, size1); + Source *source2 = context->createSource(format2, freq2); + source2->play(data2, size2); + + // Unload test.wav and test2.wav + alutUnloadWAV(format1, data1, size1, freq1); + alutUnloadWAV(format2, data2, size2, freq2); + std::cin.get(); + error = alGetError(); + + if (error != AL_NO_ERROR) { + std::cerr << "OpenAL: unloadWAV : " << alGetString(error); + } + + +} +