Fixes to fmod and scene editor

This commit is contained in:
Josh Yelon 2006-09-26 17:24:35 +00:00
parent 4009f3fd9e
commit 68c918864f
10 changed files with 337 additions and 462 deletions

View File

@ -11,6 +11,7 @@ from direct.tkwidgets import Floater
from direct.tkwidgets import Slider from direct.tkwidgets import Slider
from Tkinter import * from Tkinter import *
import string, math, types import string, math, types
from pandac.PandaModules import *
class collisionWindow(AppShell): class collisionWindow(AppShell):

View File

@ -9,7 +9,7 @@ from direct.tkwidgets.VectorWidgets import Vector3Entry
from direct.tkwidgets.Slider import Slider from direct.tkwidgets.Slider import Slider
from Tkinter import Frame, Button, Menubutton, Menu from Tkinter import Frame, Button, Menubutton, Menu
import string, math, types, Pmw, Tkinter import string, math, types, Pmw, Tkinter
from pandac.PandaModules import *
class lightingPanel(AppShell): class lightingPanel(AppShell):
################################################################# #################################################################

View File

@ -18,6 +18,7 @@ from direct.tkwidgets.AppShell import AppShell
#from direct.directtools.DirectUtil import * #from direct.directtools.DirectUtil import *
from seGeometry import * from seGeometry import *
from seSelection import * from seSelection import *
from direct.task.Task import Task
from direct.tkwidgets.Dial import AngleDial from direct.tkwidgets.Dial import AngleDial
from direct.tkwidgets.Floater import Floater from direct.tkwidgets.Floater import Floater
from direct.tkwidgets.Slider import Slider from direct.tkwidgets.Slider import Slider

View File

@ -80,7 +80,6 @@ PUBLISHED:
virtual bool add_dsp(PT(AudioDSP) x); virtual bool add_dsp(PT(AudioDSP) x);
virtual bool remove_dsp(PT(AudioDSP) x); virtual bool remove_dsp(PT(AudioDSP) x);
virtual int getSpeakerSetup(); virtual int getSpeakerSetup();
virtual void setSpeakerSetup(SPEAKERMODE_category cat); virtual void setSpeakerSetup(SPEAKERMODE_category cat);

View File

