- Timestamp:
- Oct 15, 2005, 11:44:14 PM (19 years ago)
- Location:
- trunk/src/lib/sound
- Files:
-
- 4 edited
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/sound/Makefile.am
r4750 r5386 5 5 6 6 libORXsound_a_SOURCES = sound_engine.cc \ 7 sound_source.cc \ 8 sound_buffer.cc \ 7 9 ogg_player.cc 8 10 9 11 noinst_HEADERS = sound_engine.h \ 12 sound_source.h \ 13 sound_buffer.h \ 10 14 ogg_player.h -
trunk/src/lib/sound/Makefile.in
r5351 r5386 54 54 libORXsound_a_AR = $(AR) $(ARFLAGS) 55 55 libORXsound_a_LIBADD = 56 am_libORXsound_a_OBJECTS = sound_engine.$(OBJEXT) ogg_player.$(OBJEXT) 56 am_libORXsound_a_OBJECTS = sound_engine.$(OBJEXT) \ 57 sound_source.$(OBJEXT) sound_buffer.$(OBJEXT) \ 58 ogg_player.$(OBJEXT) 57 59 libORXsound_a_OBJECTS = $(am_libORXsound_a_OBJECTS) 58 60 DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) … … 60 62 am__depfiles_maybe = depfiles 61 63 @AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/ogg_player.Po \ 62 @AMDEP_TRUE@ ./$(DEPDIR)/sound_engine.Po 64 @AMDEP_TRUE@ ./$(DEPDIR)/sound_buffer.Po \ 65 @AMDEP_TRUE@ ./$(DEPDIR)/sound_engine.Po \ 66 @AMDEP_TRUE@ ./$(DEPDIR)/sound_source.Po 63 67 CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ 64 68 $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) … … 183 187 noinst_LIBRARIES = libORXsound.a 184 188 libORXsound_a_SOURCES = sound_engine.cc \ 189 sound_source.cc \ 190 sound_buffer.cc \ 185 191 ogg_player.cc 186 192 187 193 noinst_HEADERS = sound_engine.h \ 194 sound_source.h \ 195 sound_buffer.h \ 188 196 ogg_player.h 189 197 … … 236 244 237 245 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ogg_player.Po@am__quote@ 246 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sound_buffer.Po@am__quote@ 238 247 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sound_engine.Po@am__quote@ 248 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sound_source.Po@am__quote@ 239 249 240 250 .cc.o: -
trunk/src/lib/sound/sound_buffer.cc
r5382 r5386 10 10 11 11 ### File Specific: 12 main-programmer: ...12 main-programmer: Benjamin Grauer 13 13 co-programmer: ... 14 14 */ 15 15 16 //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_SOUND 17 17 18 #include "proto_class.h" 18 #include "sound_buffer.h" 19 20 #include "sound_engine.h" 21 19 22 20 23 using namespace std; 21 24 22 25 26 ////////////////// 27 /* SOUND-BUFFER */ 28 ////////////////// 23 29 /** 24 * standard constructor25 * @ todo this constructor is not jet implemented - do it26 */27 ProtoClass::ProtoClass ()30 * Creates a Soundbuffer out of an inputfile 31 * @param fileName The name of the File 32 */ 33 SoundBuffer::SoundBuffer(const char* fileName) 28 34 { 29 this->setClassID(CL_PROTO_ID, "ProtoClass"); 35 this->setClassID(CL_SOUND_BUFFER, "SoundBuffer"); 36 this->setName(fileName); 30 37 31 /* If you make a new class, what is most probably the case when you write this file 32 don't forget to: 33 1. Add the new file new_class.cc to the ./src/Makefile.am 34 2. Add the class identifier to ./src/class_id.h eg. CL_NEW_CLASS 38 SoundEngine::getInstance()->addBuffer(this); 35 39 36 Advanced Topics: 37 - if you want to let your object be managed via the ObjectManager make sure to read 38 the object_manager.h header comments. You will use this most certanly only if you 39 make many objects of your class, like a weapon bullet. 40 */ 40 ALenum format; 41 ALvoid* data; 42 ALsizei freq; 43 44 ALenum result; 45 46 // generate a Buffer 47 alGenBuffers(1, &this->bufferID); 48 if ((result = alGetError()) != AL_NO_ERROR) 49 SoundEngine::PrintALErrorString(result); 50 51 // read in the wav data 52 /* according to http://www.edenwaith.com/products/pige/tutorials/openal.php the alutLoadWAVFile differs from platform to platform*/ 53 #ifdef __APPLE__ 54 alutLoadWAVFile((ALbyte*)fileName, &format, &data, &this->size, &freq); 55 #elif defined __WIN32__ 56 alutLoadWAVFile(fileName, &format, &data, &size, &freq, &this->loop); 57 #else 58 alutLoadWAVFile((ALbyte*)fileName, &format, &data, &this->size, &freq, &this->loop); 59 #endif 60 if ((result = alGetError()) != AL_NO_ERROR) 61 SoundEngine::PrintALErrorString(result); 62 63 // send the loaded wav data to the buffer 64 alBufferData(this->bufferID, format, data, this->size, freq); 65 if ((result = alGetError()) != AL_NO_ERROR) 66 SoundEngine::PrintALErrorString(result); 67 68 // remove the wav data (redundant) 69 alutUnloadWAV(format, data, this->size, freq); 70 if ((result = alGetError()) != AL_NO_ERROR) 71 SoundEngine::PrintALErrorString(result); 41 72 } 42 73 43 44 /** 45 * standard deconstructor 46 */ 47 ProtoClass::~ProtoClass () 74 SoundBuffer::~SoundBuffer() 48 75 { 49 // delete what has to be deleted here 76 // SoundEngine::getInstance()->removeBuffer(this); 77 alDeleteBuffers(1, &this->bufferID); 50 78 } -
trunk/src/lib/sound/sound_buffer.h
r5382 r5386 1 1 /*! 2 * @file proto_class.h3 * @brief Definition of ...2 * @file sound_buffer.h 3 * @brief Definition of the sound-buffer-class 4 4 */ 5 5 6 #ifndef _ PROTO_CLASS_H7 #define _ PROTO_CLASS_H6 #ifndef _SOUND_BUFFER_H 7 #define _SOUND_BUFFER_H 8 8 9 9 #include "base_object.h" 10 #include "alincl.h" 10 11 11 12 // FORWARD DECLARATION 12 13 14 //! A class that represents a datastructure to play Sounds. 15 class SoundBuffer : public BaseObject 16 { 17 public: 18 SoundBuffer(const char* fileName); 19 ~SoundBuffer(); 13 20 21 /** @returns the ID of the buffer used in this SoundBuffer */ 22 inline ALuint getID() const { return this->bufferID; } 14 23 15 //! A class for ... 16 class ProtoClass : public BaseObject { 24 private: 25 ALuint bufferID; //!< The address of the Buffer. 17 26 18 public: 19 ProtoClass(); 20 virtual ~ProtoClass(); 21 22 23 private: 24 27 ALsizei size; //!< The size of the Buffer. 28 ALboolean loop; //!< loop information. 25 29 }; 26 30 27 #endif /* _ PROTO_CLASS_H */31 #endif /* _SOUND_BUFFER_H */ -
trunk/src/lib/sound/sound_engine.cc
r5385 r5386 17 17 */ 18 18 19 //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY 19 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_SOUND 20 20 21 21 #include "sound_engine.h" … … 31 31 32 32 using namespace std; 33 34 //////////////////35 /* SOUND-BUFFER */36 //////////////////37 /**38 * Creates a Soundbuffer out of an inputfile39 * @param fileName The name of the File40 */41 SoundBuffer::SoundBuffer(const char* fileName)42 {43 this->setClassID(CL_SOUND_BUFFER, "SoundBuffer");44 this->setName(fileName);45 46 SoundEngine::getInstance()->addBuffer(this);47 48 ALenum format;49 ALvoid* data;50 ALsizei freq;51 52 ALenum result;53 54 // generate a Buffer55 alGenBuffers(1, &this->bufferID);56 if ((result = alGetError()) != AL_NO_ERROR)57 SoundEngine::PrintALErrorString(result);58 59 // read in the wav data60 /* according to http://www.edenwaith.com/products/pige/tutorials/openal.php the alutLoadWAVFile differs from platform to platform*/61 #ifdef __APPLE__62 alutLoadWAVFile((ALbyte*)fileName, &format, &data, &this->size, &freq);63 #elif defined __WIN32__64 alutLoadWAVFile(fileName, &format, &data, &size, &freq, &this->loop);65 #else66 alutLoadWAVFile((ALbyte*)fileName, &format, &data, &this->size, &freq, &this->loop);67 #endif68 if ((result = alGetError()) != AL_NO_ERROR)69 SoundEngine::PrintALErrorString(result);70 71 // send the loaded wav data to the buffer72 alBufferData(this->bufferID, format, data, this->size, freq);73 if ((result = alGetError()) != AL_NO_ERROR)74 SoundEngine::PrintALErrorString(result);75 76 // remove the wav data (redundant)77 alutUnloadWAV(format, data, this->size, freq);78 if ((result = alGetError()) != AL_NO_ERROR)79 SoundEngine::PrintALErrorString(result);80 }81 82 SoundBuffer::~SoundBuffer()83 {84 // SoundEngine::getInstance()->removeBuffer(this);85 alDeleteBuffers(1, &this->bufferID);86 }87 88 //////////////////89 /* SOUND-SOURCE */90 //////////////////91 /**92 * creates a SoundSource at position sourceNode with the SoundBuffer buffer93 */94 SoundSource::SoundSource(const PNode* sourceNode, const SoundBuffer* buffer)95 {96 this->setClassID(CL_SOUND_SOURCE, "SoundSource");97 98 ALenum result;99 100 // adding the Source to the SourcesList of the SoundEngine101 SoundEngine::getInstance()->addSource(this);102 103 this->buffer = buffer;104 this->sourceNode = sourceNode;105 106 alGenSources(1, &this->sourceID);107 if ((result = alGetError()) != AL_NO_ERROR)108 SoundEngine::PrintALErrorString(result);109 if (this->buffer != NULL)110 alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID());111 alSourcef (this->sourceID, AL_PITCH, 1.0 );112 alSourcef (this->sourceID, AL_GAIN, SoundEngine::getInstance()->getEffectsVolume() );113 alSourcei (sourceID, AL_LOOPING, AL_FALSE );114 }115 116 /**117 * deletes a SoundSource118 */119 SoundSource::~SoundSource()120 {121 //SoundEngine::getInstance()->removeSource(this);122 alDeleteSources(1, &this->sourceID);123 }124 125 /**126 * Plays back a SoundSource127 */128 void SoundSource::play()129 {130 alSourcePlay(this->sourceID);131 }132 133 /**134 * Plays back buffer on this Source135 * @param buffer the buffer to play back on this Source136 */137 void SoundSource::play(const SoundBuffer* buffer)138 {139 alSourceStop(this->sourceID);140 alSourcei (this->sourceID, AL_BUFFER, buffer->getID());141 alSourcePlay(this->sourceID);142 143 if (unlikely(this->buffer != NULL))144 alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID());145 }146 147 /**148 * Stops playback of a SoundSource149 */150 void SoundSource::stop()151 {152 alSourceStop(this->sourceID);153 }154 155 /**156 * Pauses Playback of a SoundSource157 */158 void SoundSource::pause()159 {160 alSourcePause(this->sourceID);161 }162 163 /**164 * Rewinds Playback of a SoundSource165 */166 void SoundSource::rewind()167 {168 alSourceRewind(this->sourceID);169 }170 171 /**172 * sets the RolloffFactor of the Sound emitted from the SoundSource173 * @param rolloffFactor The Factor described174 175 this tells openAL how fast the Sounds decay outward from the Source176 */177 void SoundSource::setRolloffFactor(ALfloat rolloffFactor)178 {179 alSourcef(this->sourceID, AL_ROLLOFF_FACTOR, rolloffFactor);180 }181 182 33 183 34 … … 439 290 const char* devWalk = deviceList; 440 291 if (alcIsExtensionPresent(NULL, (ALubyte*)"ALC_ENUMERATION_EXT") == AL_TRUE) { // try out enumeration extension 441 printf("Enumeration-extension found\n");442 443 printf("Default device: %s\n", defaultDevice);292 PRINTF(3)("Enumeration-extension found\n"); 293 294 PRINTF(3)("Default device: %s\n", defaultDevice); 444 295 do 445 296 { 446 printf("%s\n", devWalk);297 PRINTF(3)("%s\n", devWalk); 447 298 devWalk += strlen(devWalk)+1; 448 299 } while (devWalk[0] != '\0'); -
trunk/src/lib/sound/sound_engine.h
r5216 r5386 10 10 #include "alincl.h" 11 11 12 #include "sound_buffer.h" 13 #include "sound_source.h" 14 12 15 #define SOUND_DOPPLER_FACTOR 0.001 //!< A factor for the audible doppler effect 13 16 #define SOUND_DOPPLER_VELOCITY 5000000 //!< A factor for the TravelSpeed of sound … … 17 20 template<class T> class tList; 18 21 class IniParser; 19 20 21 //! A class that represents a datastructure to play Sounds.22 class SoundBuffer : public BaseObject23 {24 public:25 SoundBuffer(const char* fileName);26 ~SoundBuffer();27 28 /** @returns the ID of the buffer used in this SoundBuffer */29 inline ALuint getID() const { return this->bufferID; }30 31 private:32 ALuint bufferID; //!< The address of the Buffer.33 34 ALsizei size; //!< The size of the Buffer.35 ALboolean loop; //!< loop information.36 };37 38 //! A class that represents a SoundSource39 class SoundSource : public BaseObject40 {41 public:42 SoundSource(const PNode* sourceNode = NULL, const SoundBuffer* buffer = NULL);43 ~SoundSource();44 45 // user interaction46 void play();47 void play(const SoundBuffer* buffer);48 void stop();49 void pause();50 void rewind();51 52 // development functions53 /** @returns The ID of this Source */54 inline ALuint getID() const { return this->sourceID; }55 /** @returns the SoundBuffer of this Source */56 inline const SoundBuffer* getBuffer() const { return this->buffer; }57 /** @returns the SourceNode of this Source */58 inline const PNode* getNode() const { return this->sourceNode;}59 60 void setRolloffFactor(ALfloat rolloffFactor);61 62 private:63 ALuint sourceID; //!< The ID of the Source64 const SoundBuffer* buffer; //!< The buffer to play in this source.65 const PNode* sourceNode; //!< The SourceNode represente the position/velocity... of this source.66 };67 68 69 22 70 23 //! A class that handles audio via the openAudioLibrary -
trunk/src/lib/sound/sound_source.cc
r5382 r5386 10 10 11 11 ### File Specific: 12 main-programmer: ...12 main-programmer: Benjamin Grauer 13 13 co-programmer: ... 14 14 */ 15 15 16 //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_SOUND 17 17 18 #include "proto_class.h" 18 #include "sound_source.h" 19 #include "sound_engine.h" 20 #include "alincl.h" 21 #include "compiler.h" 19 22 20 23 using namespace std; 21 24 25 /** 26 * creates a SoundSource at position sourceNode with the SoundBuffer buffer 27 */ 28 SoundSource::SoundSource(const PNode* sourceNode, const SoundBuffer* buffer) 29 { 30 this->setClassID(CL_SOUND_SOURCE, "SoundSource"); 31 32 ALenum result; 33 34 // adding the Source to the SourcesList of the SoundEngine 35 SoundEngine::getInstance()->addSource(this); 36 37 this->buffer = buffer; 38 this->sourceNode = sourceNode; 39 40 alGenSources(1, &this->sourceID); 41 if ((result = alGetError()) != AL_NO_ERROR) 42 SoundEngine::PrintALErrorString(result); 43 if (this->buffer != NULL) 44 alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID()); 45 alSourcef (this->sourceID, AL_PITCH, 1.0 ); 46 alSourcef (this->sourceID, AL_GAIN, SoundEngine::getInstance()->getEffectsVolume() ); 47 alSourcei (sourceID, AL_LOOPING, AL_FALSE ); 48 } 22 49 23 50 /** 24 * standard constructor 25 * @todo this constructor is not jet implemented - do it 26 */ 27 ProtoClass::ProtoClass () 51 * deletes a SoundSource 52 */ 53 SoundSource::~SoundSource() 28 54 { 29 this->setClassID(CL_PROTO_ID, "ProtoClass"); 30 31 /* If you make a new class, what is most probably the case when you write this file 32 don't forget to: 33 1. Add the new file new_class.cc to the ./src/Makefile.am 34 2. Add the class identifier to ./src/class_id.h eg. CL_NEW_CLASS 35 36 Advanced Topics: 37 - if you want to let your object be managed via the ObjectManager make sure to read 38 the object_manager.h header comments. You will use this most certanly only if you 39 make many objects of your class, like a weapon bullet. 40 */ 55 //SoundEngine::getInstance()->removeSource(this); 56 alDeleteSources(1, &this->sourceID); 41 57 } 42 58 59 /** 60 * Plays back a SoundSource 61 */ 62 void SoundSource::play() 63 { 64 alSourcePlay(this->sourceID); 65 } 43 66 44 67 /** 45 * standard deconstructor 46 */ 47 ProtoClass::~ProtoClass () 68 * Plays back buffer on this Source 69 * @param buffer the buffer to play back on this Source 70 */ 71 void SoundSource::play(const SoundBuffer* buffer) 48 72 { 49 // delete what has to be deleted here 73 alSourceStop(this->sourceID); 74 alSourcei (this->sourceID, AL_BUFFER, buffer->getID()); 75 alSourcePlay(this->sourceID); 76 77 if (unlikely(this->buffer != NULL)) 78 alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID()); 50 79 } 80 81 /** 82 * Stops playback of a SoundSource 83 */ 84 void SoundSource::stop() 85 { 86 alSourceStop(this->sourceID); 87 } 88 89 /** 90 * Pauses Playback of a SoundSource 91 */ 92 void SoundSource::pause() 93 { 94 alSourcePause(this->sourceID); 95 } 96 97 /** 98 * Rewinds Playback of a SoundSource 99 */ 100 void SoundSource::rewind() 101 { 102 alSourceRewind(this->sourceID); 103 } 104 105 /** 106 * sets the RolloffFactor of the Sound emitted from the SoundSource 107 * @param rolloffFactor The Factor described 108 109 this tells openAL how fast the Sounds decay outward from the Source 110 */ 111 void SoundSource::setRolloffFactor(ALfloat rolloffFactor) 112 { 113 alSourcef(this->sourceID, AL_ROLLOFF_FACTOR, rolloffFactor); 114 } 115 -
trunk/src/lib/sound/sound_source.h
r5382 r5386 1 1 /*! 2 * @file proto_class.h3 * @brief Definition of ...2 * @file sound_source.h 3 * @brief Definition of the SoundSource. 4 4 */ 5 5 6 #ifndef _ PROTO_CLASS_H7 #define _ PROTO_CLASS_H6 #ifndef _SOUND_SOURCE_H 7 #define _SOUND_SOURCE_H 8 8 9 9 #include "base_object.h" 10 #include "alincl.h" 10 11 11 12 // FORWARD DECLARATION 13 class SoundBuffer; 14 class PNode; 12 15 16 //! A class that represents a SoundSource 17 class SoundSource : public BaseObject 18 { 19 public: 20 SoundSource(const PNode* sourceNode = NULL, const SoundBuffer* buffer = NULL); 21 ~SoundSource(); 13 22 23 // user interaction 24 void play(); 25 void play(const SoundBuffer* buffer); 26 void stop(); 27 void pause(); 28 void rewind(); 14 29 15 //! A class for ... 16 class ProtoClass : public BaseObject { 30 // development functions 31 /** @returns The ID of this Source */ 32 inline ALuint getID() const { return this->sourceID; } 33 /** @returns the SoundBuffer of this Source */ 34 inline const SoundBuffer* getBuffer() const { return this->buffer; } 35 /** @returns the SourceNode of this Source */ 36 inline const PNode* getNode() const { return this->sourceNode;} 17 37 18 public: 19 ProtoClass(); 20 virtual ~ProtoClass(); 38 void setRolloffFactor(ALfloat rolloffFactor); 21 39 22 23 private: 24 40 private: 41 ALuint sourceID; //!< The ID of the Source 42 const SoundBuffer* buffer; //!< The buffer to play in this source. 43 const PNode* sourceNode; //!< The SourceNode represente the position/velocity... of this source. 25 44 }; 26 27 #endif /* _PROTO_CLASS_H */ 45 #endif /* _SOUND_SOURCE_H */
Note: See TracChangeset
for help on using the changeset viewer.