- Timestamp:
- Jan 29, 2006, 2:31:48 PM (19 years ago)
- Location:
- trunk/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/sound/ogg_player.cc
r6827 r6828 50 50 void OggPlayer::open(const char* fileName) 51 51 { 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 52 int result; 53 54 if(!(oggFile = fopen(fileName, "rb"))) 55 PRINTF(2)("Could not open Ogg file."); 56 57 if((result = ov_open(oggFile, &oggStream, NULL, 0)) < 0) 58 { 59 fclose(oggFile); 60 61 PRINTF(2)("Could not open Ogg stream. %s", errorString(result)); 62 } 63 64 vorbisInfo = ov_info(&oggStream, -1); 65 vorbisComment = ov_comment(&oggStream, -1); 66 67 if(vorbisInfo->channels == 1) 68 format = AL_FORMAT_MONO16; 69 else 70 format = AL_FORMAT_STEREO16; 71 72 73 alGenBuffers(2, buffers); 74 check(); 75 SoundEngine::getInstance()->popALSource(this->source); 76 check(); 77 78 alSource3f(source, AL_POSITION, 0.0, 0.0, 0.0); 79 alSource3f(source, AL_VELOCITY, 0.0, 0.0, 0.0); 80 alSource3f(source, AL_DIRECTION, 0.0, 0.0, 0.0); 81 alSourcef (source, AL_ROLLOFF_FACTOR, 0.0 ); 82 alSourcei (source, AL_SOURCE_RELATIVE, AL_TRUE ); 83 alSourcef (source, AL_GAIN, SoundEngine::getInstance()->getMusicVolume()); 84 84 } 85 85 … … 89 89 void OggPlayer::release() 90 90 { 91 alSourceStop(source); 92 empty(); 93 SoundEngine::getInstance()->pushALSource(source); 94 check(); 95 alDeleteBuffers(1, buffers); 96 check(); 97 98 ov_clear(&oggStream); 99 } 100 101 /** 102 * displays some info about the ogg-file 103 */ 104 void OggPlayer::display() 105 { 106 cout 107 << "version " << vorbisInfo->version << "\n" 108 << "channels " << vorbisInfo->channels << "\n" 109 << "rate (hz) " << vorbisInfo->rate << "\n" 110 << "bitrate upper " << vorbisInfo->bitrate_upper << "\n" 111 << "bitrate nominal " << vorbisInfo->bitrate_nominal << "\n" 112 << "bitrate lower " << vorbisInfo->bitrate_lower << "\n" 113 << "bitrate window " << vorbisInfo->bitrate_window << "\n" 114 << "\n" 115 << "vendor " << vorbisComment->vendor << "\n"; 116 117 for(int i = 0; i < vorbisComment->comments; i++) 118 cout << " " << vorbisComment->user_comments[i] << "\n"; 119 120 cout << endl; 91 alSourceStop(source); 92 empty(); 93 SoundEngine::getInstance()->pushALSource(source); 94 check(); 95 alDeleteBuffers(1, buffers); 96 check(); 97 98 ov_clear(&oggStream); 121 99 } 122 100 … … 128 106 bool OggPlayer::playback() 129 107 { 130 if(playing()) 131 return true; 132 133 if(!stream(buffers[0])) 134 return false; 135 136 if(!stream(buffers[1])) 137 return false; 138 139 alSourceQueueBuffers(source, 2, buffers); 140 alSourcePlay(source); 141 108 if(playing()) 142 109 return true; 110 111 if(!stream(buffers[0])) 112 return false; 113 114 if(!stream(buffers[1])) 115 return false; 116 117 alSourceQueueBuffers(source, 2, buffers); 118 alSourcePlay(source); 119 120 return true; 143 121 } 144 122 … … 149 127 bool OggPlayer::playing() 150 128 { 151 152 153 alGetSourcei(source, AL_SOURCE_STATE, &state);154 155 129 ALenum state; 130 131 alGetSourcei(this->source, AL_SOURCE_STATE, &state); 132 133 return (state == AL_PLAYING); 156 134 } 157 135 … … 162 140 bool OggPlayer::update() 163 141 { 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 142 int processed; 143 bool active = true; 144 145 alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed); 146 147 while(processed--) 148 { 149 ALuint buffer; 150 151 alSourceUnqueueBuffers(source, 1, &buffer); 152 check(); 153 154 active = stream(buffer); 155 156 alSourceQueueBuffers(source, 1, &buffer); 157 check(); 158 } 159 160 return active; 183 161 } 184 162 … … 190 168 bool OggPlayer::stream(ALuint buffer) 191 169 { 192 char pcm[BUFFER_SIZE]; 193 int size = 0; 194 int section; 195 int result; 196 197 while(size < BUFFER_SIZE) 198 { 199 result = ov_read(&oggStream, pcm + size, BUFFER_SIZE - size, 0, 2, 1, §ion); 200 201 if(result > 0) 202 size += result; 203 else 204 if(result < 0) 205 throw errorString(result); 206 else 207 break; 208 } 209 210 if(size == 0) 211 return false; 212 213 alBufferData(buffer, format, pcm, size, vorbisInfo->rate); 170 char pcm[BUFFER_SIZE]; 171 int size = 0; 172 int section; 173 int result; 174 175 while(size < BUFFER_SIZE) 176 { 177 result = ov_read(&oggStream, pcm + size, BUFFER_SIZE - size, 0, 2, 1, §ion); 178 179 if(result > 0) 180 size += result; 181 else 182 if(result < 0) 183 throw errorString(result); 184 else 185 break; 186 } 187 188 if(size == 0) 189 return false; 190 191 alBufferData(buffer, format, pcm, size, vorbisInfo->rate); 192 check(); 193 194 return true; 195 } 196 197 198 /** 199 * empties the buffers 200 */ 201 void OggPlayer::empty() 202 { 203 int queued; 204 205 alGetSourcei(source, AL_BUFFERS_QUEUED, &queued); 206 207 while(queued--) 208 { 209 ALuint buffer; 210 211 alSourceUnqueueBuffers(source, 1, &buffer); 214 212 check(); 215 216 return true; 217 } 218 219 220 /** 221 * empties the buffers 222 */ 223 void OggPlayer::empty() 224 { 225 int queued; 226 227 alGetSourcei(source, AL_BUFFERS_QUEUED, &queued); 228 229 while(queued--) 230 { 231 ALuint buffer; 232 233 alSourceUnqueueBuffers(source, 1, &buffer); 234 check(); 235 } 213 } 236 214 } 237 215 … … 241 219 void OggPlayer::check() 242 220 { 243 int error = alGetError(); 244 245 if(error != AL_NO_ERROR) 246 PRINTF(2)("OpenAL error was raised."); 247 } 221 int error = alGetError(); 222 223 if(error != AL_NO_ERROR) 224 PRINTF(2)("OpenAL error was raised."); 225 } 226 227 228 229 /** 230 * displays some info about the ogg-file 231 */ 232 void OggPlayer::debug() 233 { 234 cout 235 << "version " << vorbisInfo->version << "\n" 236 << "channels " << vorbisInfo->channels << "\n" 237 << "rate (hz) " << vorbisInfo->rate << "\n" 238 << "bitrate upper " << vorbisInfo->bitrate_upper << "\n" 239 << "bitrate nominal " << vorbisInfo->bitrate_nominal << "\n" 240 << "bitrate lower " << vorbisInfo->bitrate_lower << "\n" 241 << "bitrate window " << vorbisInfo->bitrate_window << "\n" 242 << "\n" 243 << "vendor " << vorbisComment->vendor << "\n"; 244 245 for(int i = 0; i < vorbisComment->comments; i++) 246 cout << " " << vorbisComment->user_comments[i] << "\n"; 247 248 cout << endl; 249 } 250 248 251 249 252 /** … … 254 257 const char* OggPlayer::errorString(int code) 255 258 { 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 } 259 switch(code) 260 { 261 case OV_EREAD: 262 return ("Read from media."); 263 case OV_ENOTVORBIS: 264 return ("Not Vorbis data."); 265 case OV_EVERSION: 266 return ("Vorbis version mismatch."); 267 case OV_EBADHEADER: 268 return ("Invalid Vorbis header."); 269 case OV_EFAULT: 270 return ("Internal logic fault (bug or heap/stack corruption."); 271 default: 272 return ("Unknown Ogg error."); 273 } 274 } -
trunk/src/lib/sound/ogg_player.h
r5282 r6828 31 31 void open(const char* fileName); 32 32 void release(); 33 void d isplay();33 void debug(); 34 34 bool playback(); 35 35 bool playing(); -
trunk/src/orxonox.cc
r6695 r6828 249 249 // SDL_InitSubSystem(SDL_INIT_AUDIO); 250 250 SoundEngine::getInstance()->initAudio(); 251 SoundEngine::getInstance()->allocateSources( 1);251 SoundEngine::getInstance()->allocateSources(32); 252 252 253 253 SoundEngine::getInstance()->loadSettings(this->iniParser); -
trunk/src/story_entities/game_world_data.cc
r6827 r6828 318 318 PRINTF(3)("Setting Sound Track to %s\n", name); 319 319 this->music = (OggPlayer*)ResourceManager::getInstance()->load(name, OGG, RP_LEVEL); 320 } 321 322 320 if (this->music) 321 this->music->debug(); 322 } 323 324
Note: See TracChangeset
for help on using the changeset viewer.