Changeset 6931 for code/branches/sound5/src/orxonox/sound/SoundStreamer.cc
- Timestamp:
- May 20, 2010, 1:51:27 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/sound5/src/orxonox/sound/SoundStreamer.cc
r6769 r6931 28 28 29 29 #include <boost/thread.hpp> 30 #include < al.h>31 #include < alc.h>30 #include <AL/al.h> 31 #include <AL/alc.h> 32 32 #include <vorbis/vorbisfile.h> 33 33 #include "SoundManager.h" … … 41 41 long tellVorbis(void* datasource); 42 42 43 void orxonox::SoundStreamer::operator()(ALuint audioSource, DataStreamPtr dataStream )43 void orxonox::SoundStreamer::operator()(ALuint audioSource, DataStreamPtr dataStream, OggVorbis_File* vf, int current_section) 44 44 { 45 COUT(4) << "Sound: Creating thread for " << dataStream->getName() << std::endl; 46 47 alSourcei(audioSource, AL_BUFFER, 0); 48 49 // Open file with custom streaming 50 ov_callbacks vorbisCallbacks; 51 vorbisCallbacks.read_func = &readVorbis; 52 vorbisCallbacks.seek_func = &seekVorbis; 53 vorbisCallbacks.tell_func = &tellVorbis; 54 vorbisCallbacks.close_func = NULL; 55 56 OggVorbis_File vf; 57 int ret = ov_open_callbacks(dataStream.get(), &vf, NULL, 0, vorbisCallbacks); 58 if (ret < 0) 59 { 60 COUT(2) << "Sound: libvorbisfile: File does not seem to be an Ogg Vorbis bitstream" << std::endl; 61 ov_clear(&vf); 62 return; 63 } 45 char inbuffer[4096]; 64 46 vorbis_info* vorbisInfo; 65 vorbisInfo = ov_info( &vf, -1);47 vorbisInfo = ov_info(vf, -1); 66 48 ALenum format; 67 49 if (vorbisInfo->channels == 1) … … 69 51 else 70 52 format = AL_FORMAT_STEREO16; 71 72 char inbuffer[4096];73 ALuint initbuffers[5];74 alGenBuffers(5, initbuffers);75 if (ALint error = alGetError()) {76 COUT(2) << "Sound: Streamer: Could not generate buffer:" << getALErrorString(error) << std::endl;77 return;78 }79 int current_section;80 81 for(int i = 0; i < 5; i++)82 {83 long ret = ov_read(&vf, inbuffer, sizeof(inbuffer), 0, 2, 1, ¤t_section);84 if (ret == 0)85 {86 break;87 }88 else if (ret < 0)89 {90 COUT(2) << "Sound: libvorbisfile: error reading the file" << std::endl;91 ov_clear(&vf);92 return;93 }94 95 alBufferData(initbuffers[i], format, &inbuffer, ret, vorbisInfo->rate);96 if(ALint error = alGetError()) {97 COUT(2) << "Sound: Could not fill buffer: " << getALErrorString(error) << std::endl;98 break;99 }100 alSourceQueueBuffers(audioSource, 1, &initbuffers[i]);101 if (ALint error = alGetError()) {102 COUT(2) << "Sound: Warning: Couldn't queue buffers: " << getALErrorString(error) << std::endl;103 }104 }105 106 //alSourcei(audioSource, AL_LOOPING, AL_TRUE);107 108 alSourcePlay(audioSource);109 if(ALint error = alGetError())110 COUT(2) << "Sound: Could not start ambient sound" << getALErrorString(error) << std::endl;111 53 112 54 while(true) // Stream forever, control through thread control … … 118 60 COUT(4) << "Sound: " << dataStream->getName() << " is playing." << std::endl; 119 61 else 62 { 120 63 COUT(4) << "Sound: " << dataStream->getName() << " is not playing." << std::endl; 64 } 121 65 122 66 if(alcGetCurrentContext() == NULL) … … 130 74 if (ALint error = alGetError()) 131 75 COUT(2) << "Sound: Warning: Couldn't get number of processed buffers: " << getALErrorString(error) << std::endl; 76 132 77 COUT(4) << "Sound: processed buffers: " << processed << std::endl; 133 78 … … 138 83 if (ALint error = alGetError()) 139 84 COUT(2) << "Sound: Warning: Couldn't unqueue buffers: " << getALErrorString(error) << std::endl; 85 86 int queued; 87 alGetSourcei(audioSource, AL_BUFFERS_QUEUED, &queued); 88 if (ALint error = alGetError()) 89 COUT(2) << "Sound: Warning: Couldn't get number of queued buffers: " << getALErrorString(error) << std::endl; 90 COUT(4) << "Sound: queued buffers: " << queued << std::endl; 140 91 141 92 for(int i = 0; i < processed; i++) 142 93 { 143 long ret = ov_read( &vf, inbuffer, sizeof(inbuffer), 0, 2, 1, ¤t_section);94 long ret = ov_read(vf, inbuffer, sizeof(inbuffer), 0, 2, 1, ¤t_section); 144 95 if (ret == 0) 145 96 { 97 COUT(4) << "Sound: End of file " << dataStream->getName() << ", terminating thread" << std::endl; 146 98 return; 147 99 } … … 149 101 { 150 102 COUT(2) << "Sound: libvorbisfile: error reading the file " << dataStream->getName() << std::endl; 151 ov_clear( &vf);103 ov_clear(vf); 152 104 return; 153 105 } … … 164 116 } 165 117 } 118 else 119 { 120 msleep(10); // perhaps another value here is better 121 } 122 166 123 try { 167 124 boost::this_thread::interruption_point(); … … 180 137 return; 181 138 } 182 msleep(50); // perhaps another value here is better183 139 } 184 140 }
Note: See TracChangeset
for help on using the changeset viewer.