Skip to content

Commit 1a6fb53

Browse files
committed
openal: Be explicit about what constructs like _sound != 0 mean
1 parent fd5ce68 commit 1a6fb53

File tree

3 files changed

+55
-23
lines changed

3 files changed

+55
-23
lines changed

panda/src/audiotraits/openalAudioSound.I

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,33 @@ release_sound_data() {
6363
_sd = 0;
6464
}
6565
}
66+
67+
/**
68+
* Checks if the sound has NOT been cleaned up yet.
69+
*/
70+
bool OpenALAudioSound::
71+
is_valid() const {
72+
return _manager != NULL;
73+
}
74+
75+
/**
76+
* Checks if the sound is playing. This is per the OpenALAudioManager's
77+
* definition of "playing" -- as in, "will be called upon every update"
78+
*
79+
* This is mainly intended for use in asserts.
80+
*/
81+
bool OpenALAudioSound::
82+
is_playing() const {
83+
// Manager only gives us a _source if we need it (to talk to OpenAL), so:
84+
return _source != 0;
85+
}
86+
87+
/**
88+
* Checks if the sound has its SoundData structure open at the moment.
89+
*
90+
* This is mainly intended for use in asserts.
91+
*/
92+
bool OpenALAudioSound::
93+
has_sound_data() const {
94+
return _sd != 0;
95+
}

