|
@@ -316,7 +316,7 @@ restart_stalled_audio() {
|
|
|
// Description: Pushes a buffer into the source queue.
|
|
// Description: Pushes a buffer into the source queue.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
void OpenALAudioSound::
|
|
void OpenALAudioSound::
|
|
|
-queue_buffer(ALuint buffer, int loop_index, double time_offset) {
|
|
|
|
|
|
|
+queue_buffer(ALuint buffer, int samples, int loop_index, double time_offset) {
|
|
|
// Now push the buffer into the stream queue.
|
|
// Now push the buffer into the stream queue.
|
|
|
alGetError();
|
|
alGetError();
|
|
|
alSourceQueueBuffers(_source,1,&buffer);
|
|
alSourceQueueBuffers(_source,1,&buffer);
|
|
@@ -328,10 +328,10 @@ queue_buffer(ALuint buffer, int loop_index, double time_offset) {
|
|
|
}
|
|
}
|
|
|
QueuedBuffer buf;
|
|
QueuedBuffer buf;
|
|
|
buf._buffer = buffer;
|
|
buf._buffer = buffer;
|
|
|
|
|
+ buf._samples = samples;
|
|
|
buf._loop_index = loop_index;
|
|
buf._loop_index = loop_index;
|
|
|
buf._time_offset = time_offset;
|
|
buf._time_offset = time_offset;
|
|
|
_stream_queued.push_back(buf);
|
|
_stream_queued.push_back(buf);
|
|
|
- // audio_debug("Buffer queued " << loop_index << " " << time_offset);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
@@ -394,9 +394,18 @@ read_stream_data(int bytelen, unsigned char *buffer) {
|
|
|
cursor->seek(0.0);
|
|
cursor->seek(0.0);
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
+ if (_sd->_stream->ready() == 0) {
|
|
|
|
|
+ if (_sd->_stream->aborted()) {
|
|
|
|
|
+ _loops_completed = _playing_loops;
|
|
|
|
|
+ }
|
|
|
|
|
+ return fill;
|
|
|
|
|
+ }
|
|
|
if (samples > space) {
|
|
if (samples > space) {
|
|
|
samples = space;
|
|
samples = space;
|
|
|
}
|
|
}
|
|
|
|
|
+ if (samples > _sd->_stream->ready()) {
|
|
|
|
|
+ samples = _sd->_stream->ready();
|
|
|
|
|
+ }
|
|
|
cursor->read_samples(samples, (PN_int16 *)buffer);
|
|
cursor->read_samples(samples, (PN_int16 *)buffer);
|
|
|
size_t hval = AddHash::add_hash(0, (PN_uint8*)buffer, samples*channels*2);
|
|
size_t hval = AddHash::add_hash(0, (PN_uint8*)buffer, samples*channels*2);
|
|
|
audio_debug("Streaming " << cursor->get_source()->get_filename().get_basename() << " at " << t << " hash " << hval);
|
|
audio_debug("Streaming " << cursor->get_source()->get_filename().get_basename() << " at " << t << " hash " << hval);
|
|
@@ -490,23 +499,21 @@ push_fresh_buffers() {
|
|
|
if (_sd->_sample) {
|
|
if (_sd->_sample) {
|
|
|
while ((_loops_completed < _playing_loops) &&
|
|
while ((_loops_completed < _playing_loops) &&
|
|
|
(_stream_queued.size() < 100)) {
|
|
(_stream_queued.size() < 100)) {
|
|
|
- queue_buffer(_sd->_sample, _loops_completed, 0.0);
|
|
|
|
|
|
|
+ queue_buffer(_sd->_sample, 0,_loops_completed, 0.0);
|
|
|
_loops_completed += 1;
|
|
_loops_completed += 1;
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
MovieAudioCursor *cursor = _sd->_stream;
|
|
MovieAudioCursor *cursor = _sd->_stream;
|
|
|
int channels = cursor->audio_channels();
|
|
int channels = cursor->audio_channels();
|
|
|
int rate = cursor->audio_rate();
|
|
int rate = cursor->audio_rate();
|
|
|
- double space = 65536 / (channels * 2);
|
|
|
|
|
|
|
|
|
|
- // Calculate how many buffers to keep in the queue.
|
|
|
|
|
- int fill_to = (int)((audio_buffering_seconds * rate) / space) + 1;
|
|
|
|
|
- if (fill_to < 3) {
|
|
|
|
|
- fill_to = 3;
|
|
|
|
|
|
|
+ int fill = 0;
|
|
|
|
|
+ for (int i=0; i<_stream_queued.size(); i++) {
|
|
|
|
|
+ fill += _stream_queued[i]._samples;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
while ((_loops_completed < _playing_loops) &&
|
|
while ((_loops_completed < _playing_loops) &&
|
|
|
- (((int)(_stream_queued.size())) < fill_to)) {
|
|
|
|
|
|
|
+ (fill < (int)(audio_buffering_seconds * rate * channels))) {
|
|
|
int loop_index = _loops_completed;
|
|
int loop_index = _loops_completed;
|
|
|
double time_offset = cursor->tell();
|
|
double time_offset = cursor->tell();
|
|
|
int samples = read_stream_data(65536, data);
|
|
int samples = read_stream_data(65536, data);
|
|
@@ -515,8 +522,9 @@ push_fresh_buffers() {
|
|
|
}
|
|
}
|
|
|
ALuint buffer = make_buffer(samples, channels, rate, data);
|
|
ALuint buffer = make_buffer(samples, channels, rate, data);
|
|
|
if (_manager == 0) return;
|
|
if (_manager == 0) return;
|
|
|
- queue_buffer(buffer, loop_index, time_offset);
|
|
|
|
|
|
|
+ queue_buffer(buffer, samples, loop_index, time_offset);
|
|
|
if (_manager == 0) return;
|
|
if (_manager == 0) return;
|
|
|
|
|
+ fill += samples;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -866,17 +874,14 @@ get_name() const {
|
|
|
// Description: Get status of the sound.
|
|
// Description: Get status of the sound.
|
|
|
//
|
|
//
|
|
|
// This returns the status as of the
|
|
// This returns the status as of the
|
|
|
-// last AudioManager::update.
|
|
|
|
|
|
|
+// last push_fresh_buffers
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
AudioSound::SoundStatus OpenALAudioSound::
|
|
AudioSound::SoundStatus OpenALAudioSound::
|
|
|
status() const {
|
|
status() const {
|
|
|
if (_source==0) {
|
|
if (_source==0) {
|
|
|
return AudioSound::READY;
|
|
return AudioSound::READY;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- _manager->make_current();
|
|
|
|
|
-
|
|
|
|
|
- if (_stream_queued.size() == 0) {
|
|
|
|
|
|
|
+ if (_loops_completed >= _playing_loops) {
|
|
|
return AudioSound::READY;
|
|
return AudioSound::READY;
|
|
|
} else {
|
|
} else {
|
|
|
return AudioSound::PLAYING;
|
|
return AudioSound::PLAYING;
|