|
@@ -373,7 +373,6 @@ read_stream_data(int bytelen, unsigned char *buffer) {
|
|
|
nassertr(has_sound_data(), 0);
|
|
nassertr(has_sound_data(), 0);
|
|
|
|
|
|
|
|
MovieAudioCursor *cursor = _sd->_stream;
|
|
MovieAudioCursor *cursor = _sd->_stream;
|
|
|
- double length = cursor->length();
|
|
|
|
|
int channels = cursor->audio_channels();
|
|
int channels = cursor->audio_channels();
|
|
|
int rate = cursor->audio_rate();
|
|
int rate = cursor->audio_rate();
|
|
|
int space = bytelen / (channels * 2);
|
|
int space = bytelen / (channels * 2);
|
|
@@ -381,7 +380,7 @@ read_stream_data(int bytelen, unsigned char *buffer) {
|
|
|
|
|
|
|
|
while (space && (_loops_completed < _playing_loops)) {
|
|
while (space && (_loops_completed < _playing_loops)) {
|
|
|
double t = cursor->tell();
|
|
double t = cursor->tell();
|
|
|
- double remain = length - t;
|
|
|
|
|
|
|
+ double remain = cursor->length() - t;
|
|
|
if (remain > 60.0) {
|
|
if (remain > 60.0) {
|
|
|
remain = 60.0;
|
|
remain = 60.0;
|
|
|
}
|
|
}
|
|
@@ -403,9 +402,20 @@ read_stream_data(int bytelen, unsigned char *buffer) {
|
|
|
if (samples > _sd->_stream->ready()) {
|
|
if (samples > _sd->_stream->ready()) {
|
|
|
samples = _sd->_stream->ready();
|
|
samples = _sd->_stream->ready();
|
|
|
}
|
|
}
|
|
|
- cursor->read_samples(samples, (int16_t *)buffer);
|
|
|
|
|
- size_t hval = AddHash::add_hash(0, (uint8_t*)buffer, samples*channels*2);
|
|
|
|
|
- audio_debug("Streaming " << cursor->get_source()->get_name() << " at " << t << " hash " << hval);
|
|
|
|
|
|
|
+ samples = cursor->read_samples(samples, (int16_t *)buffer);
|
|
|
|
|
+ if (audio_cat.is_debug()) {
|
|
|
|
|
+ size_t hval = AddHash::add_hash(0, (uint8_t*)buffer, samples*channels*2);
|
|
|
|
|
+ audio_debug("Streaming " << cursor->get_source()->get_name() << " at " << t << " hash " << hval);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (samples == 0) {
|
|
|
|
|
+ _loops_completed += 1;
|
|
|
|
|
+ cursor->seek(0.0);
|
|
|
|
|
+ if (_playing_loops >= 1000000000) {
|
|
|
|
|
+ // Prevent infinite loop if endlessly looping empty sound
|
|
|
|
|
+ return fill;
|
|
|
|
|
+ }
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
fill += samples;
|
|
fill += samples;
|
|
|
space -= samples;
|
|
space -= samples;
|
|
|
buffer += (samples * channels * 2);
|
|
buffer += (samples * channels * 2);
|