mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 01:44:06 -04:00
openal: Be explicit about what constructs like _sound != 0
mean
This commit is contained in:
parent
fd5ce687b3
commit
1a6fb5300b
@ -63,3 +63,33 @@ release_sound_data() {
|
|||||||
_sd = 0;
|
_sd = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the sound has NOT been cleaned up yet.
|
||||||
|
*/
|
||||||
|
bool OpenALAudioSound::
|
||||||
|
is_valid() const {
|
||||||
|
return _manager != NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the sound is playing. This is per the OpenALAudioManager's
|
||||||
|
* definition of "playing" -- as in, "will be called upon every update"
|
||||||
|
*
|
||||||
|
* This is mainly intended for use in asserts.
|
||||||
|
*/
|
||||||
|
bool OpenALAudioSound::
|
||||||
|
is_playing() const {
|
||||||
|
// Manager only gives us a _source if we need it (to talk to OpenAL), so:
|
||||||
|
return _source != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the sound has its SoundData structure open at the moment.
|
||||||
|
*
|
||||||
|
* This is mainly intended for use in asserts.
|
||||||
|
*/
|
||||||
|
bool OpenALAudioSound::
|
||||||
|
has_sound_data() const {
|
||||||
|
return _sd != 0;
|
||||||
|
}
|
||||||
|
@ -99,13 +99,13 @@ OpenALAudioSound::
|
|||||||
void OpenALAudioSound::
|
void OpenALAudioSound::
|
||||||
cleanup() {
|
cleanup() {
|
||||||
ReMutexHolder holder(OpenALAudioManager::_lock);
|
ReMutexHolder holder(OpenALAudioManager::_lock);
|
||||||
if (_manager == 0) {
|
if (!is_valid()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_source) {
|
if (is_playing()) {
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
if (_sd) {
|
if (has_sound_data()) {
|
||||||
_manager->decrement_client_count(_sd);
|
_manager->decrement_client_count(_sd);
|
||||||
_sd = 0;
|
_sd = 0;
|
||||||
}
|
}
|
||||||
@ -119,7 +119,7 @@ cleanup() {
|
|||||||
void OpenALAudioSound::
|
void OpenALAudioSound::
|
||||||
play() {
|
play() {
|
||||||
ReMutexHolder holder(OpenALAudioManager::_lock);
|
ReMutexHolder holder(OpenALAudioManager::_lock);
|
||||||
if (_manager == 0) return;
|
if (!is_valid()) return;
|
||||||
|
|
||||||
PN_stdfloat px,py,pz,vx,vy,vz;
|
PN_stdfloat px,py,pz,vx,vy,vz;
|
||||||
|
|
||||||
@ -136,7 +136,7 @@ play() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_manager->starting_sound(this);
|
_manager->starting_sound(this);
|
||||||
if (!_source) {
|
if (!is_playing()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,9 +195,9 @@ play() {
|
|||||||
void OpenALAudioSound::
|
void OpenALAudioSound::
|
||||||
stop() {
|
stop() {
|
||||||
ReMutexHolder holder(OpenALAudioManager::_lock);
|
ReMutexHolder holder(OpenALAudioManager::_lock);
|
||||||
if (_manager==0) return;
|
if (!is_valid()) return;
|
||||||
|
|
||||||
if (_source) {
|
if (is_playing()) {
|
||||||
_manager->make_current();
|
_manager->make_current();
|
||||||
|
|
||||||
alGetError(); // clear errors
|
alGetError(); // clear errors
|
||||||
@ -254,7 +254,7 @@ get_loop() const {
|
|||||||
void OpenALAudioSound::
|
void OpenALAudioSound::
|
||||||
set_loop_count(unsigned long loop_count) {
|
set_loop_count(unsigned long loop_count) {
|
||||||
ReMutexHolder holder(OpenALAudioManager::_lock);
|
ReMutexHolder holder(OpenALAudioManager::_lock);
|
||||||
if (_manager==0) return;
|
if (!is_valid()) return;
|
||||||
|
|
||||||
if (loop_count >= 1000000000) {
|
if (loop_count >= 1000000000) {
|
||||||
loop_count = 0;
|
loop_count = 0;
|
||||||
@ -434,7 +434,7 @@ correct_calibrated_clock(double rtc, double t) {
|
|||||||
void OpenALAudioSound::
|
void OpenALAudioSound::
|
||||||
pull_used_buffers() {
|
pull_used_buffers() {
|
||||||
ReMutexHolder holder(OpenALAudioManager::_lock);
|
ReMutexHolder holder(OpenALAudioManager::_lock);
|
||||||
if (_manager == 0) return;
|
if (!is_valid()) return;
|
||||||
while (_stream_queued.size()) {
|
while (_stream_queued.size()) {
|
||||||
ALuint buffer = 0;
|
ALuint buffer = 0;
|
||||||
ALint num_buffers = 0;
|
ALint num_buffers = 0;
|
||||||
@ -490,7 +490,7 @@ push_fresh_buffers() {
|
|||||||
ReMutexHolder holder(OpenALAudioManager::_lock);
|
ReMutexHolder holder(OpenALAudioManager::_lock);
|
||||||
static unsigned char data[65536];
|
static unsigned char data[65536];
|
||||||
|
|
||||||
if (_manager == 0) return;
|
if (!is_valid()) return;
|
||||||
|
|
||||||
if (_sd->_sample) {
|
if (_sd->_sample) {
|
||||||
while ((_loops_completed < _playing_loops) &&
|
while ((_loops_completed < _playing_loops) &&
|
||||||
@ -517,9 +517,9 @@ push_fresh_buffers() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ALuint buffer = make_buffer(samples, channels, rate, data);
|
ALuint buffer = make_buffer(samples, channels, rate, data);
|
||||||
if (_manager == 0) return;
|
if (!is_valid()) return;
|
||||||
queue_buffer(buffer, samples, loop_index, time_offset);
|
queue_buffer(buffer, samples, loop_index, time_offset);
|
||||||
if (_manager == 0) return;
|
if (!is_valid()) return;
|
||||||
fill += samples;
|
fill += samples;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -541,7 +541,7 @@ set_time(PN_stdfloat time) {
|
|||||||
PN_stdfloat OpenALAudioSound::
|
PN_stdfloat OpenALAudioSound::
|
||||||
get_time() const {
|
get_time() const {
|
||||||
ReMutexHolder holder(OpenALAudioManager::_lock);
|
ReMutexHolder holder(OpenALAudioManager::_lock);
|
||||||
if (_manager == 0) {
|
if (!is_valid()) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
return _current_time;
|
return _current_time;
|
||||||
@ -553,7 +553,7 @@ get_time() const {
|
|||||||
void OpenALAudioSound::
|
void OpenALAudioSound::
|
||||||
cache_time(double rtc) {
|
cache_time(double rtc) {
|
||||||
ReMutexHolder holder(OpenALAudioManager::_lock);
|
ReMutexHolder holder(OpenALAudioManager::_lock);
|
||||||
assert(_source != 0);
|
assert(is_playing());
|
||||||
double t=get_calibrated_clock(rtc);
|
double t=get_calibrated_clock(rtc);
|
||||||
double max = _length * _playing_loops;
|
double max = _length * _playing_loops;
|
||||||
if (t >= max) {
|
if (t >= max) {
|
||||||
@ -571,7 +571,7 @@ set_volume(PN_stdfloat volume) {
|
|||||||
ReMutexHolder holder(OpenALAudioManager::_lock);
|
ReMutexHolder holder(OpenALAudioManager::_lock);
|
||||||
_volume=volume;
|
_volume=volume;
|
||||||
|
|
||||||
if (_source) {
|
if (is_playing()) {
|
||||||
volume*=_manager->get_volume();
|
volume*=_manager->get_volume();
|
||||||
_manager->make_current();
|
_manager->make_current();
|
||||||
alGetError(); // clear errors
|
alGetError(); // clear errors
|
||||||
@ -615,7 +615,7 @@ void OpenALAudioSound::
|
|||||||
set_play_rate(PN_stdfloat play_rate) {
|
set_play_rate(PN_stdfloat play_rate) {
|
||||||
ReMutexHolder holder(OpenALAudioManager::_lock);
|
ReMutexHolder holder(OpenALAudioManager::_lock);
|
||||||
_play_rate = play_rate;
|
_play_rate = play_rate;
|
||||||
if (_source) {
|
if (is_playing()) {
|
||||||
alSourcef(_source, AL_PITCH, play_rate);
|
alSourcef(_source, AL_PITCH, play_rate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -657,7 +657,7 @@ set_3d_attributes(PN_stdfloat px, PN_stdfloat py, PN_stdfloat pz, PN_stdfloat vx
|
|||||||
_velocity[1] = vz;
|
_velocity[1] = vz;
|
||||||
_velocity[2] = -vy;
|
_velocity[2] = -vy;
|
||||||
|
|
||||||
if (_source) {
|
if (is_playing()) {
|
||||||
_manager->make_current();
|
_manager->make_current();
|
||||||
|
|
||||||
alGetError(); // clear errors
|
alGetError(); // clear errors
|
||||||
@ -693,7 +693,7 @@ set_3d_min_distance(PN_stdfloat dist) {
|
|||||||
ReMutexHolder holder(OpenALAudioManager::_lock);
|
ReMutexHolder holder(OpenALAudioManager::_lock);
|
||||||
_min_dist = dist;
|
_min_dist = dist;
|
||||||
|
|
||||||
if (_source) {
|
if (is_playing()) {
|
||||||
_manager->make_current();
|
_manager->make_current();
|
||||||
|
|
||||||
alGetError(); // clear errors
|
alGetError(); // clear errors
|
||||||
@ -718,7 +718,7 @@ set_3d_max_distance(PN_stdfloat dist) {
|
|||||||
ReMutexHolder holder(OpenALAudioManager::_lock);
|
ReMutexHolder holder(OpenALAudioManager::_lock);
|
||||||
_max_dist = dist;
|
_max_dist = dist;
|
||||||
|
|
||||||
if (_source) {
|
if (is_playing()) {
|
||||||
_manager->make_current();
|
_manager->make_current();
|
||||||
|
|
||||||
alGetError(); // clear errors
|
alGetError(); // clear errors
|
||||||
@ -743,7 +743,7 @@ set_3d_drop_off_factor(PN_stdfloat factor) {
|
|||||||
ReMutexHolder holder(OpenALAudioManager::_lock);
|
ReMutexHolder holder(OpenALAudioManager::_lock);
|
||||||
_drop_off_factor = factor;
|
_drop_off_factor = factor;
|
||||||
|
|
||||||
if (_source) {
|
if (is_playing()) {
|
||||||
_manager->make_current();
|
_manager->make_current();
|
||||||
|
|
||||||
alGetError(); // clear errors
|
alGetError(); // clear errors
|
||||||
@ -831,7 +831,7 @@ get_name() const {
|
|||||||
AudioSound::SoundStatus OpenALAudioSound::
|
AudioSound::SoundStatus OpenALAudioSound::
|
||||||
status() const {
|
status() const {
|
||||||
ReMutexHolder holder(OpenALAudioManager::_lock);
|
ReMutexHolder holder(OpenALAudioManager::_lock);
|
||||||
if (_source==0) {
|
if (!is_playing()) {
|
||||||
return AudioSound::READY;
|
return AudioSound::READY;
|
||||||
}
|
}
|
||||||
if ((_loops_completed >= _playing_loops)&&(_stream_queued.size()==0)) {
|
if ((_loops_completed >= _playing_loops)&&(_stream_queued.size()==0)) {
|
||||||
|
@ -119,9 +119,11 @@ private:
|
|||||||
INLINE bool require_sound_data();
|
INLINE bool require_sound_data();
|
||||||
INLINE void release_sound_data();
|
INLINE void release_sound_data();
|
||||||
|
|
||||||
private:
|
INLINE bool is_valid() const;
|
||||||
|
INLINE bool is_playing() const;
|
||||||
|
INLINE bool has_sound_data() const;
|
||||||
|
|
||||||
void do_stop();
|
private:
|
||||||
|
|
||||||
PT(MovieAudio) _movie;
|
PT(MovieAudio) _movie;
|
||||||
OpenALAudioManager::SoundData *_sd;
|
OpenALAudioManager::SoundData *_sd;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user