28 #include <boost/concept_check.hpp>
32 for(
auto& buffer : m_buffers)
44 m_soundFile = soundFile;
46 m_waitingFile =
false;
81 void StreamSoundSource::queueBuffers()
84 alGetSourcei(
m_sourceId, AL_BUFFERS_QUEUED, &queued);
85 for(
int i = 0; i < STREAM_FRAGMENTS - queued; ++i) {
86 if(!fillBufferAndQueue(m_buffers[i]->getBufferId()))
91 void StreamSoundSource::unqueueBuffers()
94 alGetSourcei(
m_sourceId, AL_BUFFERS_QUEUED, &queued);
95 for(
int i = 0; i < queued; ++i) {
97 alSourceUnqueueBuffers(
m_sourceId, 1, &buffer);
109 alGetSourcei(
m_sourceId, AL_BUFFERS_PROCESSED, &processed);
110 for(
int i = 0; i < processed; ++i) {
112 alSourceUnqueueBuffers(
m_sourceId, 1, &buffer);
115 if(!fillBufferAndQueue(buffer))
120 if(!m_looping && m_eof) {
122 }
else if(processed == 0) {
123 g_logger.traceError(
"audio buffer underrun");
125 }
else if(m_looping) {
131 bool StreamSoundSource::fillBufferAndQueue(
uint buffer)
140 int maxRead = STREAM_FRAGMENT_SIZE;
146 bytesRead += m_soundFile->
read(&bufferData[bytesRead], maxRead - bytesRead);
149 if(bytesRead < maxRead) {
151 m_soundFile->
reset();
157 }
while(bytesRead < maxRead);
161 if(
format == AL_FORMAT_STEREO16) {
162 assert(bytesRead % 2 == 0);
164 uint16_t *data = (uint16_t*)bufferData.data();
165 for(
int i=0;i<bytesRead/2;i++)
166 data[i] = data[2*i + (m_downMix ==
DownMixLeft ? 0 : 1)];
167 format = AL_FORMAT_MONO16;
171 alBufferData(buffer,
format, &bufferData[0], bytesRead, m_soundFile->
getRate());
172 ALenum err = alGetError();
173 if(err != AL_NO_ERROR)
178 if(err != AL_NO_ERROR)
183 return (bytesRead >= STREAM_FRAGMENT_SIZE && !m_eof);