@@ -119,6 +119,7 @@ cleanup() {
119
119
void OpenALAudioSound::
120
120
play () {
121
121
ReMutexHolder holder (OpenALAudioManager::_lock);
122
+
122
123
if (!is_valid ()) return ;
123
124
124
125
PN_stdfloat px,py,pz,vx,vy,vz;
@@ -195,11 +196,14 @@ play() {
195
196
void OpenALAudioSound::
196
197
stop () {
197
198
ReMutexHolder holder (OpenALAudioManager::_lock);
199
+
198
200
if (!is_valid ()) return ;
199
201
200
202
if (is_playing ()) {
201
203
_manager->make_current ();
202
204
205
+ assert (has_sound_data ());
206
+
203
207
alGetError (); // clear errors
204
208
alSourceStop (_source);
205
209
al_audio_errcheck (" stopping a source" );
@@ -224,6 +228,9 @@ stop() {
224
228
void OpenALAudioSound::
225
229
finished () {
226
230
ReMutexHolder holder (OpenALAudioManager::_lock);
231
+
232
+ if (!is_valid ()) return ;
233
+
227
234
stop ();
228
235
_current_time = _length;
229
236
if (!_finished_event.empty ()) {
@@ -254,6 +261,7 @@ get_loop() const {
254
261
void OpenALAudioSound::
255
262
set_loop_count (unsigned long loop_count) {
256
263
ReMutexHolder holder (OpenALAudioManager::_lock);
264
+
257
265
if (!is_valid ()) return ;
258
266
259
267
if (loop_count >= 1000000000 ) {
@@ -281,9 +289,14 @@ void OpenALAudioSound::
281
289
restart_stalled_audio () {
282
290
ReMutexHolder holder (OpenALAudioManager::_lock);
283
291
ALenum status;
292
+
293
+ if (!is_valid ()) return ;
294
+ assert (is_playing ());
295
+
284
296
if (_stream_queued.size () == 0 ) {
285
297
return ;
286
298
}
299
+
287
300
alGetError ();
288
301
alGetSourcei (_source, AL_SOURCE_STATE, &status);
289
302
if (status != AL_PLAYING) {
@@ -297,6 +310,9 @@ restart_stalled_audio() {
297
310
void OpenALAudioSound::
298
311
queue_buffer (ALuint buffer, int samples, int loop_index, double time_offset) {
299
312
ReMutexHolder holder (OpenALAudioManager::_lock);
313
+
314
+ assert (is_playing ());
315
+
300
316
// Now push the buffer into the stream queue.
301
317
alGetError ();
302
318
alSourceQueueBuffers (_source,1 ,&buffer);
@@ -321,6 +337,8 @@ ALuint OpenALAudioSound::
321
337
make_buffer (int samples, int channels, int rate, unsigned char *data) {
322
338
ReMutexHolder holder (OpenALAudioManager::_lock);
323
339
340
+ assert (is_playing ());
341
+
324
342
// Allocate a buffer to hold the data.
325
343
alGetError ();
326
344
ALuint buffer;
@@ -353,6 +371,8 @@ int OpenALAudioSound::
353
371
read_stream_data (int bytelen, unsigned char *buffer) {
354
372
ReMutexHolder holder (OpenALAudioManager::_lock);
355
373
374
+ assert (has_sound_data ());
375
+
356
376
MovieAudioCursor *cursor = _sd->_stream ;
357
377
double length = cursor->length ();
358
378
int channels = cursor->audio_channels ();
@@ -403,6 +423,9 @@ read_stream_data(int bytelen, unsigned char *buffer) {
403
423
void OpenALAudioSound::
404
424
correct_calibrated_clock (double rtc, double t) {
405
425
ReMutexHolder holder (OpenALAudioManager::_lock);
426
+
427
+ assert (is_playing ());
428
+
406
429
double cc = (rtc - _calibrated_clock_base) * _calibrated_clock_scale;
407
430
double diff = cc-t;
408
431
_calibrated_clock_decavg = (_calibrated_clock_decavg * 0.95 ) + (diff * 0.05 );
@@ -434,7 +457,11 @@ correct_calibrated_clock(double rtc, double t) {
434
457
void OpenALAudioSound::
435
458
pull_used_buffers () {
436
459
ReMutexHolder holder (OpenALAudioManager::_lock);
460
+
437
461
if (!is_valid ()) return ;
462
+ assert (is_playing ());
463
+ assert (has_sound_data ());
464
+
438
465
while (_stream_queued.size ()) {
439
466
ALuint buffer = 0 ;
440
467
ALint num_buffers = 0 ;
@@ -491,6 +518,8 @@ push_fresh_buffers() {
491
518
static unsigned char data[65536 ];
492
519
493
520
if (!is_valid ()) return ;
521
+ assert (is_playing ());
522
+ assert (has_sound_data ());
494
523
495
524
if (_sd->_sample ) {
496
525
while ((_loops_completed < _playing_loops) &&
@@ -553,7 +582,9 @@ get_time() const {
553
582
void OpenALAudioSound::
554
583
cache_time (double rtc) {
555
584
ReMutexHolder holder (OpenALAudioManager::_lock);
585
+
556
586
assert (is_playing ());
587
+
557
588
double t=get_calibrated_clock (rtc);
558
589
double max = _length * _playing_loops;
559
590
if (t >= max) {
@@ -761,13 +792,16 @@ get_3d_drop_off_factor() const {
761
792
}
762
793
763
794
/* *
764
- * Sets whether the sound is marked "active". By default, the active flag
795
+ * Sets whether the sound is marked "active". By default, the active flag is
765
796
* true for all sounds. If the active flag is set to false for any particular
766
797
* sound, the sound will not be heard.
767
798
*/
768
799
void OpenALAudioSound::
769
800
set_active (bool active) {
770
801
ReMutexHolder holder (OpenALAudioManager::_lock);
802
+
803
+ if (!is_valid ()) return ;
804
+
771
805
if (_active!=active) {
772
806
_active=active;
773
807
if (_active) {
0 commit comments