mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 01:07:51 -04:00
first attempt to protect fmod against multithreaded access
This commit is contained in:
parent
370a9886b7
commit
25cb3ae4a5
@ -26,9 +26,9 @@
|
||||
#include "config_util.h"
|
||||
#include "fmodAudioManager.h"
|
||||
#include "fmodAudioSound.h"
|
||||
//Needed so People use Panda's Generic UNIX Style Paths for Filename.
|
||||
#include "filename.h"
|
||||
#include "virtualFileSystem.h"
|
||||
#include "reMutexHolder.h"
|
||||
|
||||
//FMOD Headers.
|
||||
#include <fmod.hpp>
|
||||
@ -38,6 +38,7 @@
|
||||
|
||||
TypeHandle FmodAudioManager::_type_handle;
|
||||
|
||||
ReMutex FmodAudioManager::_lock;
|
||||
FMOD::System *FmodAudioManager::_system;
|
||||
|
||||
pset<FmodAudioManager *> FmodAudioManager::_all_managers;
|
||||
@ -85,6 +86,7 @@ AudioManager *Create_FmodAudioManager() {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
FmodAudioManager::
|
||||
FmodAudioManager() {
|
||||
ReMutexHolder holder(_lock);
|
||||
FMOD_RESULT result;
|
||||
|
||||
//We need a varible temporary to check the FMOD Version.
|
||||
@ -187,6 +189,7 @@ FmodAudioManager() {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
FmodAudioManager::
|
||||
~FmodAudioManager() {
|
||||
ReMutexHolder holder(_lock);
|
||||
// Be sure to delete associated sounds before deleting the manager!
|
||||
FMOD_RESULT result;
|
||||
|
||||
@ -222,6 +225,7 @@ is_valid() {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
FMOD::DSP *FmodAudioManager::
|
||||
make_dsp(const FilterProperties::FilterConfig &conf) {
|
||||
ReMutexHolder holder(_lock);
|
||||
FMOD_DSP_TYPE dsptype;
|
||||
FMOD_RESULT result;
|
||||
FMOD::DSP *dsp;
|
||||
@ -348,6 +352,7 @@ make_dsp(const FilterProperties::FilterConfig &conf) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FmodAudioManager::
|
||||
update_dsp_chain(FMOD::DSP *head, FilterProperties *config) {
|
||||
ReMutexHolder holder(_lock);
|
||||
const FilterProperties::ConfigVector &conf = config->get_config();
|
||||
FMOD_RESULT result;
|
||||
|
||||
@ -391,6 +396,7 @@ update_dsp_chain(FMOD::DSP *head, FilterProperties *config) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool FmodAudioManager::
|
||||
configure_filters(FilterProperties *config) {
|
||||
ReMutexHolder holder(_lock);
|
||||
FMOD_RESULT result;
|
||||
FMOD::DSP *head;
|
||||
result = _channelgroup->getDSPHead(&head);
|
||||
@ -409,6 +415,7 @@ configure_filters(FilterProperties *config) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PT(AudioSound) FmodAudioManager::
|
||||
get_sound(const string &file_name, bool positional, int) {
|
||||
ReMutexHolder holder(_lock);
|
||||
//Needed so People use Panda's Generic UNIX Style Paths for Filename.
|
||||
//path.to_os_specific() converts it back to the proper OS version later on.
|
||||
|
||||
@ -446,6 +453,7 @@ get_sound(MovieAudio *source, bool positional, int) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
int FmodAudioManager::
|
||||
getSpeakerSetup() {
|
||||
ReMutexHolder holder(_lock);
|
||||
FMOD_RESULT result;
|
||||
FMOD_SPEAKERMODE speakerMode;
|
||||
int returnMode;
|
||||
@ -510,6 +518,7 @@ getSpeakerSetup() {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FmodAudioManager::
|
||||
setSpeakerSetup(AudioManager::SpeakerModeCategory cat) {
|
||||
ReMutexHolder holder(_lock);
|
||||
FMOD_RESULT result;
|
||||
FMOD_SPEAKERMODE speakerModeType = (FMOD_SPEAKERMODE)cat;
|
||||
result = _system->setSpeakerMode( speakerModeType);
|
||||
@ -524,6 +533,7 @@ setSpeakerSetup(AudioManager::SpeakerModeCategory cat) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FmodAudioManager::
|
||||
set_volume(PN_stdfloat volume) {
|
||||
ReMutexHolder holder(_lock);
|
||||
FMOD_RESULT result;
|
||||
result = _channelgroup->setVolume(volume);
|
||||
fmod_audio_errcheck("_channelgroup->setVolume()", result);
|
||||
@ -536,6 +546,7 @@ set_volume(PN_stdfloat volume) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PN_stdfloat FmodAudioManager::
|
||||
get_volume() const {
|
||||
ReMutexHolder holder(_lock);
|
||||
float volume;
|
||||
FMOD_RESULT result;
|
||||
result = _channelgroup->getVolume(&volume);
|
||||
@ -551,6 +562,7 @@ get_volume() const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FmodAudioManager::
|
||||
set_active(bool active) {
|
||||
ReMutexHolder holder(_lock);
|
||||
if (_active != active) {
|
||||
_active = active;
|
||||
|
||||
@ -580,6 +592,7 @@ get_active() const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FmodAudioManager::
|
||||
stop_all_sounds() {
|
||||
ReMutexHolder holder(_lock);
|
||||
// We have to walk through this list with some care, since stopping
|
||||
// a sound may also remove it from the set (if there are no other
|
||||
// references to the sound).
|
||||
@ -601,6 +614,7 @@ stop_all_sounds() {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FmodAudioManager::
|
||||
update() {
|
||||
ReMutexHolder holder(_lock);
|
||||
_system->update();
|
||||
}
|
||||
|
||||
@ -621,6 +635,7 @@ update() {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FmodAudioManager::
|
||||
audio_3d_set_listener_attributes(PN_stdfloat px, PN_stdfloat py, PN_stdfloat pz, PN_stdfloat vx, PN_stdfloat vy, PN_stdfloat vz, PN_stdfloat fx, PN_stdfloat fy, PN_stdfloat fz, PN_stdfloat ux, PN_stdfloat uy, PN_stdfloat uz) {
|
||||
ReMutexHolder holder(_lock);
|
||||
audio_debug("FmodAudioManager::audio_3d_set_listener_attributes()");
|
||||
|
||||
FMOD_RESULT result;
|
||||
@ -666,6 +681,7 @@ audio_3d_get_listener_attributes(PN_stdfloat *px, PN_stdfloat *py, PN_stdfloat *
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FmodAudioManager::
|
||||
audio_3d_set_distance_factor(PN_stdfloat factor) {
|
||||
ReMutexHolder holder(_lock);
|
||||
audio_debug( "FmodAudioManager::audio_3d_set_distance_factor( factor= " << factor << ")" );
|
||||
|
||||
FMOD_RESULT result;
|
||||
@ -699,6 +715,7 @@ audio_3d_get_distance_factor() const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FmodAudioManager::
|
||||
audio_3d_set_doppler_factor(PN_stdfloat factor) {
|
||||
ReMutexHolder holder(_lock);
|
||||
audio_debug("FmodAudioManager::audio_3d_set_doppler_factor(factor="<<factor<<")");
|
||||
|
||||
FMOD_RESULT result;
|
||||
@ -730,6 +747,7 @@ audio_3d_get_doppler_factor() const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FmodAudioManager::
|
||||
audio_3d_set_drop_off_factor(PN_stdfloat factor) {
|
||||
ReMutexHolder holder(_lock);
|
||||
audio_debug("FmodAudioManager::audio_3d_set_drop_off_factor("<<factor<<")");
|
||||
|
||||
FMOD_RESULT result;
|
||||
@ -748,6 +766,7 @@ audio_3d_set_drop_off_factor(PN_stdfloat factor) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PN_stdfloat FmodAudioManager::
|
||||
audio_3d_get_drop_off_factor() const {
|
||||
ReMutexHolder holder(_lock);
|
||||
audio_debug("FmodAudioManager::audio_3d_get_drop_off_factor()");
|
||||
|
||||
return _drop_off_factor;
|
||||
|
@ -169,7 +169,9 @@ private:
|
||||
virtual bool configure_filters(FilterProperties *config);
|
||||
|
||||
private:
|
||||
|
||||
// This global lock protects all access to FMod library interfaces.
|
||||
static ReMutex _lock;
|
||||
|
||||
static FMOD::System *_system;
|
||||
static pset<FmodAudioManager *> _all_managers;
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "fmodAudioSound.h"
|
||||
#include "string_utils.h"
|
||||
#include "subfileInfo.h"
|
||||
#include "reMutexHolder.h"
|
||||
|
||||
TypeHandle FmodAudioSound::_type_handle;
|
||||
|
||||
@ -39,6 +40,7 @@ TypeHandle FmodAudioSound::_type_handle;
|
||||
|
||||
FmodAudioSound::
|
||||
FmodAudioSound(AudioManager *manager, Filename file_name, bool positional) {
|
||||
ReMutexHolder holder(FmodAudioManager::_lock);
|
||||
audio_debug("FmodAudioSound::FmodAudioSound() Creating new sound, filename: " << file_name );
|
||||
|
||||
_active = manager->get_active();
|
||||
@ -212,6 +214,7 @@ FmodAudioSound(AudioManager *manager, Filename file_name, bool positional) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
FmodAudioSound::
|
||||
~FmodAudioSound() {
|
||||
ReMutexHolder holder(FmodAudioManager::_lock);
|
||||
FMOD_RESULT result;
|
||||
|
||||
//Remove me from table of all sounds.
|
||||
@ -240,6 +243,7 @@ play() {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FmodAudioSound::
|
||||
stop() {
|
||||
ReMutexHolder holder(FmodAudioManager::_lock);
|
||||
FMOD_RESULT result;
|
||||
|
||||
if (_channel != 0) {
|
||||
@ -295,7 +299,7 @@ get_loop() const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FmodAudioSound::
|
||||
set_loop_count(unsigned long loop_count) {
|
||||
|
||||
ReMutexHolder holder(FmodAudioManager::_lock);
|
||||
audio_debug("FmodAudioSound::set_loop_count() Setting the sound's loop count to: " << loop_count);
|
||||
|
||||
//LOCALS
|
||||
@ -328,6 +332,7 @@ set_loop_count(unsigned long loop_count) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
unsigned long FmodAudioSound::
|
||||
get_loop_count() const {
|
||||
ReMutexHolder holder(FmodAudioManager::_lock);
|
||||
FMOD_RESULT result;
|
||||
int loop_count;
|
||||
|
||||
@ -350,6 +355,7 @@ get_loop_count() const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FmodAudioSound::
|
||||
set_time(PN_stdfloat start_time) {
|
||||
ReMutexHolder holder(FmodAudioManager::_lock);
|
||||
_start_time = start_time;
|
||||
|
||||
if (status() == PLAYING) {
|
||||
@ -365,6 +371,7 @@ set_time(PN_stdfloat start_time) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PN_stdfloat FmodAudioSound::
|
||||
get_time() const {
|
||||
ReMutexHolder holder(FmodAudioManager::_lock);
|
||||
FMOD_RESULT result;
|
||||
unsigned int current_time;
|
||||
|
||||
@ -389,6 +396,7 @@ get_time() const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FmodAudioSound::
|
||||
set_volume(PN_stdfloat vol) {
|
||||
ReMutexHolder holder(FmodAudioManager::_lock);
|
||||
_volume = vol;
|
||||
set_volume_on_channel();
|
||||
}
|
||||
@ -410,6 +418,7 @@ get_volume() const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FmodAudioSound::
|
||||
start_playing() {
|
||||
ReMutexHolder holder(FmodAudioManager::_lock);
|
||||
FMOD_RESULT result;
|
||||
|
||||
if (!_active) {
|
||||
@ -469,6 +478,7 @@ start_playing() {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FmodAudioSound::
|
||||
set_volume_on_channel() {
|
||||
ReMutexHolder holder(FmodAudioManager::_lock);
|
||||
FMOD_RESULT result;
|
||||
|
||||
if (_channel != 0) {
|
||||
@ -488,6 +498,7 @@ set_volume_on_channel() {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FmodAudioSound::
|
||||
set_balance(PN_stdfloat bal) {
|
||||
ReMutexHolder holder(FmodAudioManager::_lock);
|
||||
_balance = bal;
|
||||
set_speaker_mix_or_balance_on_channel();
|
||||
}
|
||||
@ -516,6 +527,7 @@ get_balance() const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FmodAudioSound::
|
||||
set_play_rate(PN_stdfloat rate) {
|
||||
ReMutexHolder holder(FmodAudioManager::_lock);
|
||||
_playrate = rate;
|
||||
set_play_rate_on_channel();
|
||||
}
|
||||
@ -537,6 +549,7 @@ get_play_rate() const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FmodAudioSound::
|
||||
set_play_rate_on_channel() {
|
||||
ReMutexHolder holder(FmodAudioManager::_lock);
|
||||
FMOD_RESULT result;
|
||||
PN_stdfloat frequency = _sampleFrequency * _playrate;
|
||||
|
||||
@ -568,6 +581,7 @@ get_name() const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PN_stdfloat FmodAudioSound::
|
||||
length() const {
|
||||
ReMutexHolder holder(FmodAudioManager::_lock);
|
||||
FMOD_RESULT result;
|
||||
unsigned int length;
|
||||
|
||||
@ -594,6 +608,7 @@ length() const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FmodAudioSound::
|
||||
set_3d_attributes(PN_stdfloat px, PN_stdfloat py, PN_stdfloat pz, PN_stdfloat vx, PN_stdfloat vy, PN_stdfloat vz) {
|
||||
ReMutexHolder holder(FmodAudioManager::_lock);
|
||||
_location.x = px;
|
||||
_location.y = pz;
|
||||
_location.z = py;
|
||||
@ -612,6 +627,7 @@ set_3d_attributes(PN_stdfloat px, PN_stdfloat py, PN_stdfloat pz, PN_stdfloat vx
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FmodAudioSound::
|
||||
set_3d_attributes_on_channel() {
|
||||
ReMutexHolder holder(FmodAudioManager::_lock);
|
||||
FMOD_RESULT result;
|
||||
FMOD_MODE soundMode;
|
||||
|
||||
@ -647,6 +663,7 @@ get_3d_attributes(PN_stdfloat *px, PN_stdfloat *py, PN_stdfloat *pz, PN_stdfloat
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FmodAudioSound::
|
||||
set_3d_min_distance(PN_stdfloat dist) {
|
||||
ReMutexHolder holder(FmodAudioManager::_lock);
|
||||
FMOD_RESULT result;
|
||||
|
||||
_min_dist = dist;
|
||||
@ -672,6 +689,7 @@ get_3d_min_distance() const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FmodAudioSound::
|
||||
set_3d_max_distance(PN_stdfloat dist) {
|
||||
ReMutexHolder holder(FmodAudioManager::_lock);
|
||||
FMOD_RESULT result;
|
||||
|
||||
_max_dist = dist;
|
||||
@ -703,6 +721,7 @@ get_3d_max_distance() const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PN_stdfloat FmodAudioSound::
|
||||
get_speaker_mix(AudioManager::SpeakerId speaker) {
|
||||
ReMutexHolder holder(FmodAudioManager::_lock);
|
||||
if (_channel == 0) {
|
||||
return 0.0;
|
||||
}
|
||||
@ -751,6 +770,7 @@ get_speaker_mix(AudioManager::SpeakerId speaker) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FmodAudioSound::
|
||||
set_speaker_mix(PN_stdfloat frontleft, PN_stdfloat frontright, PN_stdfloat center, PN_stdfloat sub, PN_stdfloat backleft, PN_stdfloat backright, PN_stdfloat sideleft, PN_stdfloat sideright) {
|
||||
ReMutexHolder holder(FmodAudioManager::_lock);
|
||||
_mix[AudioManager::SPK_frontleft] = frontleft;
|
||||
_mix[AudioManager::SPK_frontright] = frontright;
|
||||
_mix[AudioManager::SPK_center] = center;
|
||||
@ -776,6 +796,7 @@ set_speaker_mix(PN_stdfloat frontleft, PN_stdfloat frontright, PN_stdfloat cente
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FmodAudioSound::
|
||||
set_speaker_mix_or_balance_on_channel() {
|
||||
ReMutexHolder holder(FmodAudioManager::_lock);
|
||||
FMOD_RESULT result;
|
||||
FMOD_MODE soundMode;
|
||||
|
||||
@ -825,7 +846,7 @@ get_priority() {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FmodAudioSound::
|
||||
set_priority(int priority) {
|
||||
// intentionally blank
|
||||
ReMutexHolder holder(FmodAudioManager::_lock);
|
||||
|
||||
audio_debug("FmodAudioSound::set_priority()");
|
||||
|
||||
@ -844,6 +865,7 @@ set_priority(int priority) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
AudioSound::SoundStatus FmodAudioSound::
|
||||
status() const {
|
||||
ReMutexHolder holder(FmodAudioManager::_lock);
|
||||
FMOD_RESULT result;
|
||||
bool playingState;
|
||||
|
||||
@ -869,6 +891,7 @@ status() const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FmodAudioSound::
|
||||
set_active(bool active) {
|
||||
ReMutexHolder holder(FmodAudioManager::_lock);
|
||||
if (_active != active) {
|
||||
_active = active;
|
||||
if (_active) {
|
||||
|
@ -76,6 +76,7 @@
|
||||
#ifdef HAVE_FMODEX //[
|
||||
|
||||
#include "audioSound.h"
|
||||
#include "reMutex.h"
|
||||
|
||||
#include <fmod.hpp>
|
||||
#include <fmod_errors.h>
|
||||
|
Loading…
x
Reference in New Issue
Block a user