panda/src/audiotraits/openalAudioSound.cxx

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ OpenALAudioSound::
9999
void OpenALAudioSound::
100100
cleanup() {
101101
ReMutexHolder holder(OpenALAudioManager::_lock);
102-
if (_manager == 0) {
102+
if (!is_valid()) {
103103
return;
104104
}
105-
if (_source) {
105+
if (is_playing()) {
106106
stop();
107107
}
108-
if (_sd) {
108+
if (has_sound_data()) {
109109
_manager->decrement_client_count(_sd);
110110
_sd = 0;
111111
}
@@ -119,7 +119,7 @@ cleanup() {
119119
void OpenALAudioSound::
120120
play() {
121121
ReMutexHolder holder(OpenALAudioManager::_lock);
122-
if (_manager == 0) return;
122+
if (!is_valid()) return;
123123

124124
PN_stdfloat px,py,pz,vx,vy,vz;
125125

@@ -136,7 +136,7 @@ play() {
136136
}
137137

138138
_manager->starting_sound(this);
139-
if (!_source) {
139+
if (!is_playing()) {
140140
return;
141141
}
142142

@@ -195,9 +195,9 @@ play() {
195195
void OpenALAudioSound::
196196
stop() {
197197
ReMutexHolder holder(OpenALAudioManager::_lock);
198-
if (_manager==0) return;
198+
if (!is_valid()) return;
199199

200-
if (_source) {
200+
if (is_playing()) {
201201
_manager->make_current();
202202

203203
alGetError(); // clear errors
@@ -254,7 +254,7 @@ get_loop() const {
254254
void OpenALAudioSound::
255255
set_loop_count(unsigned long loop_count) {
256256
ReMutexHolder holder(OpenALAudioManager::_lock);
257-
if (_manager==0) return;
257+
if (!is_valid()) return;
258258

259259
if (loop_count >= 1000000000) {
260260
loop_count = 0;
@@ -434,7 +434,7 @@ correct_calibrated_clock(double rtc, double t) {
434434
void OpenALAudioSound::
435435
pull_used_buffers() {
436436
ReMutexHolder holder(OpenALAudioManager::_lock);
437-
if (_manager == 0) return;
437+
if (!is_valid()) return;
438438
while (_stream_queued.size()) {
439439
ALuint buffer = 0;
440440
ALint num_buffers = 0;
@@ -490,7 +490,7 @@ push_fresh_buffers() {
490490
ReMutexHolder holder(OpenALAudioManager::_lock);
491491
static unsigned char data[65536];
492492

493-
if (_manager == 0) return;
493+
if (!is_valid()) return;
494494

495495
if (_sd->_sample) {
496496
while ((_loops_completed < _playing_loops) &&
@@ -517,9 +517,9 @@ push_fresh_buffers() {
517517
break;
518518
}
519519
ALuint buffer = make_buffer(samples, channels, rate, data);
520-
if (_manager == 0) return;
520+
if (!is_valid()) return;
521521
queue_buffer(buffer, samples, loop_index, time_offset);
522-
if (_manager == 0) return;
522+
if (!is_valid()) return;
523523
fill += samples;
524524
}
525525
}
@@ -541,7 +541,7 @@ set_time(PN_stdfloat time) {
541541
PN_stdfloat OpenALAudioSound::
542542
get_time() const {
543543
ReMutexHolder holder(OpenALAudioManager::_lock);
544-
if (_manager == 0) {
544+
if (!is_valid()) {
545545
return 0.0;
546546
}
547547
return _current_time;
@@ -553,7 +553,7 @@ get_time() const {
553553
void OpenALAudioSound::
554554
cache_time(double rtc) {
555555
ReMutexHolder holder(OpenALAudioManager::_lock);
556-
assert(_source != 0);
556+
assert(is_playing());
557557
double t=get_calibrated_clock(rtc);
558558
double max = _length * _playing_loops;
559559
if (t >= max) {
@@ -571,7 +571,7 @@ set_volume(PN_stdfloat volume) {
571571
ReMutexHolder holder(OpenALAudioManager::_lock);
572572
_volume=volume;
573573

574-
if (_source) {
574+
if (is_playing()) {
575575
volume*=_manager->get_volume();
576576
_manager->make_current();
577577
alGetError(); // clear errors
@@ -615,7 +615,7 @@ void OpenALAudioSound::
615615
set_play_rate(PN_stdfloat play_rate) {
616616
ReMutexHolder holder(OpenALAudioManager::_lock);
617617
_play_rate = play_rate;
618-
if (_source) {
618+
if (is_playing()) {
619619
alSourcef(_source, AL_PITCH, play_rate);
620620
}
621621
}
@@ -657,7 +657,7 @@ set_3d_attributes(PN_stdfloat px, PN_stdfloat py, PN_stdfloat pz, PN_stdfloat vx
657657
_velocity[1] = vz;
658658
_velocity[2] = -vy;
659659

660-
if (_source) {
660+
if (is_playing()) {
661661
_manager->make_current();
662662

663663
alGetError(); // clear errors
@@ -693,7 +693,7 @@ set_3d_min_distance(PN_stdfloat dist) {
693693
ReMutexHolder holder(OpenALAudioManager::_lock);
694694
_min_dist = dist;
695695

696-
if (_source) {
696+
if (is_playing()) {
697697
_manager->make_current();
698698

699699
alGetError(); // clear errors
@@ -718,7 +718,7 @@ set_3d_max_distance(PN_stdfloat dist) {
718718
ReMutexHolder holder(OpenALAudioManager::_lock);
719719
_max_dist = dist;
720720

721-
if (_source) {
721+
if (is_playing()) {
722722
_manager->make_current();
723723

724724
alGetError(); // clear errors
@@ -743,7 +743,7 @@ set_3d_drop_off_factor(PN_stdfloat factor) {
743743
ReMutexHolder holder(OpenALAudioManager::_lock);
744744
_drop_off_factor = factor;
745745

746-
if (_source) {
746+
if (is_playing()) {
747747
_manager->make_current();
748748

749749
alGetError(); // clear errors
@@ -831,7 +831,7 @@ get_name() const {
831831
AudioSound::SoundStatus OpenALAudioSound::
832832
status() const {
833833
ReMutexHolder holder(OpenALAudioManager::_lock);
834-
if (_source==0) {
834+
if (!is_playing()) {
835835
return AudioSound::READY;
836836
}
837837
if ((_loops_completed >= _playing_loops)&&(_stream_queued.size()==0)) {

panda/src/audiotraits/openalAudioSound.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,11 @@ class EXPCL_OPENAL_AUDIO OpenALAudioSound : public AudioSound {
119119
INLINE bool require_sound_data();
120120
INLINE void release_sound_data();
121121

122-
private:
122+
INLINE bool is_valid() const;
123+
INLINE bool is_playing() const;
124+
INLINE bool has_sound_data() const;
123125

124-
void do_stop();
126+
private:
125127

126128
PT(MovieAudio) _movie;
127129
OpenALAudioManager::SoundData *_sd;

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