- Timestamp:
- Jul 1, 2006, 10:45:47 AM (18 years ago)
- Location:
- trunk/src/lib/sound
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/sound/sound_buffer.cc
r8619 r8969 23 23 #include <cassert> 24 24 #include "debug.h" 25 #include "sys/stat.h" 26 #include "helper_functions.h" 25 27 26 28 #ifdef HAVE_SDL_SDL_H … … 48 50 alGenBuffers(1, &this->bufferID); 49 51 SoundEngine::checkError("Generate Buffer", __LINE__); 50 this->loadWAV(fileName); 52 if (!nocaseCmp(fileName.substr(fileName.size() - 3), "WAV")) 53 { 54 this->loadWAV(fileName); 55 } 56 else if (!nocaseCmp(fileName.substr(fileName.size() - 3), "OGG")) 57 this->loadOGG(fileName); 58 51 59 } 52 60 … … 76 84 } 77 85 #if SDL_BYTEORDER == SDL_BIG_ENDIAN 78 if ( !( wavSpec.format == AUDIO_U8 || wavSpec.format == AUDIO_S8 ) ) { 79 int cnt = wavLength/2; 80 Uint16* wavBufferAsShorts = ( Uint16* )wavBuffer; 81 for ( int i = 0; i < cnt; ++i, ++wavBufferAsShorts ) 82 *wavBufferAsShorts = SDL_Swap16( *wavBufferAsShorts ); 83 } 86 if ( !( wavSpec.format == AUDIO_U8 || wavSpec.format == AUDIO_S8 ) ) 87 { 88 int cnt = wavLength/2; 89 Uint16* wavBufferAsShorts = ( Uint16* )wavBuffer; 90 for ( int i = 0; i < cnt; ++i, ++wavBufferAsShorts ) 91 *wavBufferAsShorts = SDL_Swap16( *wavBufferAsShorts ); 92 } 84 93 #endif 85 94 alBufferData(this->bufferID, SoundBuffer::sdlAudioSpecToAlFormat(&wavSpec), 86 95 wavBuffer, wavLength, wavSpec.freq); 87 96 88 97 SDL_FreeWAV(wavBuffer); … … 92 101 return false; 93 102 } 103 104 105 #ifndef AL_FORMAT_VORBIS_EXT 106 #define AL_FORMAT_VORBIS_EXT 0x100030 107 #endif 108 bool SoundBuffer::loadOGG(const std::string& fileName) 109 { 110 void* ovdata; 111 FILE* fh; 112 113 fh = fopen( fileName.c_str() , "rb") ; 114 if( fh != NULL ) 115 { 116 struct stat sbuf ; 117 118 if(stat( fileName.c_str(), &sbuf ) != -1) 119 { 120 ovdata = malloc(sbuf.st_size); 121 if(ovdata != NULL) 122 { 123 fread( ovdata, 1, sbuf.st_size, fh); 124 125 alBufferData( this->bufferID, 126 AL_FORMAT_VORBIS_EXT, 127 ovdata, 128 sbuf.st_size, 129 1) ; 130 131 free(ovdata); 132 } 133 fclose(fh); 134 } 135 else 136 return false; 137 } 138 else 139 return false; 140 141 return true ; 142 143 } 144 94 145 95 146 /** -
trunk/src/lib/sound/sound_buffer.h
r7460 r8969 23 23 24 24 bool loadWAV(const std::string& fileName); 25 bool loadOGG(const std::string& fileName); 25 26 26 27 /** @returns the ID of the buffer used in this SoundBuffer */ -
trunk/src/lib/sound/sound_source.cc
r8793 r8969 1 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 4 4 Copyright (C) 2004 orx 5 5 6 6 This program is free software; you can redistribute it and/or modify 7 7 it under the terms of the GNU General Public License as published by 8 8 the Free Software Foundation; either version 2, or (at your option) 9 9 any later version. 10 10 11 11 ### File Specific: 12 12 main-programmer: Benjamin Grauer … … 85 85 else 86 86 this->stop(); 87 88 return *this; 87 89 } 88 90 … … 166 168 * @brief Plays back buffer on this Source with gain 167 169 * @param buffer the buffer to play back on this Source 168 * @param gain the gain of the sound buffer 170 * @param gain the gain of the sound buffer 169 171 */ 170 172 void SoundSource::play(const SoundBuffer* buffer, float gain)
Note: See TracChangeset
for help on using the changeset viewer.