@ -51,7 +51,7 @@ FmodAudioDSP(AudioManager *manager, AudioManager::DSP_category cat) {
FMOD_DSP_TYPE dsptype = (FMOD_DSP_TYPE)cat; FMOD_DSP_TYPE dsptype = (FMOD_DSP_TYPE)cat;
result = _manager->_system->createDSPByType( dsptype, &_dsp); result = _manager->_system->createDSPByType( dsptype, &_dsp);
ERRCHECK(result); fmod_audio_errcheck(result);
set_in_chain(false); set_in_chain(false);
@ -74,10 +74,10 @@ FmodAudioDSP::
FMOD_RESULT result; FMOD_RESULT result;
result = _dsp->remove(); result = _dsp->remove();
ERRCHECK(result); fmod_audio_errcheck(result);
result = _dsp->release(); result = _dsp->release();
ERRCHECK(result); fmod_audio_errcheck(result);
audio_debug("DSP GONE"); audio_debug("DSP GONE");
} }
@ -98,7 +98,7 @@ reset() {
FMOD_RESULT result; FMOD_RESULT result;
result = _dsp->reset(); result = _dsp->reset();
ERRCHECK(result); fmod_audio_errcheck(result);
audio_debug("DSP Reset."); audio_debug("DSP Reset.");
} }
@ -118,7 +118,7 @@ remove() {
FMOD_RESULT result; FMOD_RESULT result;
result = _dsp->remove(); result = _dsp->remove();
ERRCHECK(result); fmod_audio_errcheck(result);
audio_debug("DSP Removed from relative effects chain."); audio_debug("DSP Removed from relative effects chain.");
} }
@ -138,7 +138,7 @@ set_bypass(bool bypass) {
FMOD_RESULT result; FMOD_RESULT result;
result = _dsp->setBypass(bypass); result = _dsp->setBypass(bypass);
ERRCHECK(result); fmod_audio_errcheck(result);
audio_debug("DSP Bypass set to:" << bypass ); audio_debug("DSP Bypass set to:" << bypass );
} }
@ -159,7 +159,7 @@ get_bypass() {
bool bypass; bool bypass;
result = _dsp->getBypass(&bypass); result = _dsp->getBypass(&bypass);
ERRCHECK(result); fmod_audio_errcheck(result);
return bypass; return bypass;
} }
@ -183,7 +183,7 @@ set_parameter(const string &name, float value) {
FMOD_RESULT result; FMOD_RESULT result;
result = _dsp->setParameter(parameterIndex, value); result = _dsp->setParameter(parameterIndex, value);
ERRCHECK(result); fmod_audio_errcheck(result);
} }
@ -203,7 +203,7 @@ get_num_parameters() {
int numOfParameters; int numOfParameters;
result = _dsp->getNumParameters(&numOfParameters); result = _dsp->getNumParameters(&numOfParameters);
ERRCHECK(result); fmod_audio_errcheck(result);
return numOfParameters; return numOfParameters;
} }
@ -231,7 +231,7 @@ get_parameter_name(int parameterIndex) {
float parameterMax; float parameterMax;
result = _dsp->getParameterInfo(parameterIndex, parameterName, parameterLabel, parameterDescription, parameterDescriptionLength, &parameterMin, &parameterMax); result = _dsp->getParameterInfo(parameterIndex, parameterName, parameterLabel, parameterDescription, parameterDescriptionLength, &parameterMin, &parameterMax);
ERRCHECK(result); fmod_audio_errcheck(result);
string returnInfo = (parameterName); string returnInfo = (parameterName);
@ -275,7 +275,7 @@ get_parameter_description(int parameterIndex) {
float parameterMax; float parameterMax;
result = _dsp->getParameterInfo(parameterIndex, parameterName, parameterLabel, parameterDescription, parameterDescriptionLength, &parameterMin, &parameterMax); result = _dsp->getParameterInfo(parameterIndex, parameterName, parameterLabel, parameterDescription, parameterDescriptionLength, &parameterMin, &parameterMax);
ERRCHECK(result); fmod_audio_errcheck(result);
return parameterLabel; return parameterLabel;
@ -304,7 +304,7 @@ get_parameter_min(int parameterIndex) {
float parameterMax; float parameterMax;
result = _dsp->getParameterInfo(parameterIndex, parameterName, parameterLabel, parameterDescription, parameterDescriptionLength, &parameterMin, &parameterMax); result = _dsp->getParameterInfo(parameterIndex, parameterName, parameterLabel, parameterDescription, parameterDescriptionLength, &parameterMin, &parameterMax);
ERRCHECK(result); fmod_audio_errcheck(result);
return parameterMin; return parameterMin;
} }
@ -332,7 +332,7 @@ get_parameter_max(int parameterIndex) {
float parameterMax; float parameterMax;
result = _dsp->getParameterInfo(parameterIndex, parameterName, parameterLabel, parameterDescription, parameterDescriptionLength, &parameterMin, &parameterMax); result = _dsp->getParameterInfo(parameterIndex, parameterName, parameterLabel, parameterDescription, parameterDescriptionLength, &parameterMin, &parameterMax);
ERRCHECK(result); fmod_audio_errcheck(result);
return parameterMax; return parameterMax;
} }
@ -361,7 +361,7 @@ get_parameter_value(const string &name) {
result = _dsp->getParameter(parameterIndex, &parameterValue, valuestr, valuestrlen); result = _dsp->getParameter(parameterIndex, &parameterValue, valuestr, valuestrlen);
ERRCHECK(result); fmod_audio_errcheck(result);
return parameterValue; return parameterValue;
} }
@ -404,7 +404,7 @@ get_dsp_name() {
int configheight; int configheight;
result = _dsp->getInfo(name, &version, &channels, &configwidth, &configheight); result = _dsp->getInfo(name, &version, &channels, &configwidth, &configheight);
ERRCHECK(result); fmod_audio_errcheck(result);
string returnInfo = (name); string returnInfo = (name);
//returnInfo.append(" Version: "); //returnInfo.append(" Version: ");

View File

@ -27,7 +27,7 @@
// //
//Currently FmodAudioDSP give you access to all of FMODs built in DSP functions. //Currently FmodAudioDSP give you access to all of FMODs built in DSP functions.
// //
//The enumerated list for the types are found in the AudioManager.h, but I will //The enumerated list for the types are found in the 'AudioManager.h, but I will
//repeat it here for good fortune. //repeat it here for good fortune.
// //
// enum DSP_category { // enum DSP_category {
@ -54,10 +54,10 @@
// }; // };
// //
//Now, I want to point a couple things out. First, we have to place the above list //Now, I want to point a couple things out. First, we have to place the above list
//in AudioManager.h because that was the only way to them to be PUBLISHED in //in AudioManager.h because that was the only way to them to be 'PUBLISHED in
//Pandas Python bindings when you build Panda. //Pandas Python bindings when you build Panda.
// //
//Second, you only need to use the it#### named DSP effects if you are using //Second, you only need to use the 'it#### named DSP effects if you are using
//mod/tracker files. [If you dont know what a mod/tracker file is you probably //mod/tracker files. [If you dont know what a mod/tracker file is you probably
//arent using them so dont worry about it.] //arent using them so dont worry about it.]
// //

View File

@ -39,32 +39,25 @@
#include <fmod_errors.h> #include <fmod_errors.h>
////////////////////////////////////////////////////////////////////
// This in needed for Panda's Pointer System
// DO NOT ERASE!
////////////////////////////////////////////////////////////////////
TypeHandle FmodAudioManager::_type_handle; TypeHandle FmodAudioManager::_type_handle;
////////////////////////////////////////////////////////////////////
// END OF POINTER THING
////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// OK I am not sure if there is the best place for this one, // Central dispatcher for audio errors.
// but it seems to work. IE, the FmodSound and FmodDSP classes can find it. ////////////////////////////////////////////////////////////////////
// All FMOD API calls return a success or failure error.
// [I am sure there is a name for this type of programming but I don't know it.] static void fmod_audio_errcheck(FMOD_RESULT result) {
// Anyway, by adding the line "notify-level-audio debug" to the config.prc file if (result != 0) {
// of Panda, of the config.in file of MAKEPANDA, you can see the Debugs printed out at the audio_error("FMOD State: "<< result <<" "<< FMOD_ErrorString(result) );
// Python Prompt }
/////////////////////////////////////////////////////////////////////
void ERRCHECK(FMOD_RESULT result){
audio_debug("FMOD State: "<< result <<" "<< FMOD_ErrorString(result) );
} }
////////////////////////////////////////////////////////////////////
// Function: Create_AudioManager
// Access: Private
// Description: Factory Function
////////////////////////////////////////////////////////////////////
PT(AudioManager) Create_AudioManager() { PT(AudioManager) Create_AudioManager() {
audio_debug("Create_AudioManager() Fmod."); audio_debug("Create_AudioManager() Fmod.");
return new FmodAudioManager; return new FmodAudioManager;
@ -108,12 +101,12 @@ FmodAudioManager() {
audio_debug("FMOD::System_Create()"); audio_debug("FMOD::System_Create()");
result = FMOD::System_Create(&_system); result = FMOD::System_Create(&_system);
ERRCHECK(result); fmod_audio_errcheck(result);
// Let check the Version of FMOD to make sure the Headers and Libraries are correct. // Let check the Version of FMOD to make sure the Headers and Libraries are correct.
audio_debug("FMOD::System_Create()"); audio_debug("FMOD::System_Create()");
result = _system->getVersion(&version); result = _system->getVersion(&version);
ERRCHECK(result); fmod_audio_errcheck(result);
audio_debug("FMOD VERSION:" << hex << version ); audio_debug("FMOD VERSION:" << hex << version );
audio_debug("FMOD - Getting Version"); audio_debug("FMOD - Getting Version");
@ -129,14 +122,14 @@ FmodAudioManager() {
if (fmod_use_surround_sound) { if (fmod_use_surround_sound) {
audio_debug("Setting FMOD to use 5.1 Surround Sound."); audio_debug("Setting FMOD to use 5.1 Surround Sound.");
result = _system->setSpeakerMode( FMOD_SPEAKERMODE_5POINT1 ); result = _system->setSpeakerMode( FMOD_SPEAKERMODE_5POINT1 );
ERRCHECK(result); fmod_audio_errcheck(result);
} }
//Now we Initialize the System. //Now we Initialize the System.
audio_debug("FMOD::System_Init"); audio_debug("FMOD::System_Init");
result = _system->init(fmod_number_of_sound_channels, FMOD_INIT_NORMAL, 0); result = _system->init(fmod_number_of_sound_channels, FMOD_INIT_NORMAL, 0);
ERRCHECK(result); fmod_audio_errcheck(result);
if (result == FMOD_OK){ if (result == FMOD_OK){
audio_debug("FMOD Intialized OK, We are good to go Houston!"); audio_debug("FMOD Intialized OK, We are good to go Houston!");
@ -160,7 +153,7 @@ FmodAudioManager() {
audio_debug("Setting 3D Audio settings: Doppler Factor, Distance Factor, Drop Off Factor"); audio_debug("Setting 3D Audio settings: Doppler Factor, Distance Factor, Drop Off Factor");
result = _system->set3DSettings( _doppler_factor, _distance_factor, _drop_off_factor); result = _system->set3DSettings( _doppler_factor, _distance_factor, _drop_off_factor);
ERRCHECK( result ); fmod_audio_errcheck( result );
} }
@ -183,10 +176,10 @@ FmodAudioManager::
_all_sounds.clear(); _all_sounds.clear();
//result = _system->close(); //result = _system->close();
//ERRCHECK(result); //fmod_audio_errcheck(result);
result = _system->release(); result = _system->release();
ERRCHECK(result); fmod_audio_errcheck(result);
audio_debug("~FmodAudioManager(): System Down."); audio_debug("~FmodAudioManager(): System Down.");
@ -275,7 +268,7 @@ add_dsp( PT(AudioDSP) x) {
{ {
result = _system->addDSP( fdsp->_dsp ); result = _system->addDSP( fdsp->_dsp );
ERRCHECK( result ); fmod_audio_errcheck( result );
_system_dsp.insert(fdsp); _system_dsp.insert(fdsp);
@ -305,7 +298,7 @@ remove_dsp(PT(AudioDSP) x) {
if ( fdsp->get_in_chain() ) { if ( fdsp->get_in_chain() ) {
result = fdsp->_dsp->remove(); result = fdsp->_dsp->remove();
ERRCHECK( result ); fmod_audio_errcheck( result );
_system_dsp.erase(fdsp); _system_dsp.erase(fdsp);
@ -340,7 +333,7 @@ getSpeakerSetup() {
int returnMode; int returnMode;
result = _system->getSpeakerMode( &speakerMode ); result = _system->getSpeakerMode( &speakerMode );
ERRCHECK( result ); fmod_audio_errcheck( result );
switch (speakerMode) { switch (speakerMode) {
case FMOD_SPEAKERMODE_RAW: case FMOD_SPEAKERMODE_RAW:
@ -409,7 +402,7 @@ setSpeakerSetup(AudioManager::SPEAKERMODE_category cat) {
FMOD_SPEAKERMODE speakerModeType = (FMOD_SPEAKERMODE)cat; FMOD_SPEAKERMODE speakerModeType = (FMOD_SPEAKERMODE)cat;
result = _system->setSpeakerMode( speakerModeType); result = _system->setSpeakerMode( speakerModeType);
ERRCHECK(result); fmod_audio_errcheck(result);
audio_debug("Speaker Mode Set"); audio_debug("Speaker Mode Set");
@ -531,7 +524,7 @@ audio_3d_set_listener_attributes(float px, float py, float pz, float vx, float v
_up.z = uy; _up.z = uy;
result = _system->set3DListenerAttributes( 0, &_position, &_velocity, &_forward, &_up); result = _system->set3DListenerAttributes( 0, &_position, &_velocity, &_forward, &_up);
ERRCHECK( result ); fmod_audio_errcheck( result );
} }
@ -562,7 +555,7 @@ audio_3d_set_distance_factor(float factor) {
_distance_factor = factor; _distance_factor = factor;
result = _system->set3DSettings( _doppler_factor, _distance_factor, _drop_off_factor); result = _system->set3DSettings( _doppler_factor, _distance_factor, _drop_off_factor);
ERRCHECK( result ); fmod_audio_errcheck( result );
} }
@ -595,7 +588,7 @@ audio_3d_set_doppler_factor(float factor) {
_doppler_factor = factor; _doppler_factor = factor;
result = _system->set3DSettings( _doppler_factor, _distance_factor, _drop_off_factor); result = _system->set3DSettings( _doppler_factor, _distance_factor, _drop_off_factor);
ERRCHECK( result ); fmod_audio_errcheck( result );
} }
@ -626,7 +619,7 @@ audio_3d_set_drop_off_factor(float factor) {
_drop_off_factor = factor; _drop_off_factor = factor;
result = _system->set3DSettings( _doppler_factor, _distance_factor, _drop_off_factor); result = _system->set3DSettings( _doppler_factor, _distance_factor, _drop_off_factor);
ERRCHECK( result ); fmod_audio_errcheck( result );
} }

View File

@ -82,22 +82,9 @@
class FmodAudioSound; class FmodAudioSound;
class FmodAudioDSP; class FmodAudioDSP;
//////////////////////////////////////////////////////////////////// extern void fmod_audio_errcheck(FMOD_RESULT n);
// OK I am not sure if there is the best place for this one,
// but it seems to work. IE, the FmodSound and FmodDSP classes can find it.
// All FMOD API calls return a success or failure error.
// [I am sure there is a name for this type of programming but I don't know it.]
// Anyway, by adding the line "notify-level-audio debug" to the config.prc file
// of Panda, of the config.in file of MAKEPANDA, you can see the Debugs printed out at the
// Python Prompt
/////////////////////////////////////////////////////////////////////
void ERRCHECK(FMOD_RESULT result);
class EXPCL_FMOD_AUDIO FmodAudioManager : public AudioManager { class EXPCL_FMOD_AUDIO FmodAudioManager : public AudioManager {
// All of these methods are stubbed out to some degree.
// If you're looking for a starting place for a new AudioManager,
// please consider looking at the milesAudioManager.
friend class FmodAudioSound; friend class FmodAudioSound;
friend class FmodAudioDSP; friend class FmodAudioDSP;
@ -251,6 +238,7 @@ class EXPCL_FMOD_AUDIO FmodAudioManager : public AudioManager {
EXPCL_FMOD_AUDIO PT(AudioManager) Create_AudioManager(); EXPCL_FMOD_AUDIO PT(AudioManager) Create_AudioManager();
#endif //] #endif //]
#endif /* __FMOD_AUDIO_MANAGER_H__ */ #endif /* __FMOD_AUDIO_MANAGER_H__ */

View File

@ -32,11 +32,10 @@
TypeHandle FmodAudioSound::_type_handle; TypeHandle FmodAudioSound::_type_handle;
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: FmodAudioSound::FmodAudioSound // Function: FmodAudioSound::FmodAudioSound
// Access: public // Access: public
// Description: CONSTRUCTOR // Description: Constructor
// All sound will DEFAULT load as a 2D sound unless // All sound will DEFAULT load as a 2D sound unless
// otherwise specified. // otherwise specified.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -75,17 +74,17 @@ FmodAudioSound(AudioManager *manager, string file_name, bool positional) {
DCAST_INTO_V(fmanager, manager); DCAST_INTO_V(fmanager, manager);
_manager = fmanager; _manager = fmanager;
//_channel = 0; _channel = 0;
_file_name = file_name; _file_name = file_name;
//Get the Speaker Mode [Important for later on.] //Get the Speaker Mode [Important for later on.]
result = _manager->_system->getSpeakerMode( &_speakermode ); result = _manager->_system->getSpeakerMode( &_speakermode );
ERRCHECK(result); fmod_audio_errcheck(result);
if (positional == true) { if (positional == true) {
result = _manager->_system->createSound( file_name.c_str(), FMOD_SOFTWARE | FMOD_3D , 0, &_sound); result = _manager->_system->createSound( file_name.c_str(), FMOD_SOFTWARE | FMOD_3D , 0, &_sound);
ERRCHECK(result); fmod_audio_errcheck(result);
//This is just to collect the defaults of the sound, so we don't //This is just to collect the defaults of the sound, so we don't
//Have to query FMOD everytime for the info. //Have to query FMOD everytime for the info.
@ -93,14 +92,14 @@ FmodAudioSound(AudioManager *manager, string file_name, bool positional) {
//'set_play_rate()' and 'get_play_rate()' methods later; //'set_play_rate()' and 'get_play_rate()' methods later;
result = _sound->getDefaults( &_sampleFrequency, &_volume , &_balance, &_priority); result = _sound->getDefaults( &_sampleFrequency, &_volume , &_balance, &_priority);
ERRCHECK(result); fmod_audio_errcheck(result);
audio_debug("Sound loaded as 3D"); audio_debug("Sound loaded as 3D");
} else { } else {
result = _manager->_system->createSound( file_name.c_str(), FMOD_SOFTWARE | FMOD_2D , 0, &_sound); result = _manager->_system->createSound( file_name.c_str(), FMOD_SOFTWARE | FMOD_2D , 0, &_sound);
ERRCHECK(result); fmod_audio_errcheck(result);
//This is just to collect the defaults of the sound, so we don't //This is just to collect the defaults of the sound, so we don't
//Have to query FMOD everytime for the info. //Have to query FMOD everytime for the info.
@ -108,7 +107,7 @@ FmodAudioSound(AudioManager *manager, string file_name, bool positional) {
//'set_play_rate()' and 'get_play_rate()' methods later; //'set_play_rate()' and 'get_play_rate()' methods later;
result = _sound->getDefaults( &_sampleFrequency, &_volume , &_balance, &_priority); result = _sound->getDefaults( &_sampleFrequency, &_volume , &_balance, &_priority);
ERRCHECK(result); fmod_audio_errcheck(result);
audio_debug("Sound loaded as 2D"); audio_debug("Sound loaded as 2D");
@ -136,7 +135,7 @@ FmodAudioSound::
//The Release Sound //The Release Sound
result = _sound->release(); result = _sound->release();
ERRCHECK(result); fmod_audio_errcheck(result);
audio_debug("FmodAudioSound::~FmodAudioSound() FMOD Sound Released and Closed."); audio_debug("FmodAudioSound::~FmodAudioSound() FMOD Sound Released and Closed.");
@ -190,53 +189,47 @@ FmodAudioSound::
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void FmodAudioSound:: void FmodAudioSound::
play() { play() {
audio_debug("FmodAudioSound::play() Going to play a sound." );
FMOD_RESULT result; FMOD_RESULT result;
bool paused = 0;
result = _channel->getPaused(&paused);
ERRCHECK(result);
if ( paused ) {
set_volume_on_channel();
set_play_rate_on_channel();
set_speaker_mix_or_balance_on_channel();
add_dsp_on_channel();
set_time(0.0);
result = _channel->setPaused(false); result = _channel->setPaused(false);
ERRCHECK(result); fmod_audio_errcheck(result);
} else {
prepareSound();
set_volume_on_channel();
set_play_rate_on_channel();
set_speaker_mix_or_balance_on_channel();;
add_dsp_on_channel();
result = _channel->setPaused(false);
ERRCHECK(result);
}
audio_debug("FmodAudioSound::play() Sound should be playing (or played if it is really short)." );
} }
////////////////////////////////////////////////////////////////////
// Function: sound_end_callback
// Access: Static
// Description: When fmod finishes playing a sound, the channel
// handle of the sound becomes invalid. This callback
// removes the invalid channel handle from the relevant
// fmodAudioSound.
////////////////////////////////////////////////////////////////////
static FMOD_RESULT F_CALLBACK sound_end_callback(FMOD_CHANNEL * channel,
FMOD_CHANNEL_CALLBACKTYPE type,
int command,
unsigned int commanddata1,
unsigned int commanddata2) {
FmodAudioSound *fsound = (FmodAudioSound*)command;
if (fsound->_channel != 0) {
fsound->_channel = 0;
fsound->unref();
}
return FMOD_OK;
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: FmodAudioSound::prepareSound // Function: FmodAudioSound::prepareSound
// Access: Private // Access: Private
// Description: Prepares a sound [GENERAL] // Description: Prepares a sound [GENERAL]
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void FmodAudioSound:: void FmodAudioSound::
prepareSound() { prepareSound() {
if (_channel != 0) {
return;
}
audio_debug("FmodAudioSound::prepareSound()" ); audio_debug("FmodAudioSound::prepareSound()" );
FMOD_RESULT result; FMOD_RESULT result;
@ -246,18 +239,23 @@ prepareSound() {
audio_debug("FmodAudioSound::play() Going to perpare a sound." ); audio_debug("FmodAudioSound::play() Going to perpare a sound." );
result = _sound->getMode(&soundMode); result = _sound->getMode(&soundMode);
ERRCHECK(result); fmod_audio_errcheck(result);
if ( ( soundMode & FMOD_3D ) > 0 ) {
if ( soundMode & FMOD_3D ) {
prepare3DSound(); prepare3DSound();
} else { } else {
prepare2DSound(); prepare2DSound();
} }
// This function sets up an fmod callback, which will
// clear the _channel variable when the sound stops playing.
// We want to make sure this fmodAudioSound doesn't go away
// until after the _channel is cleared, so I increment the
// ref-count.
this->ref();
result = _channel->setCallback(FMOD_CHANNEL_CALLBACKTYPE_END, sound_end_callback, (int)this);
fmod_audio_errcheck(result);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -280,7 +278,7 @@ prepare2DSound() {
FMOD_RESULT result; FMOD_RESULT result;
result = _manager->_system->playSound(FMOD_CHANNEL_REUSE, _sound, true, &_channel); result = _manager->_system->playSound(FMOD_CHANNEL_REUSE, _sound, true, &_channel);
ERRCHECK(result); fmod_audio_errcheck(result);
} }
@ -304,10 +302,10 @@ prepare3DSound() {
FMOD_RESULT result; FMOD_RESULT result;
result = _manager->_system->playSound(FMOD_CHANNEL_REUSE, _sound, true, &_channel); result = _manager->_system->playSound(FMOD_CHANNEL_REUSE, _sound, true, &_channel);
ERRCHECK(result); fmod_audio_errcheck(result);
result = _channel->set3DAttributes( &_location, &_velocity ); result = _channel->set3DAttributes( &_location, &_velocity );
ERRCHECK(result); fmod_audio_errcheck(result);
} }
@ -325,8 +323,12 @@ stop() {
//LOCALS //LOCALS
FMOD_RESULT result; FMOD_RESULT result;
if (_channel != 0) {
result = _channel->stop(); result = _channel->stop();
ERRCHECK(result); fmod_audio_errcheck(result);
_channel = 0;
unref();
}
audio_debug("FmodAudioSound::stop() Sound should be stopped."); audio_debug("FmodAudioSound::stop() Sound should be stopped.");
} }
@ -344,12 +346,12 @@ set_loop(bool loop) {
FMOD_RESULT result; FMOD_RESULT result;
if ( loop ) { if ( loop ) {
result = _sound->setMode(FMOD_LOOP_NORMAL); result = _sound->setMode(FMOD_LOOP_NORMAL);
ERRCHECK(result); fmod_audio_errcheck(result);
audio_debug("This sound is set to loop." ); audio_debug("This sound is set to loop." );
} else { } else {
result = _sound->setMode(FMOD_LOOP_OFF); result = _sound->setMode(FMOD_LOOP_OFF);
ERRCHECK(result); fmod_audio_errcheck(result);
audio_debug("FmodAudioSound::set_loop() This sound is set to one-shot." ); audio_debug("FmodAudioSound::set_loop() This sound is set to one-shot." );
} }
} }
@ -373,7 +375,7 @@ get_loop() const {
bool loopState; bool loopState;
result = _sound->getMode( &loopMode ); result = _sound->getMode( &loopMode );
ERRCHECK(result); fmod_audio_errcheck(result);
if ( (loopMode & FMOD_LOOP_NORMAL) != 0 ) { if ( (loopMode & FMOD_LOOP_NORMAL) != 0 ) {
loopState = true; loopState = true;
@ -407,10 +409,10 @@ set_loop_count(unsigned long loop_count) {
if (numberOfLoops == 0) { if (numberOfLoops == 0) {
result = _sound->setLoopCount( -1 ); result = _sound->setLoopCount( -1 );
ERRCHECK(result); fmod_audio_errcheck(result);
} else { } else {
result = _sound->setLoopCount( numberOfLoops ); result = _sound->setLoopCount( numberOfLoops );
ERRCHECK(result); fmod_audio_errcheck(result);
} }
audio_debug("FmodAudioSound::set_loop_count() Sound's loop count should be set to: " << loop_count); audio_debug("FmodAudioSound::set_loop_count() Sound's loop count should be set to: " << loop_count);
@ -431,7 +433,7 @@ get_loop_count() const {
unsigned long returnedNumber; unsigned long returnedNumber;
result = _sound->getLoopCount( &loop_count ); result = _sound->getLoopCount( &loop_count );
ERRCHECK(result); fmod_audio_errcheck(result);
audio_debug("FmodAudioSound::get_loop_count() returning "<< loop_count); audio_debug("FmodAudioSound::get_loop_count() returning "<< loop_count);
@ -451,17 +453,18 @@ set_time(float start_time) {
FMOD_RESULT result; FMOD_RESULT result;
audio_debug("FmodAudioSound::set_time() Going to set a sounds start position" ); audio_debug("FmodAudioSound::set_time() Going to set a sounds start position" );
unsigned int startTime;
//We must 'prepareSound()' [set it to play on a channel] so
//we can set its start time.
prepareSound(); prepareSound();
startTime = start_time * 1000; set_volume_on_channel();
set_play_rate_on_channel();
set_speaker_mix_or_balance_on_channel();
add_dsp_on_channel();
set_3d_attributes_on_channel();
int startTime = start_time * 1000;
result = _channel->setPosition( startTime , FMOD_TIMEUNIT_MS ); result = _channel->setPosition( startTime , FMOD_TIMEUNIT_MS );
ERRCHECK(result); fmod_audio_errcheck(result);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -473,11 +476,15 @@ float FmodAudioSound::
get_time() const { get_time() const {
audio_debug("FmodAudioSound::get_time() Going to get a sound's position" ); audio_debug("FmodAudioSound::get_time() Going to get a sound's position" );
if (_channel == 0) {
return 0.0f;
}
FMOD_RESULT result; FMOD_RESULT result;
unsigned int current_time; unsigned int current_time;
result = _channel->getPosition( &current_time , FMOD_TIMEUNIT_MS ); result = _channel->getPosition( &current_time , FMOD_TIMEUNIT_MS );
ERRCHECK(result); fmod_audio_errcheck(result);
current_time = current_time / 1000; current_time = current_time / 1000;
@ -492,17 +499,8 @@ get_time() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void FmodAudioSound:: void FmodAudioSound::
set_volume(float vol) { set_volume(float vol) {
audio_debug("FmodAudioSound::set_volume() Going to set a sounds volume." );
FMOD_RESULT result;
_volume = vol; _volume = vol;
set_volume_on_channel();
result = _channel->setVolume( _volume );
ERRCHECK(result);
audio_debug("FmodAudioSound::set_volume() Setting volume to " << vol);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -512,14 +510,14 @@ set_volume(float vol) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void FmodAudioSound:: void FmodAudioSound::
set_volume_on_channel() { set_volume_on_channel() {
audio_debug("FmodAudioSound::set_volume() Going to set a sounds volume." );
FMOD_RESULT result; FMOD_RESULT result;
result = _channel->setVolume( _volume ); if (_channel == 0) {
ERRCHECK(result); return;
}
audio_debug("FmodAudioSound::set_volume() Setting volume to " << _volume ); result = _channel->setVolume( _volume );
fmod_audio_errcheck(result);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -529,9 +527,6 @@ set_volume_on_channel() {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
float FmodAudioSound:: float FmodAudioSound::
get_volume() const { get_volume() const {
audio_debug("FmodAudioSound::get_volume() Going to get a sound's volume." );
return _volume; return _volume;
} }
@ -542,39 +537,8 @@ get_volume() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void FmodAudioSound:: void FmodAudioSound::
set_balance(float bal) { set_balance(float bal) {
audio_debug("FmodAudioSound::set_balance() Going to set a sound's balance." );
FMOD_RESULT result;
_balance = bal; _balance = bal;
set_speaker_mix_or_balance_on_channel();
result = _sound->setDefaults( _sampleFrequency, _volume , _balance, _priority);
ERRCHECK(result);
result = _channel->setPan( _balance );
ERRCHECK(result);
audio_debug("FmodAudioSound::set_balance() Setting Pan to " << bal);
}
////////////////////////////////////////////////////////////////////
// Function: FmodAudioSound::set_balance_on_channel()
// Access: public
// Description: -1.0 to 1.0 scale Set the pan on a prepared Sound channel.
// -1 should be all the way left.
// 1 is all the way to the right.
////////////////////////////////////////////////////////////////////
void FmodAudioSound::
set_balance_on_channel() {
audio_debug("FmodAudioSound::set_balance() Going to set a sound's balance to " << _balance );
FMOD_RESULT result;
result = _channel->setPan( _balance );
ERRCHECK(result);
audio_debug("FmodAudioSound::set_balance() Setting Pan to " << _balance);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -586,9 +550,6 @@ set_balance_on_channel() {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
float FmodAudioSound:: float FmodAudioSound::
get_balance() const { get_balance() const {
audio_debug("FmodAudioSound::get_balance() Going to get a sound's balance." );
return _balance; return _balance;
} }
@ -604,25 +565,8 @@ get_balance() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void FmodAudioSound:: void FmodAudioSound::
set_play_rate(float rate) { set_play_rate(float rate) {
audio_debug("FmodAudioSound::set_play_rate() Going to set a sound's play rate to " << rate);
FMOD_RESULT result;
float frequencyToSetChannelTo;
_playrate = rate; _playrate = rate;
set_play_rate_on_channel();
if (rate == 1) {
result = _channel->setFrequency( _sampleFrequency );
ERRCHECK(result);
} else {
frequencyToSetChannelTo = _sampleFrequency * rate ;
result = _channel->setFrequency( frequencyToSetChannelTo );
ERRCHECK(result);
}
audio_debug("FmodAudioSound::set_play_rate() Sound's balance set to " << rate);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -632,28 +576,23 @@ set_play_rate(float rate) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void FmodAudioSound:: void FmodAudioSound::
set_play_rate_on_channel() { set_play_rate_on_channel() {
audio_debug("FmodAudioSound::set_play_rate() Going to set a sound's balance to " << _playrate);
FMOD_RESULT result; FMOD_RESULT result;
float frequencyToSetChannelTo;
if ( _playrate == 1) {
result = _channel->setFrequency( _sampleFrequency );
ERRCHECK(result);
} else {
frequencyToSetChannelTo = _sampleFrequency * _playrate ;
result = _channel->setFrequency( frequencyToSetChannelTo );
ERRCHECK(result);
if (_channel == 0) {
return;
} }
audio_debug("FmodAudioSound::set_play_rate() Sound's balance set to " << _playrate); float frequencyToSetChannelTo;
if ( _playrate == 1) {
result = _channel->setFrequency( _sampleFrequency );
fmod_audio_errcheck(result);
} else {
frequencyToSetChannelTo = _sampleFrequency * _playrate ;
result = _channel->setFrequency( frequencyToSetChannelTo );
fmod_audio_errcheck(result);
}
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: FmodAudioSound::get_play_rate // Function: FmodAudioSound::get_play_rate
// Access: public // Access: public
@ -661,13 +600,9 @@ set_play_rate_on_channel() {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
float FmodAudioSound:: float FmodAudioSound::
get_play_rate() const { get_play_rate() const {
audio_debug("FmodAudioSound::set_play_rate() Going to get a sound's balance.");
return _playrate; return _playrate;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: FmodAudioSound::get_name // Function: FmodAudioSound::get_name
// Access: public // Access: public
@ -675,8 +610,6 @@ get_play_rate() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
const string& FmodAudioSound:: const string& FmodAudioSound::
get_name() const { get_name() const {
audio_debug("FmodAudioSound::get_name() Going to get a sound's file name.");
return _file_name; return _file_name;
} }
@ -688,14 +621,11 @@ get_name() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
float FmodAudioSound:: float FmodAudioSound::
length() const { length() const {
audio_debug("FmodAudioSound::length() Going to get a sound's length in second.");
FMOD_RESULT result; FMOD_RESULT result;
unsigned int length; unsigned int length;
result = _sound->getLength( &length, FMOD_TIMEUNIT_MS ); result = _sound->getLength( &length, FMOD_TIMEUNIT_MS );
ERRCHECK(result); fmod_audio_errcheck(result);
length = length / 1000; length = length / 1000;
@ -719,10 +649,6 @@ length() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void FmodAudioSound:: void FmodAudioSound::
set_3d_attributes(float px, float py, float pz, float vx, float vy, float vz) { set_3d_attributes(float px, float py, float pz, float vx, float vy, float vz) {
audio_debug("FmodAudioSound::set_3d_attributes() Setting a sound's 3D Coordinates.");
FMOD_RESULT result;
_location.x = px; _location.x = px;
_location.y = pz; _location.y = pz;
_location.z = py; _location.z = py;
@ -731,8 +657,30 @@ set_3d_attributes(float px, float py, float pz, float vx, float vy, float vz) {
_velocity.y = vz; _velocity.y = vz;
_velocity.z = vy; _velocity.z = vy;
set_3d_attributes_on_channel();
}
////////////////////////////////////////////////////////////////////
// Function: FmodAudioSound::set_3d_attributes
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
void FmodAudioSound::
set_3d_attributes_on_channel() {
FMOD_RESULT result;
FMOD_MODE soundMode;
if (_channel == 0) {
return;
}
result = _sound->getMode(&soundMode);
fmod_audio_errcheck(result);
if ( soundMode & FMOD_3D ) {
result = _channel->set3DAttributes( &_location, &_velocity ); result = _channel->set3DAttributes( &_location, &_velocity );
ERRCHECK(result); fmod_audio_errcheck(result);
}
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -744,7 +692,6 @@ set_3d_attributes(float px, float py, float pz, float vx, float vy, float vz) {
void FmodAudioSound:: void FmodAudioSound::
get_3d_attributes(float *px, float *py, float *pz, float *vx, float *vy, float *vz) { get_3d_attributes(float *px, float *py, float *pz, float *vx, float *vy, float *vz) {
audio_error("get3dAttributes: Currently unimplemented. Get the attributes of the attached object."); audio_error("get3dAttributes: Currently unimplemented. Get the attributes of the attached object.");
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -755,17 +702,12 @@ get_3d_attributes(float *px, float *py, float *pz, float *vx, float *vy, float *
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void FmodAudioSound:: void FmodAudioSound::
set_3d_min_distance(float dist) { set_3d_min_distance(float dist) {
audio_debug("FmodAudioSound::set_3d_min_distance() Setting the sound's 3D min distance ( min= " << dist << " ) ");
FMOD_RESULT result; FMOD_RESULT result;
_min_dist = dist; _min_dist = dist;
result = _sound->set3DMinMaxDistance( dist, _max_dist ); result = _sound->set3DMinMaxDistance( dist, _max_dist );
ERRCHECK(result); fmod_audio_errcheck(result);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -775,9 +717,6 @@ set_3d_min_distance(float dist) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
float FmodAudioSound:: float FmodAudioSound::
get_3d_min_distance() const { get_3d_min_distance() const {
audio_debug("FmodAudioSound::get_3d_min_distance() ");
return _min_dist; return _min_dist;
} }
@ -788,16 +727,12 @@ get_3d_min_distance() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void FmodAudioSound:: void FmodAudioSound::
set_3d_max_distance(float dist) { set_3d_max_distance(float dist) {
audio_debug("FmodAudioSound::set_3d_max_distance() Setting the sound's 3D max distance ( max= " << dist << " ) ");
FMOD_RESULT result; FMOD_RESULT result;
_max_dist = dist; _max_dist = dist;
result = _sound->set3DMinMaxDistance( _min_dist, dist ); result = _sound->set3DMinMaxDistance( _min_dist, dist );
ERRCHECK(result); fmod_audio_errcheck(result);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -807,9 +742,6 @@ set_3d_max_distance(float dist) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
float FmodAudioSound:: float FmodAudioSound::
get_3d_max_distance() const { get_3d_max_distance() const {
audio_debug("FmodAudioSound::get_3d_max_distance() ");
return _max_dist; return _max_dist;
} }
@ -825,8 +757,6 @@ get_3d_max_distance() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool FmodAudioSound:: bool FmodAudioSound::
add_dsp( PT(AudioDSP) x) { add_dsp( PT(AudioDSP) x) {
audio_debug("FmodAudioManager()::add_dsp");
FMOD_RESULT result; FMOD_RESULT result;
bool playingState; bool playingState;
@ -839,17 +769,16 @@ add_dsp( PT(AudioDSP) x) {
return false; return false;
} else } else {
{
_sound_dsp.insert(fdsp); _sound_dsp.insert(fdsp);
if ( _channel != 0 ) { if ( _channel != 0 ) {
result = _channel->isPlaying( &playingState ); result = _channel->isPlaying( &playingState );
ERRCHECK(result); fmod_audio_errcheck(result);
if ( playingState ) { if ( playingState ) {
result = _channel->addDSP( fdsp->_dsp ); result = _channel->addDSP( fdsp->_dsp );
ERRCHECK( result ); fmod_audio_errcheck( result );
} }
} }
@ -858,7 +787,6 @@ add_dsp( PT(AudioDSP) x) {
return true; return true;
} }
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -875,7 +803,7 @@ add_dsp_on_channel() {
for (DSPSet::iterator i = _sound_dsp.begin(); i != _sound_dsp.end(); ++i) { for (DSPSet::iterator i = _sound_dsp.begin(); i != _sound_dsp.end(); ++i) {
result = _channel->addDSP( (*i)->_dsp ); result = _channel->addDSP( (*i)->_dsp );
ERRCHECK( result ); fmod_audio_errcheck( result );
} }
} }
@ -902,7 +830,7 @@ remove_dsp(PT(AudioDSP) x) {
if ( fdsp->get_in_chain() ) { if ( fdsp->get_in_chain() ) {
result = fdsp->_dsp->remove(); result = fdsp->_dsp->remove();
ERRCHECK( result ); fmod_audio_errcheck( result );
_sound_dsp.erase(fdsp); _sound_dsp.erase(fdsp);
@ -949,6 +877,10 @@ get_speaker_mix(int speaker) {
audio_debug("FmodAudioSound::getSpeakerMix()"); audio_debug("FmodAudioSound::getSpeakerMix()");
if (_channel == 0) {
return 0.0;
}
FMOD_RESULT result; FMOD_RESULT result;
float frontleft; float frontleft;
float frontright; float frontright;
@ -961,50 +893,37 @@ get_speaker_mix(int speaker) {
float returnValue; float returnValue;
result = _channel->getSpeakerMix( &frontleft, &frontright, &center, &sub, &backleft, &backright, &sideleft, &sideright );
fmod_audio_errcheck(result);
switch(speaker) { switch(speaker) {
case 1: case 1:
result = _channel->getSpeakerMix( &frontleft, &frontright, &center, &sub, &backleft, &backright, &sideleft, &sideright );
ERRCHECK(result);
returnValue = frontleft; returnValue = frontleft;
break; break;
case 2: case 2:
result = _channel->getSpeakerMix( &frontleft, &frontright, &center, &sub, &backleft, &backright, &sideleft, &sideright );
ERRCHECK(result);
returnValue = frontright; returnValue = frontright;
break; break;
case 3: case 3:
result = _channel->getSpeakerMix( &frontleft, &frontright, &center, &sub, &backleft, &backright, &sideleft, &sideright );
ERRCHECK(result);
returnValue = center; returnValue = center;
break; break;
case 4: case 4:
result = _channel->getSpeakerMix( &frontleft, &frontright, &center, &sub, &backleft, &backright, &sideleft, &sideright );
ERRCHECK(result);
returnValue = sub; returnValue = sub;
break; break;
case 5: case 5:
result = _channel->getSpeakerMix( &frontleft, &frontright, &center, &sub, &backleft, &backright, &sideleft, &sideright );
ERRCHECK(result);
returnValue = backleft; returnValue = backleft;
break; break;
case 6: case 6:
result = _channel->getSpeakerMix( &frontleft, &frontright, &center, &sub, &backleft, &backright, &sideleft, &sideright );
ERRCHECK(result);
returnValue = backright; returnValue = backright;
break; break;
case 7: case 7:
result = _channel->getSpeakerMix( &frontleft, &frontright, &center, &sub, &backleft, &backright, &sideleft, &sideright );
ERRCHECK(result);
returnValue = sideleft; returnValue = sideleft;
break; break;
case 8: case 8:
result = _channel->getSpeakerMix( &frontleft, &frontright, &center, &sub, &backleft, &backright, &sideleft, &sideright );
ERRCHECK(result);
returnValue = sideright; returnValue = sideright;
break; break;
default: default:
cerr << "You specified a speaker which doesn't exist."; audio_error("You specified a speaker which doesn't exist.");
} }
return returnValue; return returnValue;
@ -1027,12 +946,6 @@ get_speaker_mix(int speaker) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void FmodAudioSound:: void FmodAudioSound::
set_speaker_mix(float frontleft, float frontright, float center, float sub, float backleft, float backright, float sideleft, float sideright) { set_speaker_mix(float frontleft, float frontright, float center, float sub, float backleft, float backright, float sideleft, float sideright) {
// intentionally blank
audio_debug("FmodAudioSound::setSpeakerMix()");
FMOD_RESULT result;
_frontleft = frontleft; _frontleft = frontleft;
_frontright = frontright; _frontright = frontright;
_center = center; _center = center;
@ -1042,29 +955,9 @@ set_speaker_mix(float frontleft, float frontright, float center, float sub, floa
_sideleft = sideleft; _sideleft = sideleft;
_sideright = sideright; _sideright = sideright;
result = _channel->setSpeakerMix( _frontleft, _frontright, _center, _sub, _backleft, _backright, _sideleft, _sideright ); set_speaker_mix_or_balance_on_channel();
ERRCHECK(result);;
} }
////////////////////////////////////////////////////////////////////
// Function: FmodAudioSound::set_speaker_mix_on_channel
// Access: Published
// Description: Set the Speaker Mix for a sound on a prepared Sound channel.
////////////////////////////////////////////////////////////////////
void FmodAudioSound::
set_speaker_mix_on_channel() {
// intentionally blank
audio_debug("FmodAudioSound::setSpeakerMix()");
FMOD_RESULT result;
result = _channel->setSpeakerMix( _frontleft, _frontright, _center, _sub, _backleft, _backright, _sideleft, _sideright );
ERRCHECK(result);;
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: FmodAudioSound::set_speaker_mix_or_balance_on_channel // Function: FmodAudioSound::set_speaker_mix_or_balance_on_channel
// Access: Private // Access: Private
@ -1078,33 +971,26 @@ set_speaker_mix_on_channel() {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void FmodAudioSound:: void FmodAudioSound::
set_speaker_mix_or_balance_on_channel() { set_speaker_mix_or_balance_on_channel() {
// intentionally blank
audio_debug("FmodAudioSound::set_speaker_mix_or_balance_on_channel()");
FMOD_RESULT result; FMOD_RESULT result;
FMOD_MODE soundMode; FMOD_MODE soundMode;
result = _sound->getMode(&soundMode); result = _sound->getMode(&soundMode);
ERRCHECK(result); fmod_audio_errcheck(result);
if ( _speakermode == FMOD_SPEAKERMODE_STEREO ) { if ( _speakermode == FMOD_SPEAKERMODE_STEREO ) {
//FMOD Returns an error is you try and pan a sound in 3D Audio. //FMOD Returns an error is you try and pan a sound in 3D Audio.
//Which makes sense. //Which makes sense.
//It is nothing serious, but might as well avoid it while we can. //It is nothing serious, but might as well avoid it while we can.
if ( !( ( soundMode & FMOD_3D ) > 0 ) ) { if ( soundMode & FMOD_3D ) {
set_balance_on_channel(); result = _channel->setPan( _balance );
fmod_audio_errcheck(result);
} }
} else { } else {
if ( soundMode & FMOD_3D ) {
set_speaker_mix_on_channel(); result = _channel->setSpeakerMix( _frontleft, _frontright, _center, _sub, _backleft, _backright, _sideleft, _sideright );
fmod_audio_errcheck(result);
}
} }
} }
@ -1138,7 +1024,7 @@ set_priority(int priority) {
_priority = priority; _priority = priority;
result = _sound->setDefaults( _sampleFrequency, _volume , _balance, _priority); result = _sound->setDefaults( _sampleFrequency, _volume , _balance, _priority);
ERRCHECK(result); fmod_audio_errcheck(result);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -1158,7 +1044,7 @@ status() const {
if ( _channel != 0 ) { if ( _channel != 0 ) {
result = _channel->isPlaying( &playingState ); result = _channel->isPlaying( &playingState );
ERRCHECK(result); fmod_audio_errcheck(result);
} }
//audio_debug("If you get 'FMOD State: 32 An invalid object handle was used.' "); //audio_debug("If you get 'FMOD State: 32 An invalid object handle was used.' ");

View File

@ -208,6 +208,7 @@ class EXPCL_FMOD_AUDIO FmodAudioSound : public AudioSound {
void set_balance_on_channel(); void set_balance_on_channel();
void set_play_rate_on_channel(); void set_play_rate_on_channel();
void set_speaker_mix_on_channel(); void set_speaker_mix_on_channel();
void set_3d_attributes_on_channel();
void add_dsp_on_channel(); void add_dsp_on_channel();
void set_speaker_mix_or_balance_on_channel(); void set_speaker_mix_or_balance_on_channel();
@ -223,6 +224,12 @@ class EXPCL_FMOD_AUDIO FmodAudioSound : public AudioSound {
//THESE are stubs in FMOD-EX version //THESE are stubs in FMOD-EX version
string _finished_event; string _finished_event;
friend FMOD_RESULT F_CALLBACK sound_end_callback(FMOD_CHANNEL * channel,
FMOD_CHANNEL_CALLBACKTYPE type,
int command,
unsigned int commanddata1,
unsigned int commanddata2);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//These are needed for Panda's Pointer System. DO NOT ERASE! //These are needed for Panda's Pointer System. DO NOT ERASE!
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////