Changeset 423 for code/branches/FICN/src/audio
- Timestamp:
- Dec 5, 2007, 9:20:44 PM (17 years ago)
- Location:
- code/branches/FICN/src/audio
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/FICN/src/audio/AudioManager.cc
r420 r423 7 7 alutInit(NULL, 0); 8 8 9 bgSound.open("ambient3"); 9 bgSound.open("ambient1"); 10 11 12 10 13 bgSound.display(); 11 12 orxonox::Error("Sound loaded!");13 14 14 15 if(!bgSound.playback()) 15 16 { 16 std::cout << "Ogg refused to play.";17 orxonox::Error("Ogg refused to play."); 17 18 } 18 19 } … … 26 27 void AudioManager::update() 27 28 { 28 bgSound.update(); 29 if(!bgSound.playing()) 30 { 31 if(!bgSound.playback()) 32 std::cout << "Ogg abruptly stopped."; 33 else 34 std::cout << "Ogg stream was interrupted.\n"; 35 } 29 30 if (bgSound.isLoaded()) 31 { 32 bgSound.update(); 33 if(!bgSound.playing()) 34 { 35 if(!bgSound.playback()) 36 orxonox::Error("Ogg abruptly stopped."); 37 else 38 orxonox::Error("Ogg stream was interrupted."); 39 } 40 } 36 41 } 37 42 -
code/branches/FICN/src/audio/AudioStream.cc
r419 r423 7 7 { 8 8 int result; 9 loaded = false; 9 10 10 11 path = "audio/ambient/" + path + ".ogg"; 11 12 12 13 if(!(oggFile = fopen(path.c_str(), "rb"))) 13 throw std::string("Could not open Ogg file."); 14 14 { 15 orxonox::Error("Could not open Ogg file "+path); 16 return; 17 } 18 15 19 if((result = ov_open(oggFile, &oggStream, NULL, 0)) < 0) 16 20 { 17 fclose(oggFile); 18 19 throw std::string("Could not open Ogg stream. ") + errorString(result); 20 } 21 fclose(oggFile); 22 orxonox::Error("Could not open Ogg stream. " + errorString(result)); 23 return; 24 } 25 26 loaded = true; 21 27 22 28 vorbisInfo = ov_info(&oggStream, -1); … … 38 44 alSource3f(source, AL_DIRECTION, 0.0, 0.0, 0.0); 39 45 alSourcef (source, AL_ROLLOFF_FACTOR, 0.0 ); 40 alSourcei (source, AL_SOURCE_RELATIVE, AL_ TRUE );46 alSourcei (source, AL_SOURCE_RELATIVE, AL_FALSE ); 41 47 } 42 48 … … 46 52 void AudioStream::release() 47 53 { 54 if (loaded) 55 { 48 56 alSourceStop(source); 49 57 empty(); … … 54 62 55 63 ov_clear(&oggStream); 64 loaded = false; 65 } 56 66 } 57 67 … … 61 71 void AudioStream::display() 62 72 { 73 if (loaded) 74 { 63 75 std::cout 64 76 << "version " << vorbisInfo->version << "\n" … … 75 87 std::cout << " " << vorbisComment->user_comments[i] << "\n"; 76 88 77 std::cout << std::endl; 89 std::cout << std::endl; 90 } 78 91 } 79 92 … … 83 96 bool AudioStream::playback() 84 97 { 98 if (!loaded) 99 { 100 return false; 101 } 102 85 103 if(playing()) 86 104 return true; … … 103 121 bool AudioStream::playing() 104 122 { 123 if (!loaded) 124 { 125 return false; 126 } 127 105 128 ALenum state; 106 107 129 alGetSourcei(source, AL_SOURCE_STATE, &state); 108 109 130 return (state == AL_PLAYING); 110 131 } … … 154 175 else 155 176 if(result < 0) 156 throw errorString(result);177 orxonox::Error(errorString(result)); 157 178 else 158 179 break; … … 169 190 170 191 171 172 192 173 193 void AudioStream::empty() 174 194 { … … 194 214 195 215 if(error != AL_NO_ERROR) 196 throw std::string("OpenAL error was raised.");216 orxonox::Error("OpenAL error was raised."); 197 217 } 198 218 -
code/branches/FICN/src/audio/AudioStream.h
r411 r423 19 19 bool playing(); 20 20 bool update(); 21 21 inline bool isLoaded() { return loaded; } 22 22 23 protected: 23 24 … … 33 34 vorbis_info* vorbisInfo; 34 35 vorbis_comment* vorbisComment; 35 36 bool loaded; 37 36 38 ALuint buffers[2]; 37 39 ALuint source;
Note: See TracChangeset
for help on using the changeset viewer.