audio: Add positional property getter to AudioSound

Fixes #1257
Closes #1282

Co-authored-by: morganmliang <morganmliang@users.noreply.github.com>
This commit is contained in:
rdb 2022-11-06 11:15:47 +01:00
parent fea66ea087
commit 2ec147f3b0
7 changed files with 18 additions and 7 deletions

View File

@ -10,3 +10,11 @@
* @author jyelon * @author jyelon
* @date 2007-08-01 * @date 2007-08-01
*/ */
/**
* Returns true if this was created as a positional sound.
*/
INLINE bool AudioSound::
is_positional() const {
return _positional;
}

View File

@ -29,7 +29,7 @@ AudioSound::
* *
*/ */
AudioSound:: AudioSound::
AudioSound() { AudioSound(bool positional) : _positional(positional) {
// Intentionally blank. // Intentionally blank.
} }

View File

@ -88,6 +88,8 @@ PUBLISHED:
// There is no set_name(), this is intentional. // There is no set_name(), this is intentional.
virtual const std::string& get_name() const = 0; virtual const std::string& get_name() const = 0;
INLINE bool is_positional() const;
// return: playing time in seconds. // return: playing time in seconds.
virtual PN_stdfloat length() const = 0; virtual PN_stdfloat length() const = 0;
@ -134,9 +136,12 @@ PUBLISHED:
MAKE_PROPERTY(play_rate, get_play_rate, set_play_rate); MAKE_PROPERTY(play_rate, get_play_rate, set_play_rate);
MAKE_PROPERTY(active, get_active, set_active); MAKE_PROPERTY(active, get_active, set_active);
MAKE_PROPERTY(name, get_name); MAKE_PROPERTY(name, get_name);
MAKE_PROPERTY(positional, is_positional);
protected: protected:
AudioSound(); AudioSound(bool positional);
const bool _positional = false;
friend class AudioManager; friend class AudioManager;

View File

@ -26,7 +26,7 @@ namespace {
/** /**
* All of these functions are just stubs. * All of these functions are just stubs.
*/ */
NullAudioSound::NullAudioSound() { NullAudioSound::NullAudioSound() : AudioSound(false) {
// Intentionally blank. // Intentionally blank.
} }

View File

@ -37,9 +37,8 @@ TypeHandle FmodAudioSound::_type_handle;
* Constructor All sound will DEFAULT load as a 2D sound unless otherwise * Constructor All sound will DEFAULT load as a 2D sound unless otherwise
* specified. * specified.
*/ */
FmodAudioSound:: FmodAudioSound::
FmodAudioSound(AudioManager *manager, VirtualFile *file, bool positional) { FmodAudioSound(AudioManager *manager, VirtualFile *file, bool positional) : AudioSound(positional) {
ReMutexHolder holder(FmodAudioManager::_lock); ReMutexHolder holder(FmodAudioManager::_lock);
audio_debug("FmodAudioSound::FmodAudioSound() Creating new sound, filename: " audio_debug("FmodAudioSound::FmodAudioSound() Creating new sound, filename: "
<< file->get_original_filename()); << file->get_original_filename());

View File

@ -37,6 +37,7 @@ OpenALAudioSound(OpenALAudioManager* manager,
MovieAudio *movie, MovieAudio *movie,
bool positional, bool positional,
int mode) : int mode) :
AudioSound(positional),
_movie(movie), _movie(movie),
_sd(nullptr), _sd(nullptr),
_playing_loops(0), _playing_loops(0),
@ -47,7 +48,6 @@ OpenALAudioSound(OpenALAudioManager* manager,
_volume(1.0f), _volume(1.0f),
_balance(0), _balance(0),
_play_rate(1.0), _play_rate(1.0),
_positional(positional),
_min_dist(1.0f), _min_dist(1.0f),
_max_dist(1000000000.0f), _max_dist(1000000000.0f),
_drop_off_factor(1.0f), _drop_off_factor(1.0f),

View File

@ -152,7 +152,6 @@ private:
PN_stdfloat _balance; // -1..1 PN_stdfloat _balance; // -1..1
PN_stdfloat _play_rate; // 0..1.0 PN_stdfloat _play_rate; // 0..1.0
bool _positional;
ALfloat _location[3]; ALfloat _location[3];
ALfloat _velocity[3]; ALfloat _velocity[3];