mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 02:42:49 -04:00
Audio changes
This commit is contained in:
parent
5d2466c72a
commit
215e2bf894
@ -271,5 +271,4 @@ class Audio3DManager:
|
||||
self.audio_manager.audio3dSetListenerAttributes(pos[0], pos[1], pos[2], vel[0], vel[1], vel[2], 0, 1, 0, 0, 0, 1)
|
||||
else:
|
||||
self.audio_manager.audio3dSetListenerAttributes(0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1)
|
||||
self.audio_manager.audio3dUpdate()
|
||||
return Task.cont
|
||||
|
@ -1314,6 +1314,13 @@ class ShowBase(DirectObject.DirectObject):
|
||||
self.appTrav.traverse(self.render)
|
||||
return Task.cont
|
||||
|
||||
def audioLoop(self, state):
|
||||
if (self.musicManager != None):
|
||||
self.musicManager.update()
|
||||
for x in self.sfxManagerList:
|
||||
x.update()
|
||||
return Task.cont
|
||||
|
||||
def igLoop(self, state):
|
||||
# We render the watch variables for the onScreenDebug as soon
|
||||
# as we reasonably can before the renderFrame().
|
||||
@ -1374,9 +1381,13 @@ class ShowBase(DirectObject.DirectObject):
|
||||
# give the igLoop task a reasonably "late" priority,
|
||||
# so that it will get run after most tasks
|
||||
self.taskMgr.add(self.igLoop, 'igLoop', priority = 50)
|
||||
# the audioLoop updates the positions of 3D sounds.
|
||||
# as such, it needs to run after the cull traversal in the igLoop.
|
||||
self.taskMgr.add(self.audioLoop, 'audioLoop', priority = 60)
|
||||
self.eventMgr.restart()
|
||||
|
||||
def shutdown(self):
|
||||
self.taskMgr.remove('audioLoop')
|
||||
self.taskMgr.remove('igLoop')
|
||||
self.taskMgr.remove('shadowCollisionLoop')
|
||||
self.taskMgr.remove('collisionLoop')
|
||||
|
@ -152,8 +152,8 @@ get_null_sound() {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PT(AudioDSP) AudioManager::
|
||||
create_dsp(DSP_category) {
|
||||
// intentionally blank.
|
||||
return NULL;
|
||||
// intentionally blank.
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@ -164,8 +164,8 @@ create_dsp(DSP_category) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool AudioManager::
|
||||
add_dsp(PT(AudioDSP) x) {
|
||||
// intentionally blank
|
||||
return false;
|
||||
// intentionally blank
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -175,8 +175,8 @@ add_dsp(PT(AudioDSP) x) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool AudioManager::
|
||||
remove_dsp(PT(AudioDSP) x) {
|
||||
// intentionally blank
|
||||
return false;
|
||||
// intentionally blank
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -187,8 +187,8 @@ remove_dsp(PT(AudioDSP) x) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
int AudioManager::
|
||||
getSpeakerSetup() {
|
||||
// intentionally blank
|
||||
return 0;
|
||||
// intentionally blank
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -198,21 +198,19 @@ getSpeakerSetup() {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void AudioManager::
|
||||
setSpeakerSetup(SPEAKERMODE_category cat) {
|
||||
// intentionally blank
|
||||
;
|
||||
// intentionally blank
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: AudioManager::audio_3d_update
|
||||
// Access: Public
|
||||
// Description:
|
||||
// Function: AudioManager::update()
|
||||
// Access: Published
|
||||
// Description: Must be called every frame. Failure to call this
|
||||
// every frame could cause problems for some audio
|
||||
// managers.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void AudioManager::audio_3d_update() {
|
||||
// intentionally blank.
|
||||
void AudioManager::
|
||||
update() {
|
||||
// Intentionally blank.
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
@ -163,18 +163,15 @@ PUBLISHED:
|
||||
// this call may be for efficient on some implementations.
|
||||
virtual void stop_all_sounds() = 0;
|
||||
|
||||
|
||||
// Changes to the positions of 3D spacialized sounds and the listener
|
||||
// are all made at once when this method is called. It should be put
|
||||
// in the main program loop.
|
||||
virtual void audio_3d_update();
|
||||
// This should be called every frame. Failure to call could
|
||||
// cause problems.
|
||||
virtual void update();
|
||||
|
||||
// This controls the "set of ears" that listens to 3D spacialized sound
|
||||
// px, py, pz are position coordinates.
|
||||
// vx, vy, vz are a velocity vector in UNITS PER SECOND (default: meters).
|
||||
// fx, fy and fz are the respective components of a unit forward-vector
|
||||
// ux, uy and uz are the respective components of a unit up-vector
|
||||
// These changes will NOT be invoked until audio_3d_update() is called.
|
||||
virtual void audio_3d_set_listener_attributes(float px, float py, float pz,
|
||||
float vx, float vy, float vz,
|
||||
float fx, float fy, float fz,
|
||||
|
@ -208,16 +208,6 @@ stop_all_sounds() {
|
||||
// intentionally blank.
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: NullAudioManager::audio_3d_update
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void NullAudioManager::
|
||||
audio_3d_update() {
|
||||
// intentionally blank.
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: NullAudioManager::audio_3d_set_listener_attributes
|
||||
// Access: Public
|
||||
|
@ -56,8 +56,6 @@ public:
|
||||
|
||||
virtual void stop_all_sounds();
|
||||
|
||||
virtual void audio_3d_update();
|
||||
|
||||
virtual void audio_3d_set_listener_attributes(float px, float py, float pz,
|
||||
float vx, float vy, float vz,
|
||||
float fx, float fy, float fz,
|
||||
|
@ -27,12 +27,13 @@
|
||||
|
||||
//Panda headers.
|
||||
#include "config_audio.h"
|
||||
#include "config_util.h"
|
||||
#include "fmodAudioManager.h"
|
||||
#include "fmodAudioSound.h"
|
||||
#include "fmodAudioDSP.h"
|
||||
//Needed so People use Panda's Generic UNIX Style Paths for Filename.
|
||||
#include "filename.h"
|
||||
|
||||
#include "virtualFileSystem.h"
|
||||
|
||||
//FMOD Headers.
|
||||
#include <fmod.hpp>
|
||||
@ -42,6 +43,7 @@
|
||||
|
||||
TypeHandle FmodAudioManager::_type_handle;
|
||||
|
||||
pset<FmodAudioManager *> FmodAudioManager::_all_managers;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Central dispatcher for audio errors.
|
||||
@ -49,7 +51,7 @@ TypeHandle FmodAudioManager::_type_handle;
|
||||
|
||||
static void fmod_audio_errcheck(FMOD_RESULT result) {
|
||||
if (result != 0) {
|
||||
audio_error("FMOD State: "<< result <<" "<< FMOD_ErrorString(result) );
|
||||
audio_error("FMOD Error: "<< FMOD_ErrorString(result) );
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,7 +61,6 @@ static void fmod_audio_errcheck(FMOD_RESULT result) {
|
||||
// Description: Factory Function
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PT(AudioManager) Create_AudioManager() {
|
||||
audio_debug("Create_AudioManager() Fmod.");
|
||||
return new FmodAudioManager;
|
||||
}
|
||||
|
||||
@ -71,15 +72,13 @@ PT(AudioManager) Create_AudioManager() {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
FmodAudioManager::
|
||||
FmodAudioManager() {
|
||||
|
||||
//OK Lets create the FMOD Audio Manager.
|
||||
audio_debug("FmodAudioManager::FmodAudioManager()");
|
||||
|
||||
FMOD_RESULT result;
|
||||
|
||||
//We need a varible temporary to check the FMOD Version.
|
||||
unsigned int version;
|
||||
|
||||
_all_managers.insert(this);
|
||||
|
||||
//Init 3D attributes
|
||||
_position.x = 0;
|
||||
_position.y = 0;
|
||||
@ -97,28 +96,18 @@ FmodAudioManager() {
|
||||
_up.y = 0;
|
||||
_up.z = 0;
|
||||
|
||||
|
||||
|
||||
audio_debug("FMOD::System_Create()");
|
||||
result = FMOD::System_Create(&_system);
|
||||
fmod_audio_errcheck(result);
|
||||
|
||||
// Let check the Version of FMOD to make sure the Headers and Libraries are correct.
|
||||
audio_debug("FMOD::System_Create()");
|
||||
result = _system->getVersion(&version);
|
||||
fmod_audio_errcheck(result);
|
||||
|
||||
audio_debug("FMOD VERSION:" << hex << version );
|
||||
audio_debug("FMOD - Getting Version");
|
||||
|
||||
|
||||
if (version < FMOD_VERSION){
|
||||
audio_debug("Error! You are using an old version of FMOD. This program requires:" << FMOD_VERSION);
|
||||
audio_error("You are using an old version of FMOD. This program requires:" << FMOD_VERSION);
|
||||
}
|
||||
|
||||
//Stick Surround Sound 5.1 thing Here.
|
||||
|
||||
audio_debug("Checking for Surround Sound Flag.");
|
||||
|
||||
if (fmod_use_surround_sound) {
|
||||
audio_debug("Setting FMOD to use 5.1 Surround Sound.");
|
||||
result = _system->setSpeakerMode( FMOD_SPEAKERMODE_5POINT1 );
|
||||
@ -126,16 +115,12 @@ FmodAudioManager() {
|
||||
}
|
||||
|
||||
//Now we Initialize the System.
|
||||
|
||||
audio_debug("FMOD::System_Init");
|
||||
result = _system->init(fmod_number_of_sound_channels, FMOD_INIT_NORMAL, 0);
|
||||
fmod_audio_errcheck(result);
|
||||
|
||||
if (result == FMOD_OK){
|
||||
audio_debug("FMOD Intialized OK, We are good to go Houston!");
|
||||
_is_valid = true;
|
||||
} else {
|
||||
audio_debug("Something is still wrong with FMOD! Check source.");
|
||||
_is_valid = false;
|
||||
}
|
||||
|
||||
@ -150,11 +135,8 @@ FmodAudioManager() {
|
||||
_distance_factor = 3.28;
|
||||
_drop_off_factor = 1;
|
||||
|
||||
audio_debug("Setting 3D Audio settings: Doppler Factor, Distance Factor, Drop Off Factor");
|
||||
|
||||
result = _system->set3DSettings( _doppler_factor, _distance_factor, _drop_off_factor);
|
||||
fmod_audio_errcheck( result );
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -165,8 +147,6 @@ FmodAudioManager() {
|
||||
FmodAudioManager::
|
||||
~FmodAudioManager() {
|
||||
// Be sure to delete associated sounds before deleting the manager!
|
||||
audio_debug("~FmodAudioManager(): Closing Down");
|
||||
|
||||
FMOD_RESULT result;
|
||||
|
||||
//Release DSPs First
|
||||
@ -175,14 +155,11 @@ FmodAudioManager::
|
||||
//Release Sounds Next
|
||||
_all_sounds.clear();
|
||||
|
||||
//result = _system->close();
|
||||
//fmod_audio_errcheck(result);
|
||||
// Remove me from the managers list.
|
||||
_all_managers.erase(this);
|
||||
|
||||
result = _system->release();
|
||||
result = _system->release();
|
||||
fmod_audio_errcheck(result);
|
||||
|
||||
audio_debug("~FmodAudioManager(): System Down.");
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -193,7 +170,6 @@ FmodAudioManager::
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool FmodAudioManager::
|
||||
is_valid() {
|
||||
audio_debug("FmodAudioManager::is_valid() = " << _is_valid );
|
||||
return _is_valid;
|
||||
}
|
||||
|
||||
@ -204,13 +180,14 @@ is_valid() {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PT(AudioSound) FmodAudioManager::
|
||||
get_sound(const string &file_name, bool positional) {
|
||||
|
||||
audio_debug("FmodAudioManager::get_sound(file_name=\""<<file_name<<"\")");
|
||||
|
||||
//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.
|
||||
|
||||
Filename path = file_name;
|
||||
|
||||
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
|
||||
vfs->resolve_filename(path, get_sound_path());
|
||||
|
||||
// Build a new AudioSound from the audio data.
|
||||
PT(AudioSound) audioSound = 0;
|
||||
PT(FmodAudioSound) fmodAudioSound = new FmodAudioSound(this, path.to_os_specific(), positional );
|
||||
@ -220,7 +197,6 @@ get_sound(const string &file_name, bool positional) {
|
||||
audioSound = fmodAudioSound;
|
||||
|
||||
return audioSound;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -231,8 +207,6 @@ get_sound(const string &file_name, bool positional) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PT(AudioDSP) FmodAudioManager::
|
||||
create_dsp(DSP_category index) {
|
||||
audio_debug("FmodAudioManager()::create_dsp");
|
||||
|
||||
// Build a new AudioSound from the audio data.
|
||||
PT(FmodAudioDSP) fmodAudioDSP = new FmodAudioDSP(this, index);
|
||||
|
||||
@ -249,8 +223,6 @@ create_dsp(DSP_category index) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool FmodAudioManager::
|
||||
add_dsp( PT(AudioDSP) x) {
|
||||
// intentionally blank
|
||||
|
||||
FMOD_RESULT result;
|
||||
|
||||
FmodAudioDSP *fdsp;
|
||||
@ -258,25 +230,14 @@ add_dsp( PT(AudioDSP) x) {
|
||||
DCAST_INTO_R(fdsp, x, false);
|
||||
|
||||
if ( fdsp->get_in_chain() ) {
|
||||
|
||||
audio_debug("FmodAudioManager()::add_dsp");
|
||||
audio_debug("This DSP has already been assigned to the system or a sound.");
|
||||
|
||||
return false;
|
||||
|
||||
} else
|
||||
{
|
||||
|
||||
} else {
|
||||
result = _system->addDSP( fdsp->_dsp );
|
||||
fmod_audio_errcheck( result );
|
||||
|
||||
_system_dsp.insert(fdsp);
|
||||
|
||||
fdsp->set_in_chain(true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -288,15 +249,12 @@ add_dsp( PT(AudioDSP) x) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool FmodAudioManager::
|
||||
remove_dsp(PT(AudioDSP) x) {
|
||||
// intentionally blank
|
||||
|
||||
FMOD_RESULT result;
|
||||
|
||||
FmodAudioDSP *fdsp;
|
||||
DCAST_INTO_R(fdsp, x, false);
|
||||
|
||||
if ( fdsp->get_in_chain() ) {
|
||||
|
||||
result = fdsp->_dsp->remove();
|
||||
fmod_audio_errcheck( result );
|
||||
|
||||
@ -305,17 +263,9 @@ remove_dsp(PT(AudioDSP) x) {
|
||||
fdsp->set_in_chain(false);
|
||||
|
||||
return true;
|
||||
|
||||
} else
|
||||
{
|
||||
|
||||
audio_debug("FmodAudioManager()::remove_dsp()");
|
||||
audio_debug("This DSP doesn't exist in this chain.");
|
||||
|
||||
} else {
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -326,8 +276,6 @@ remove_dsp(PT(AudioDSP) x) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
int FmodAudioManager::
|
||||
getSpeakerSetup() {
|
||||
// intentionally blank
|
||||
|
||||
FMOD_RESULT result;
|
||||
FMOD_SPEAKERMODE speakerMode;
|
||||
int returnMode;
|
||||
@ -392,10 +340,6 @@ getSpeakerSetup() {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FmodAudioManager::
|
||||
setSpeakerSetup(AudioManager::SPEAKERMODE_category cat) {
|
||||
// intentionally blank
|
||||
|
||||
audio_debug("FmodAudioSound::setSpeakerSetup() " );
|
||||
|
||||
//Local Variables that are needed.
|
||||
FMOD_RESULT result;
|
||||
|
||||
@ -403,9 +347,6 @@ setSpeakerSetup(AudioManager::SPEAKERMODE_category cat) {
|
||||
|
||||
result = _system->setSpeakerMode( speakerModeType);
|
||||
fmod_audio_errcheck(result);
|
||||
|
||||
audio_debug("Speaker Mode Set");
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -416,8 +357,7 @@ setSpeakerSetup(AudioManager::SPEAKERMODE_category cat) {
|
||||
// so this function is moot now.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FmodAudioManager::set_volume(float volume) {
|
||||
audio_debug("FmodAudioManager::set_volume()" );
|
||||
audio_debug("This function has no effect in this version." );
|
||||
audio_warning("FmodAudioManager::set_volume has no effect." );
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -429,20 +369,19 @@ void FmodAudioManager::set_volume(float volume) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
float FmodAudioManager::
|
||||
get_volume() const {
|
||||
audio_debug("FmodAudioManager::get_volume() returning ");
|
||||
audio_debug("This function has no effect in this version." );
|
||||
return 0;
|
||||
audio_warning("FmodAudioManager::get_volume has no effect." );
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FmodAudioManager::set_active(bool active)
|
||||
// Access: Public
|
||||
// Description: Turn on/off
|
||||
// Again, this function is pretty much moot in this version now.
|
||||
// Warning: not implemented.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FmodAudioManager::
|
||||
set_active(bool active) {
|
||||
audio_debug("FmodAudioManager::set_active(flag="<<active<<")");
|
||||
_active = active;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -452,7 +391,6 @@ set_active(bool active) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool FmodAudioManager::
|
||||
get_active() const {
|
||||
audio_debug("FmodAudioManager::get_active() returning "<<_active);
|
||||
return _active;
|
||||
}
|
||||
|
||||
@ -463,27 +401,19 @@ get_active() const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FmodAudioManager::
|
||||
stop_all_sounds() {
|
||||
audio_debug("FmodAudioManager::stop_all_sounds()" );
|
||||
|
||||
for (SoundSet::iterator i = _all_sounds.begin(); i != _all_sounds.end(); ++i) {
|
||||
(*i)->stop();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FmodAudioManager::audio_3d_update
|
||||
// Function: FmodAudioManager::update
|
||||
// Access: Public
|
||||
// Description: Commit position changes to listener and all
|
||||
// positioned sounds. Normally, you'd want to call this
|
||||
// once per iteration of your main loop.
|
||||
// Description: Perform all per-frame update functions.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FmodAudioManager::
|
||||
audio_3d_update() {
|
||||
audio_debug("FmodAudioManager::audio_3d_update()");
|
||||
audio_debug("Calling FMOD's update function");
|
||||
|
||||
update() {
|
||||
_system->update();
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
@ -85,154 +85,138 @@ class FmodAudioDSP;
|
||||
extern void fmod_audio_errcheck(FMOD_RESULT n);
|
||||
|
||||
class EXPCL_FMOD_AUDIO FmodAudioManager : public AudioManager {
|
||||
friend class FmodAudioSound;
|
||||
friend class FmodAudioDSP;
|
||||
friend class FmodAudioSound;
|
||||
friend class FmodAudioDSP;
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
//Constructor and Destructor
|
||||
FmodAudioManager();
|
||||
virtual ~FmodAudioManager();
|
||||
//Constructor and Destructor
|
||||
FmodAudioManager();
|
||||
virtual ~FmodAudioManager();
|
||||
|
||||
virtual bool is_valid();
|
||||
virtual bool is_valid();
|
||||
|
||||
virtual PT(AudioSound) get_sound(const string&, bool positional = false);
|
||||
virtual PT(AudioSound) get_sound(const string&, bool positional = false);
|
||||
|
||||
virtual PT(AudioDSP) create_dsp(DSP_category);
|
||||
virtual bool add_dsp(PT(AudioDSP) dspToAdd);
|
||||
virtual bool remove_dsp(PT(AudioDSP) x);
|
||||
virtual PT(AudioDSP) create_dsp(DSP_category);
|
||||
virtual bool add_dsp(PT(AudioDSP) dspToAdd);
|
||||
virtual bool remove_dsp(PT(AudioDSP) x);
|
||||
|
||||
virtual int getSpeakerSetup();
|
||||
virtual void setSpeakerSetup(SPEAKERMODE_category cat);
|
||||
virtual int getSpeakerSetup();
|
||||
virtual void setSpeakerSetup(SPEAKERMODE_category cat);
|
||||
|
||||
virtual void set_volume(float);
|
||||
virtual float get_volume() const;
|
||||
virtual void set_volume(float);
|
||||
virtual float get_volume() const;
|
||||
|
||||
virtual void set_active(bool);
|
||||
virtual bool get_active() const;
|
||||
virtual void set_active(bool);
|
||||
virtual bool get_active() const;
|
||||
|
||||
virtual void stop_all_sounds();
|
||||
virtual void stop_all_sounds();
|
||||
|
||||
// Changes to the positions of 3D spacialized sounds and the listener
|
||||
// are all made at once when this method is called. It should be put
|
||||
// in the main program loop.
|
||||
virtual void audio_3d_update();
|
||||
virtual void update();
|
||||
|
||||
// This controls the "set of ears" that listens to 3D spacialized sound
|
||||
// px, py, pz are position coordinates. Can be 0.0f to ignore.
|
||||
// vx, vy, vz are a velocity vector in UNITS PER SECOND (default: meters).
|
||||
// fx, fy and fz are the respective components of a unit forward-vector
|
||||
// ux, uy and uz are the respective components of a unit up-vector
|
||||
// These changes will NOT be invoked until audio_3d_update() is called.
|
||||
virtual void audio_3d_set_listener_attributes(float px, float py, float pz,
|
||||
float vx, float xy, float xz,
|
||||
float fx, float fy, float fz,
|
||||
float ux, float uy, float uz);
|
||||
|
||||
// This controls the "set of ears" that listens to 3D spacialized sound
|
||||
// px, py, pz are position coordinates. Can be 0.0f to ignore.
|
||||
// vx, vy, vz are a velocity vector in UNITS PER SECOND (default: meters).
|
||||
// fx, fy and fz are the respective components of a unit forward-vector
|
||||
// ux, uy and uz are the respective components of a unit up-vector
|
||||
// These changes will NOT be invoked until audio_3d_update() is called.
|
||||
virtual void audio_3d_set_listener_attributes(float px, float py, float pz,
|
||||
float vx, float xy, float xz,
|
||||
float fx, float fy, float fz,
|
||||
float ux, float uy, float uz);
|
||||
|
||||
// REMOVE THIS ONE
|
||||
virtual void audio_3d_get_listener_attributes(float *px, float *py, float *pz,
|
||||
float *vx, float *vy, float *vz,
|
||||
float *fx, float *fy, float *fz,
|
||||
float *ux, float *uy, float *uz);
|
||||
// REMOVE THIS ONE
|
||||
virtual void audio_3d_get_listener_attributes(float *px, float *py, float *pz,
|
||||
float *vx, float *vy, float *vz,
|
||||
float *fx, float *fy, float *fz,
|
||||
float *ux, float *uy, float *uz);
|
||||
|
||||
// Control the "relative distance factor" for 3D spacialized audio. Default is 1.0
|
||||
// Fmod uses meters internally, so give a float in Units-per meter
|
||||
// Don't know what Miles uses.
|
||||
virtual void audio_3d_set_distance_factor(float factor);
|
||||
virtual float audio_3d_get_distance_factor() const;
|
||||
// Control the "relative distance factor" for 3D spacialized audio. Default is 1.0
|
||||
// Fmod uses meters internally, so give a float in Units-per meter
|
||||
// Don't know what Miles uses.
|
||||
virtual void audio_3d_set_distance_factor(float factor);
|
||||
virtual float audio_3d_get_distance_factor() const;
|
||||
|
||||
// Control the presence of the Doppler effect. Default is 1.0
|
||||
// Exaggerated Doppler, use >1.0
|
||||
// Diminshed Doppler, use <1.0
|
||||
virtual void audio_3d_set_doppler_factor(float factor);
|
||||
virtual float audio_3d_get_doppler_factor() const;
|
||||
// Control the presence of the Doppler effect. Default is 1.0
|
||||
// Exaggerated Doppler, use >1.0
|
||||
// Diminshed Doppler, use <1.0
|
||||
virtual void audio_3d_set_doppler_factor(float factor);
|
||||
virtual float audio_3d_get_doppler_factor() const;
|
||||
|
||||
// Exaggerate or diminish the effect of distance on sound. Default is 1.0
|
||||
// Faster drop off, use >1.0
|
||||
// Slower drop off, use <1.0
|
||||
virtual void audio_3d_set_drop_off_factor(float factor);
|
||||
virtual float audio_3d_get_drop_off_factor() const;
|
||||
// Exaggerate or diminish the effect of distance on sound. Default is 1.0
|
||||
// Faster drop off, use >1.0
|
||||
// Slower drop off, use <1.0
|
||||
virtual void audio_3d_set_drop_off_factor(float factor);
|
||||
virtual float audio_3d_get_drop_off_factor() const;
|
||||
|
||||
//THESE ARE NOT USED ANYMORE.
|
||||
//THEY ARE ONLY HERE BECAUSE THEY are still needed by Miles.
|
||||
//THESE are stubs in FMOD-EX version
|
||||
////////////////////////////////////////////////////////////////////
|
||||
virtual void set_concurrent_sound_limit(unsigned int limit = 0);
|
||||
virtual unsigned int get_concurrent_sound_limit() const;
|
||||
virtual void reduce_sounds_playing_to(unsigned int count);
|
||||
virtual void uncache_sound(const string&);
|
||||
virtual void clear_cache();
|
||||
virtual void set_cache_limit(unsigned int count);
|
||||
virtual unsigned int get_cache_limit() const;
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//THESE ARE NOT USED ANYMORE.
|
||||
//THEY ARE ONLY HERE BECAUSE THEY are still needed by Miles.
|
||||
//THESE are stubs in FMOD-EX version
|
||||
////////////////////////////////////////////////////////////////////
|
||||
virtual void set_concurrent_sound_limit(unsigned int limit = 0);
|
||||
virtual unsigned int get_concurrent_sound_limit() const;
|
||||
virtual void reduce_sounds_playing_to(unsigned int count);
|
||||
virtual void uncache_sound(const string&);
|
||||
virtual void clear_cache();
|
||||
virtual void set_cache_limit(unsigned int count);
|
||||
virtual unsigned int get_cache_limit() const;
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
protected:
|
||||
private:
|
||||
|
||||
// This is the main FMOD system varible. Without it you got nothing.
|
||||
FMOD::System *_system;
|
||||
FMOD::System *_system;
|
||||
|
||||
static pset<FmodAudioManager *> _all_managers;
|
||||
|
||||
private:
|
||||
FMOD_VECTOR _position;
|
||||
FMOD_VECTOR _velocity;
|
||||
FMOD_VECTOR _forward;
|
||||
FMOD_VECTOR _up;
|
||||
|
||||
// This varible is something to receive the FMOD_RESULTs which we use to check
|
||||
// FMOD's State
|
||||
FMOD_VECTOR _position;
|
||||
FMOD_VECTOR _velocity;
|
||||
FMOD_VECTOR _forward;
|
||||
FMOD_VECTOR _up;
|
||||
bool _is_valid;
|
||||
bool _active;
|
||||
|
||||
float _distance_factor;
|
||||
float _doppler_factor;
|
||||
float _drop_off_factor;
|
||||
|
||||
bool _is_valid;
|
||||
bool _active;
|
||||
// The set of all sounds. Needed only to implement stop_all_sounds.
|
||||
typedef pset<FmodAudioSound *> SoundSet;
|
||||
SoundSet _all_sounds;
|
||||
|
||||
float _distance_factor;
|
||||
float _doppler_factor;
|
||||
float _drop_off_factor;
|
||||
// The Data Structure that holds all the DSPs.
|
||||
typedef pset<PT (FmodAudioDSP) > DSPSet;
|
||||
DSPSet _system_dsp;
|
||||
|
||||
//The Data Structure that holds all the sounds.
|
||||
//BTW. Notice that this IS NOT A PT Structure.
|
||||
//It probably should never bee either.
|
||||
//We tried it as a PT, and you run into a problem with
|
||||
//PANDA's garbage collection system, when you finally get around
|
||||
//to destroying the sounds.
|
||||
//So you are probably wondering why we even need a set like the one below by now.
|
||||
//Mainly becuase we need something for the 'stop_all_sounds()' function.
|
||||
//Which does just take it stop all the sounds at once [and believe it is needed at times.]
|
||||
typedef pset<FmodAudioSound *> SoundSet;
|
||||
SoundSet _all_sounds;
|
||||
friend class FmodAudioSound;
|
||||
|
||||
//The Data Structure that holds all the DSPs.
|
||||
typedef pset<PT (FmodAudioDSP) > DSPSet;
|
||||
DSPSet _system_dsp;
|
||||
////////////////////////////////////////////////////////////
|
||||
//These are needed for Panda's Pointer System. DO NOT ERASE!
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
friend class FmodAudioSound;
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type() {
|
||||
AudioManager::init_type();
|
||||
register_type(_type_handle, "FmodAudioManager", AudioManager::get_class_type());
|
||||
}
|
||||
virtual TypeHandle get_type() const {
|
||||
return get_class_type();
|
||||
}
|
||||
virtual TypeHandle force_init_type() {
|
||||
init_type();
|
||||
return get_class_type();
|
||||
}
|
||||
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//These are needed for Panda's Pointer System. DO NOT ERASE!
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type() {
|
||||
AudioManager::init_type();
|
||||
register_type(_type_handle, "FmodAudioManager", AudioManager::get_class_type());
|
||||
}
|
||||
virtual TypeHandle get_type() const {
|
||||
return get_class_type();
|
||||
}
|
||||
virtual TypeHandle force_init_type() {
|
||||
init_type();
|
||||
return get_class_type();
|
||||
}
|
||||
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//DONE
|
||||
////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////
|
||||
//DONE
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
};
|
||||
|
||||
|
@ -81,37 +81,31 @@ FmodAudioSound(AudioManager *manager, string file_name, bool positional) {
|
||||
result = _manager->_system->getSpeakerMode( &_speakermode );
|
||||
fmod_audio_errcheck(result);
|
||||
|
||||
if (positional == true) {
|
||||
|
||||
result = _manager->_system->createSound( file_name.c_str(), FMOD_SOFTWARE | FMOD_3D , 0, &_sound);
|
||||
int flag = positional ? FMOD_3D : FMOD_2D;
|
||||
|
||||
result = _manager->_system->createSound( file_name.c_str(), FMOD_SOFTWARE | flag , 0, &_sound);
|
||||
if (result != FMOD_OK) {
|
||||
char blank_data[100];
|
||||
FMOD_CREATESOUNDEXINFO exinfo;
|
||||
audio_error("CreateSound " << file_name << ": " << FMOD_ErrorString(result));
|
||||
memset(&exinfo, 0, sizeof(exinfo));
|
||||
memset(blank_data, 0, sizeof(blank_data));
|
||||
exinfo.cbsize = sizeof(exinfo);
|
||||
exinfo.length = sizeof(blank_data);
|
||||
exinfo.numchannels = 1;
|
||||
exinfo.defaultfrequency = 8000;
|
||||
exinfo.format = FMOD_SOUND_FORMAT_PCM16;
|
||||
result = _manager->_system->createSound( blank_data, FMOD_SOFTWARE | flag | FMOD_OPENMEMORY | FMOD_OPENRAW, &exinfo, &_sound);
|
||||
fmod_audio_errcheck(result);
|
||||
|
||||
//This is just to collect the defaults of the sound, so we don't
|
||||
//Have to query FMOD everytime for the info.
|
||||
//It is also important we get the '_sampleFrequency' variable here, for the
|
||||
//'set_play_rate()' and 'get_play_rate()' methods later;
|
||||
|
||||
result = _sound->getDefaults( &_sampleFrequency, &_volume , &_balance, &_priority);
|
||||
fmod_audio_errcheck(result);
|
||||
|
||||
audio_debug("Sound loaded as 3D");
|
||||
|
||||
} else {
|
||||
|
||||
result = _manager->_system->createSound( file_name.c_str(), FMOD_SOFTWARE | FMOD_2D , 0, &_sound);
|
||||
fmod_audio_errcheck(result);
|
||||
|
||||
//This is just to collect the defaults of the sound, so we don't
|
||||
//Have to query FMOD everytime for the info.
|
||||
//It is also important we get the '_sampleFrequency' variable here, for the
|
||||
//'set_play_rate()' and 'get_play_rate()' methods later;
|
||||
|
||||
result = _sound->getDefaults( &_sampleFrequency, &_volume , &_balance, &_priority);
|
||||
fmod_audio_errcheck(result);
|
||||
|
||||
audio_debug("Sound loaded as 2D");
|
||||
|
||||
}
|
||||
|
||||
//This is just to collect the defaults of the sound, so we don't
|
||||
//Have to query FMOD everytime for the info.
|
||||
//It is also important we get the '_sampleFrequency' variable here, for the
|
||||
//'set_play_rate()' and 'get_play_rate()' methods later;
|
||||
|
||||
result = _sound->getDefaults( &_sampleFrequency, &_volume , &_balance, &_priority);
|
||||
fmod_audio_errcheck(result);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user