Changeset 513 for code/branches/FICN/src/audio
- Timestamp:
- Dec 13, 2007, 5:58:14 PM (17 years ago)
- Location:
- code/branches/FICN/src/audio
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/FICN/src/audio/AudioBuffer.cc
r389 r513 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * ... 23 * Co-authors: 24 * ... 25 * 26 */ 27 1 28 #include "AudioBuffer.h" 2 29 … … 18 45 if(alGetError() != AL_NO_ERROR) 19 46 loaded=AL_FALSE; 20 47 21 48 loaded=AL_TRUE; 22 49 } 23 50 24 51 AudioBuffer::~AudioBuffer() 25 52 { 26 53 27 54 } 28 55 } -
code/branches/FICN/src/audio/AudioManager.cc
r458 r513 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * ... 23 * Co-authors: 24 * ... 25 * 26 */ 27 1 28 #include "AudioManager.h" 2 29 -
code/branches/FICN/src/audio/AudioSource.cc
r389 r513 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * ... 23 * Co-authors: 24 * ... 25 * 26 */ 27 1 28 #include "AudioSource.h" 2 29 … … 7 34 8 35 } 9 36 10 37 AudioSource::~AudioSource() 11 38 { 12 39 13 40 } 14 41 } -
code/branches/FICN/src/audio/AudioStream.cc
r430 r513 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * ... 23 * Co-authors: 24 * ... 25 * 26 */ 27 1 28 2 29 #include "AudioStream.h" … … 8 35 this->path = path; 9 36 loaded = false; 10 } 37 } 11 38 12 39 void AudioStream::open() … … 14 41 int result; 15 42 16 43 17 44 if(!(oggFile = fopen(path.c_str(), "rb"))) 18 45 { … … 23 50 if((result = ov_open(oggFile, &oggStream, NULL, 0)) < 0) 24 51 { 25 fclose(oggFile); 52 fclose(oggFile); 26 53 orxonox::Error("Could not open Ogg stream. " + errorString(result)); 27 54 return; … … 29 56 30 57 loaded = true; 31 58 32 59 vorbisInfo = ov_info(&oggStream, -1); 33 60 vorbisComment = ov_comment(&oggStream, -1); 34 61 35 62 if(vorbisInfo->channels == 1) 36 63 format = AL_FORMAT_MONO16; 37 64 else 38 65 format = AL_FORMAT_STEREO16; 39 40 66 67 41 68 alGenBuffers(2, buffers); 42 69 check(); 43 70 alGenSources(1, &source); 44 71 check(); 45 72 46 73 alSource3f(source, AL_POSITION, 0.0, 0.0, 0.0); 47 74 alSource3f(source, AL_VELOCITY, 0.0, 0.0, 0.0); … … 50 77 alSourcei (source, AL_SOURCE_RELATIVE, AL_FALSE ); 51 78 } 52 53 54 55 79 80 81 82 56 83 void AudioStream::release() 57 84 { … … 63 90 alDeleteBuffers(1, buffers); 64 91 check(); 65 92 66 93 ov_clear(&oggStream); 67 94 loaded = false; 68 69 } 70 71 72 73 95 96 } 97 98 99 100 74 101 void AudioStream::display() 75 102 { … … 86 113 << "\n" 87 114 << "vendor " << vorbisComment->vendor << "\n"; 88 115 89 116 for(int i = 0; i < vorbisComment->comments; i++) 90 117 std::cout << " " << vorbisComment->user_comments[i] << "\n"; 91 92 std::cout << std::endl; 118 119 std::cout << std::endl; 93 120 } 94 121 } 95 96 97 98 122 123 124 125 99 126 bool AudioStream::playback() 100 127 { … … 106 133 if(playing()) 107 134 return true; 108 135 109 136 if(!stream(buffers[0])) 110 137 return false; 111 138 112 139 if(!stream(buffers[1])) 113 140 return false; 114 141 115 142 alSourceQueueBuffers(source, 2, buffers); 116 143 alSourcePlay(source); 117 144 118 145 return true; 119 146 } 120 121 122 123 147 148 149 150 124 151 bool AudioStream::playing() 125 152 { … … 133 160 return (state == AL_PLAYING); 134 161 } 135 136 137 138 162 163 164 165 139 166 bool AudioStream::update() 140 167 { 141 168 int processed; 142 169 bool active = true; 143 170 144 171 alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed); 145 172 146 173 while(processed--) 147 174 { 148 175 ALuint buffer; 149 176 150 177 alSourceUnqueueBuffers(source, 1, &buffer); 151 178 check(); 152 179 153 180 active = stream(buffer); 154 181 155 182 alSourceQueueBuffers(source, 1, &buffer); 156 183 check(); 157 184 } 158 185 159 186 if (active==false) 160 187 { … … 163 190 return active; 164 191 } 165 166 167 168 192 193 194 195 169 196 bool AudioStream::stream(ALuint buffer) 170 197 { … … 173 200 int section; 174 201 int result; 175 202 176 203 while(size < BUFFER_SIZE) 177 204 { 178 205 result = ov_read(&oggStream, pcm + size, BUFFER_SIZE - size, 0, 2, 1, §ion); 179 206 180 207 if(result > 0) 181 208 size += result; … … 186 213 break; 187 214 } 188 215 189 216 if(size == 0) 190 217 return false; 191 218 192 219 alBufferData(buffer, format, pcm, size, vorbisInfo->rate); 193 220 check(); 194 221 195 222 return true; 196 223 } 197 198 224 225 199 226 200 227 void AudioStream::empty() 201 228 { 202 229 int queued; 203 230 204 231 alGetSourcei(source, AL_BUFFERS_QUEUED, &queued); 205 232 206 233 while(queued--) 207 234 { 208 235 ALuint buffer; 209 236 210 237 alSourceUnqueueBuffers(source, 1, &buffer); 211 238 check(); 212 239 } 213 240 } 214 215 216 217 241 242 243 244 218 245 void AudioStream::check() 219 246 { 220 247 int error = alGetError(); 221 248 222 249 if(error != AL_NO_ERROR) 223 250 orxonox::Error("OpenAL error was raised."); 224 251 } 225 226 227 252 253 254 228 255 std::string AudioStream::errorString(int code) 229 256 { -
code/branches/FICN/src/audio/_AudioObject.cc
r389 r513 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * ... 23 * Co-authors: 24 * ... 25 * 26 */ 27 28 1 29 #include <iostream> 2 30 #include <string> … … 33 61 34 62 // Initialize OpenAL and clear the error bit. 35 63 36 64 alutInit(NULL, 0); 37 65 alGetError(); 38 66 39 67 // Load the wav data. 40 68 41 69 if(LoadALData() == AL_FALSE) 42 70 { 43 71 printf("Error loading sound data."); 44 72 45 73 } 46 74 … … 48 76 std::cout << "Play sone ambient background sound"; 49 77 } 50 78 51 79 AudioObject::~AudioObject() 52 { 80 { 53 81 KillALData(); 54 82 } 55 83 56 84 ALboolean AudioObject::LoadALData() 57 85 { … … 61 89 ALsizei freq; 62 90 ALboolean loop; 63 64 91 92 65 93 alGenBuffers(1, &Buffer); 66 94 67 95 if(alGetError() != AL_NO_ERROR) 68 96 return AL_FALSE; 69 97 70 98 alutLoadWAVFile((ALbyte*)audioFile_.c_str(), &format, &data, &size, &freq, &loop); 71 99 alBufferData(Buffer, format, data, size, freq); 72 100 alutUnloadWAV(format, data, size, freq); 73 101 74 102 alGenSources(1, &Source); 75 103 76 104 if(alGetError() != AL_NO_ERROR) 77 105 return AL_FALSE; 78 106 79 107 alSourcei (Source, AL_BUFFER, Buffer ); 80 108 alSourcef (Source, AL_PITCH, 1.0 ); … … 83 111 alSourcefv(Source, AL_VELOCITY, SourceVel); 84 112 alSourcei (Source, AL_LOOPING, loop ); 85 113 86 114 if(alGetError() == AL_NO_ERROR) 87 115 return AL_TRUE; 88 89 116 117 90 118 return AL_FALSE; 91 } 119 } 92 120 93 121 void AudioObject::SetListenerValues() … … 97 125 alListenerfv(AL_ORIENTATION, ListenerOri); 98 126 } 99 127 100 128 void AudioObject::KillALData() 101 129 { … … 108 136 { 109 137 alSourcePlay(Source); 110 138 111 139 } 112 140 }
Note: See TracChangeset
for help on using the changeset viewer.