Skip to content

Commit 9a5d7d8

Browse files
committed
openal: Add several asserts
This also includes a few slight style fixes.
1 parent 1a6fb53 commit 9a5d7d8

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

panda/src/audiotraits/openalAudioSound.cxx

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ cleanup() {
119119
void OpenALAudioSound::
120120
play() {
121121
ReMutexHolder holder(OpenALAudioManager::_lock);
122+
122123
if (!is_valid()) return;
123124

124125
PN_stdfloat px,py,pz,vx,vy,vz;
@@ -195,11 +196,14 @@ play() {
195196
void OpenALAudioSound::
196197
stop() {
197198
ReMutexHolder holder(OpenALAudioManager::_lock);
199+
198200
if (!is_valid()) return;
199201

200202
if (is_playing()) {
201203
_manager->make_current();
202204

205+
assert(has_sound_data());
206+
203207
alGetError(); // clear errors
204208
alSourceStop(_source);
205209
al_audio_errcheck("stopping a source");
@@ -224,6 +228,9 @@ stop() {
224228
void OpenALAudioSound::
225229
finished() {
226230
ReMutexHolder holder(OpenALAudioManager::_lock);
231+
232+
if (!is_valid()) return;
233+
227234
stop();
228235
_current_time = _length;
229236
if (!_finished_event.empty()) {
@@ -254,6 +261,7 @@ get_loop() const {
254261
void OpenALAudioSound::
255262
set_loop_count(unsigned long loop_count) {
256263
ReMutexHolder holder(OpenALAudioManager::_lock);
264+
257265
if (!is_valid()) return;
258266

259267
if (loop_count >= 1000000000) {
@@ -281,9 +289,14 @@ void OpenALAudioSound::
281289
restart_stalled_audio() {
282290
ReMutexHolder holder(OpenALAudioManager::_lock);
283291
ALenum status;
292+
293+
if (!is_valid()) return;
294+
assert(is_playing());
295+
284296
if (_stream_queued.size() == 0) {
285297
return;
286298
}
299+
287300
alGetError();
288301
alGetSourcei(_source, AL_SOURCE_STATE, &status);
289302
if (status != AL_PLAYING) {
@@ -297,6 +310,9 @@ restart_stalled_audio() {
297310
void OpenALAudioSound::
298311
queue_buffer(ALuint buffer, int samples, int loop_index, double time_offset) {
299312
ReMutexHolder holder(OpenALAudioManager::_lock);
313+
314+
assert(is_playing());
315+
300316
// Now push the buffer into the stream queue.
301317
alGetError();
302318
alSourceQueueBuffers(_source,1,&buffer);
@@ -321,6 +337,8 @@ ALuint OpenALAudioSound::
321337
make_buffer(int samples, int channels, int rate, unsigned char *data) {
322338
ReMutexHolder holder(OpenALAudioManager::_lock);
323339

340+
assert(is_playing());
341+
324342
// Allocate a buffer to hold the data.
325343
alGetError();
326344
ALuint buffer;
@@ -353,6 +371,8 @@ int OpenALAudioSound::
353371
read_stream_data(int bytelen, unsigned char *buffer) {
354372
ReMutexHolder holder(OpenALAudioManager::_lock);
355373

374+
assert(has_sound_data());
375+
356376
MovieAudioCursor *cursor = _sd->_stream;
357377
double length = cursor->length();
358378
int channels = cursor->audio_channels();
@@ -403,6 +423,9 @@ read_stream_data(int bytelen, unsigned char *buffer) {
403423
void OpenALAudioSound::
404424
correct_calibrated_clock(double rtc, double t) {
405425
ReMutexHolder holder(OpenALAudioManager::_lock);
426+
427+
assert(is_playing());
428+
406429
double cc = (rtc - _calibrated_clock_base) * _calibrated_clock_scale;
407430
double diff = cc-t;
408431
_calibrated_clock_decavg = (_calibrated_clock_decavg * 0.95) + (diff * 0.05);
@@ -434,7 +457,11 @@ correct_calibrated_clock(double rtc, double t) {
434457
void OpenALAudioSound::
435458
pull_used_buffers() {
436459
ReMutexHolder holder(OpenALAudioManager::_lock);
460+
437461
if (!is_valid()) return;
462+
assert(is_playing());
463+
assert(has_sound_data());
464+
438465
while (_stream_queued.size()) {
439466
ALuint buffer = 0;
440467
ALint num_buffers = 0;
@@ -491,6 +518,8 @@ push_fresh_buffers() {
491518
static unsigned char data[65536];
492519

493520
if (!is_valid()) return;
521+
assert(is_playing());
522+
assert(has_sound_data());
494523

495524
if (_sd->_sample) {
496525
while ((_loops_completed < _playing_loops) &&
@@ -553,7 +582,9 @@ get_time() const {
553582
void OpenALAudioSound::
554583
cache_time(double rtc) {
555584
ReMutexHolder holder(OpenALAudioManager::_lock);
585+
556586
assert(is_playing());
587+
557588
double t=get_calibrated_clock(rtc);
558589
double max = _length * _playing_loops;
559590
if (t >= max) {
@@ -761,13 +792,16 @@ get_3d_drop_off_factor() const {
761792
}
762793

763794
/**
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
765796
* true for all sounds. If the active flag is set to false for any particular
766797
* sound, the sound will not be heard.
767798
*/
768799
void OpenALAudioSound::
769800
set_active(bool active) {
770801
ReMutexHolder holder(OpenALAudioManager::_lock);
802+
803+
if (!is_valid()) return;
804+
771805
if (_active!=active) {
772806
_active=active;
773807
if (_active) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy