|
|
@@ -53,6 +53,7 @@ OpenALAudioSound(OpenALAudioManager* manager,
|
|
|
_drop_off_factor(1.0f),
|
|
|
_length(0.0),
|
|
|
_loop_count(1),
|
|
|
+ _loop_start(0),
|
|
|
_desired_mode(mode),
|
|
|
_start_time(0.0),
|
|
|
_current_time(0.0),
|
|
|
@@ -279,6 +280,36 @@ get_loop_count() const {
|
|
|
return _loop_count;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Sets the time at which subsequent loops will begin.
|
|
|
+ * A value of 0 indicates the beginning of the audio.
|
|
|
+ */
|
|
|
+void OpenALAudioSound::
|
|
|
+set_loop_start(PN_stdfloat loop_start) {
|
|
|
+ ReMutexHolder holder(OpenALAudioManager::_lock);
|
|
|
+
|
|
|
+ if (!is_valid()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (loop_start >= _length) {
|
|
|
+ // This loop would begin after the song ends.
|
|
|
+ // Not a good idea.
|
|
|
+ loop_start = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ _loop_start = loop_start;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Return the time at which subsequent loops will begin.
|
|
|
+ * A value of 0 indicates the beginning of the audio.
|
|
|
+ */
|
|
|
+PN_stdfloat OpenALAudioSound::
|
|
|
+get_loop_start() const {
|
|
|
+ return _loop_start;
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* When streaming audio, the computer is supposed to keep OpenAL's queue full.
|
|
|
* However, there are times when the computer is running slow and the queue
|
|
|
@@ -389,7 +420,7 @@ read_stream_data(int bytelen, unsigned char *buffer) {
|
|
|
int samples = (int)(remain * rate);
|
|
|
if (samples <= 0) {
|
|
|
_loops_completed += 1;
|
|
|
- cursor->seek(0.0);
|
|
|
+ cursor->seek(_loop_start);
|
|
|
continue;
|
|
|
}
|
|
|
if (_sd->_stream->ready() == 0) {
|
|
|
@@ -411,7 +442,7 @@ read_stream_data(int bytelen, unsigned char *buffer) {
|
|
|
}
|
|
|
if (samples == 0) {
|
|
|
_loops_completed += 1;
|
|
|
- cursor->seek(0.0);
|
|
|
+ cursor->seek(_loop_start);
|
|
|
if (_playing_loops >= 1000000000) {
|
|
|
// Prevent infinite loop if endlessly looping empty sound
|
|
|
return fill;
|
|
|
@@ -535,7 +566,7 @@ push_fresh_buffers() {
|
|
|
if (_sd->_sample) {
|
|
|
while ((_loops_completed < _playing_loops) &&
|
|
|
(_stream_queued.size() < 100)) {
|
|
|
- queue_buffer(_sd->_sample, 0,_loops_completed, 0.0);
|
|
|
+ queue_buffer(_sd->_sample, 0,_loops_completed, _loop_start);
|
|
|
_loops_completed += 1;
|
|
|
}
|
|
|
} else {
|