- Timestamp:
- Sep 24, 2006, 12:58:19 PM (18 years ago)
- Location:
- branches/new_class_id/src/lib/sound
- Files:
-
- 3 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/new_class_id/src/lib/sound/Makefile.am
r5475 r9803 7 7 sound_source.cc \ 8 8 sound_buffer.cc \ 9 sound_buffer_data.cc \ 9 10 ogg_player.cc 10 11 … … 12 13 sound_source.h \ 13 14 sound_buffer.h \ 15 sound_buffer_data.h \ 14 16 ogg_player.h -
branches/new_class_id/src/lib/sound/sound_buffer.cc
r9715 r9803 39 39 /* SOUND-BUFFER */ 40 40 ////////////////// 41 SoundBuffer::SoundBuffer() 42 : data(new SoundBufferData) 43 { 44 this->registerObject(this, SoundBuffer::_objectList); 45 } 41 46 /** 42 * Creates a Soundbuffer out of an inputfile47 * @brief Creates a Soundbuffer out of an inputfile 43 48 * @param fileName The name of the File 44 49 */ 45 50 SoundBuffer::SoundBuffer(const std::string& fileName) 51 : data(new SoundBufferData) 46 52 { 47 53 this->registerObject(this, SoundBuffer::_objectList); 48 54 this->setName(fileName); 49 55 50 // generate a Buffer 51 alGenBuffers(1, &this->bufferID); 52 SoundEngine::checkError("Generate Buffer", __LINE__); 53 if (!nocaseCmp(fileName.substr(fileName.size() - 3), "WAV")) 54 { 55 this->loadWAV(fileName); 56 } 57 else if (!nocaseCmp(fileName.substr(fileName.size() - 3), "OGG")) 58 this->loadOGG(fileName); 59 60 } 61 62 SoundBuffer::~SoundBuffer() 63 { 64 // SoundEngine::getInstance()->removeBuffer(this); 65 alDeleteBuffers(1, &this->bufferID); 66 SoundEngine::checkError("SoundBuffer: Delete Buffer", __LINE__); 67 } 68 69 /** 70 * @brief loads a Waveform from the local fileSystem into this Source. 71 * @param fileName the Name of the File to Load. 72 * @returns true on success. 73 */ 74 bool SoundBuffer::loadWAV(const std::string& fileName) 75 { 76 SDL_AudioSpec wavSpec; 77 Uint32 wavLength; 78 Uint8 *wavBuffer; 79 80 /* Load the WAV */ 81 if( SDL_LoadWAV(fileName.c_str(), &wavSpec, &wavBuffer, &wavLength) == NULL) 82 { 83 PRINTF(2)("Could not open %s: %s\n", fileName.c_str(), SDL_GetError()); 84 return false; 85 } 86 #if SDL_BYTEORDER == SDL_BIG_ENDIAN 87 if ( !( wavSpec.format == AUDIO_U8 || wavSpec.format == AUDIO_S8 ) ) 88 { 89 int cnt = wavLength/2; 90 Uint16* wavBufferAsShorts = ( Uint16* )wavBuffer; 91 for ( int i = 0; i < cnt; ++i, ++wavBufferAsShorts ) 92 *wavBufferAsShorts = SDL_Swap16( *wavBufferAsShorts ); 93 } 94 #endif 95 alBufferData(this->bufferID, SoundBuffer::sdlAudioSpecToAlFormat(&wavSpec), 96 wavBuffer, wavLength, wavSpec.freq); 97 98 SDL_FreeWAV(wavBuffer); 99 if (SoundEngine::checkError("Could not load Wave file", __LINE__)) 100 return true; 101 else 102 return false; 103 } 104 105 106 #ifndef AL_FORMAT_VORBIS_EXT 107 #define AL_FORMAT_VORBIS_EXT 0x100030 108 #endif 109 /** 110 * @brief loads an OGG-file into a SOundBuffer 111 * @param fileName the Name of the File to load. 112 * @returns true on success (file exists and is fully loaded), false otherwise. 113 */ 114 bool SoundBuffer::loadOGG(const std::string& fileName) 115 { 116 void* ovdata; 117 FILE* fh; 118 119 fh = fopen( fileName.c_str() , "rb") ; 120 if( fh != NULL ) 121 { 122 struct stat sbuf ; 123 124 if(stat( fileName.c_str(), &sbuf ) != -1) 125 { 126 ovdata = malloc(sbuf.st_size); 127 if(ovdata != NULL) 128 { 129 fread( ovdata, 1, sbuf.st_size, fh); 130 131 alBufferData( this->bufferID, 132 AL_FORMAT_VORBIS_EXT, 133 ovdata, 134 sbuf.st_size, 135 1) ; 136 SoundEngine::checkError("Could not load OGG file", __LINE__); 137 138 free(ovdata); 139 } 140 fclose(fh); 141 } 142 else 143 return false; 144 } 145 else 146 return false; 147 148 return true ; 149 150 } 151 152 153 /** 154 * @brief converts an SDL_AudioSpec into a valid OpenAL AUDIO_FORMAT enumerator 155 * @param audiospec the AudioSpec to convert. 156 * @returns the AL_FORMAT 157 */ 158 ALenum SoundBuffer::sdlAudioSpecToAlFormat(const SDL_AudioSpec* audiospec) 159 { 160 assert (audiospec != NULL); 161 bool stereo = true; 162 bool is16Bit = true; 163 if (audiospec->format == AUDIO_U8 || audiospec->format == AUDIO_S8) 164 is16Bit = false; 165 if (audiospec->channels == 1) 166 stereo = false; 167 168 if (!stereo && !is16Bit) 169 return AL_FORMAT_MONO8; 170 else if (!stereo && is16Bit) 171 return AL_FORMAT_MONO16; 172 else if (stereo && !is16Bit) 173 return AL_FORMAT_STEREO8; 174 else /* if (stereo && is16Bit) */ 175 return AL_FORMAT_STEREO16; 56 this->load(fileName); 176 57 } 177 58 } -
branches/new_class_id/src/lib/sound/sound_buffer.h
r9715 r9803 10 10 #include "alincl.h" 11 11 12 // FORWARD DECLARATION 13 typedef struct SDL_AudioSpec; 12 #include "sound_buffer_data.h" 14 13 15 14 namespace OrxSound … … 20 19 ObjectListDeclaration(SoundBuffer); 21 20 public: 21 SoundBuffer(); 22 22 SoundBuffer(const std::string& fileName); 23 virtual ~SoundBuffer();24 23 25 bool loadWAV(const std::string& fileName); 26 bool loadOGG(const std::string& fileName); 24 /** @see SoundBufferData::load */ 25 inline bool load(const std::string& fileName) { return this->data->load(fileName); }; 26 /** @see SoundBufferData::loadWav */ 27 inline bool loadWAV(const std::string& fileName) { return this->data->loadWAV(fileName); }; 28 /** @see SoundBufferData::loadOgg */ 29 inline bool loadOGG(const std::string& fileName) { return this->data->loadOGG(fileName); }; 27 30 28 31 /** @returns the ID of the buffer used in this SoundBuffer */ 29 inline ALuint getID() const { return this-> bufferID; }32 inline ALuint getID() const { return this->data->getID(); } 30 33 31 34 private: 32 ALenum sdlAudioSpecToAlFormat(const SDL_AudioSpec* audiospec); 33 34 private: 35 ALuint bufferID; //!< The address of the Buffer. 36 37 ALsizei size; //!< The size of the Buffer. 38 ALboolean loop; //!< loop information. 35 SoundBufferData::Pointer data; 39 36 }; 40 37 } -
branches/new_class_id/src/lib/sound/sound_buffer_data.cc
r9801 r9803 16 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_SOUND 17 17 18 #include "sound_buffer .h"18 #include "sound_buffer_data.h" 19 19 20 20 #include "sound_engine.h" … … 35 35 namespace OrxSound 36 36 { 37 ObjectListDefinition(SoundBuffer );37 ObjectListDefinition(SoundBufferData); 38 38 ////////////////// 39 39 /* SOUND-BUFFER */ 40 40 ////////////////// 41 41 /** 42 * Creates a Soundbufferout of an inputfile42 * @brief Creates a SoundbufferData out of an inputfile 43 43 * @param fileName The name of the File 44 44 */ 45 SoundBuffer ::SoundBuffer(const std::string& fileName)45 SoundBufferData::SoundBufferData() 46 46 { 47 this->registerObject(this, SoundBuffer ::_objectList);48 this-> setName(fileName);47 this->registerObject(this, SoundBufferData::_objectList); 48 this->bufferID = 0; 49 49 50 // generate a Buffer 51 alGenBuffers(1, &this->bufferID); 52 SoundEngine::checkError("Generate Buffer", __LINE__); 53 if (!nocaseCmp(fileName.substr(fileName.size() - 3), "WAV")) 54 { 55 this->loadWAV(fileName); 56 } 57 else if (!nocaseCmp(fileName.substr(fileName.size() - 3), "OGG")) 58 this->loadOGG(fileName); 50 this->size = 0; 51 this->loop = AL_FALSE; 52 59 53 60 54 } 61 55 62 SoundBuffer ::~SoundBuffer()56 SoundBufferData::~SoundBufferData() 63 57 { 64 58 // SoundEngine::getInstance()->removeBuffer(this); … … 68 62 69 63 /** 64 * @brief check the File-extension and loads either Wav of Ogg 65 * @param fileName the Name of the File to load. 66 * @returns true on success (file found, and loaded.) 67 */ 68 bool SoundBufferData::load(const std::string& fileName) 69 { 70 // generate a Buffer 71 alGenBuffers(1, &this->bufferID); 72 SoundEngine::checkError("Generate Buffer", __LINE__); 73 if (!nocaseCmp(fileName.substr(fileName.size() - 3), "WAV")) 74 { 75 return this->loadWAV(fileName); 76 } 77 else if (!nocaseCmp(fileName.substr(fileName.size() - 3), "OGG")) 78 return this->loadOGG(fileName); 79 else 80 return false; 81 } 82 83 /** 70 84 * @brief loads a Waveform from the local fileSystem into this Source. 71 85 * @param fileName the Name of the File to Load. 72 86 * @returns true on success. 73 87 */ 74 bool SoundBuffer ::loadWAV(const std::string& fileName)88 bool SoundBufferData::loadWAV(const std::string& fileName) 75 89 { 76 90 SDL_AudioSpec wavSpec; … … 93 107 } 94 108 #endif 95 alBufferData(this->bufferID, SoundBuffer ::sdlAudioSpecToAlFormat(&wavSpec),109 alBufferData(this->bufferID, SoundBufferData::sdlAudioSpecToAlFormat(&wavSpec), 96 110 wavBuffer, wavLength, wavSpec.freq); 97 111 … … 112 126 * @returns true on success (file exists and is fully loaded), false otherwise. 113 127 */ 114 bool SoundBuffer ::loadOGG(const std::string& fileName)128 bool SoundBufferData::loadOGG(const std::string& fileName) 115 129 { 116 130 void* ovdata; … … 156 170 * @returns the AL_FORMAT 157 171 */ 158 ALenum SoundBuffer ::sdlAudioSpecToAlFormat(const SDL_AudioSpec* audiospec)172 ALenum SoundBufferData::sdlAudioSpecToAlFormat(const SDL_AudioSpec* audiospec) 159 173 { 160 174 assert (audiospec != NULL); -
branches/new_class_id/src/lib/sound/sound_buffer_data.h
r9801 r9803 1 1 /*! 2 * @file sound_buffer .h3 * @brief Definition of the sound-buffer- class2 * @file sound_buffer_data.h 3 * @brief Definition of the sound-buffer-datacontainer-class 4 4 */ 5 5 6 #ifndef _SOUND_BUFFER_ H7 #define _SOUND_BUFFER_ H6 #ifndef _SOUND_BUFFER_DATA_H 7 #define _SOUND_BUFFER_DATA_H 8 8 9 9 #include "base_object.h" 10 10 #include "alincl.h" 11 #include "util/count_pointer.h" 11 12 12 13 // FORWARD DECLARATION … … 16 17 { 17 18 //! A class that represents a datastructure to play Sounds. 18 class SoundBuffer : public BaseObject19 class SoundBufferData : public BaseObject 19 20 { 20 ObjectListDeclaration(SoundBuffer );21 ObjectListDeclaration(SoundBufferData); 21 22 public: 22 SoundBuffer(const std::string& fileName); 23 virtual ~SoundBuffer(); 23 typedef CountPointer<SoundBufferData> Pointer; 24 24 25 public: 26 SoundBufferData(); 27 virtual ~SoundBufferData(); 28 29 bool load(const std::string& fileName); 25 30 bool loadWAV(const std::string& fileName); 26 31 bool loadOGG(const std::string& fileName); … … 39 44 }; 40 45 } 41 #endif /* _SOUND_BUFFER_ H */46 #endif /* _SOUND_BUFFER_DATA_H */
Note: See TracChangeset
for help on using the changeset viewer.