mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 02:42:49 -04:00
whee. Make it so sfx and music can be turned on and off independantly.
Also give master volume control for SFX and music.
This commit is contained in:
parent
5a61602f0d
commit
9633192ede
@ -334,6 +334,8 @@ void LinuxSamplePlayer::play_sound(AudioTraits::SoundClass*,
|
||||
float start_time) {
|
||||
initialize();
|
||||
LinuxSamplePlaying* lplaying = (LinuxSamplePlaying*)playing;
|
||||
if (!AudioManager::get_sfx_active())
|
||||
return;
|
||||
unsigned long l = lplaying->get_data()->get_size();
|
||||
float factor = ((float)l) / (audio_mix_freq * 2. * sample_size);
|
||||
factor = start_time / factor;
|
||||
@ -349,10 +351,16 @@ void LinuxSamplePlayer::stop_sound(AudioTraits::SoundClass*,
|
||||
AudioTraits::PlayingClass* playing) {
|
||||
initialize();
|
||||
LinuxSamplePlaying* lplaying = (LinuxSamplePlaying*)playing;
|
||||
if (!AudioManager::get_sfx_active())
|
||||
return;
|
||||
buffers.erase(lplaying->get_data());
|
||||
}
|
||||
|
||||
void LinuxSamplePlayer::set_volume(AudioTraits::PlayingClass*, float) {
|
||||
void LinuxSamplePlayer::set_volume(AudioTraits::PlayingClass* p, float v) {
|
||||
p->set_volume(v);
|
||||
}
|
||||
|
||||
void LinuxSamplePlayer::adjust_volume(AudioTraits::PlayingClass*) {
|
||||
}
|
||||
|
||||
LinuxSamplePlayer* LinuxSamplePlayer::get_instance(void) {
|
||||
@ -377,7 +385,11 @@ void LinuxMusicPlayer::stop_sound(AudioTraits::SoundClass*,
|
||||
initialize();
|
||||
}
|
||||
|
||||
void LinuxMusicPlayer::set_volume(AudioTraits::PlayingClass*, float) {
|
||||
void LinuxMusicPlayer::set_volume(AudioTraits::PlayingClass* p, float v) {
|
||||
p->set_volume(v);
|
||||
}
|
||||
|
||||
void LinuxMusicPlayer::adjust_volume(AudioTraits::PlayingClass*) {
|
||||
}
|
||||
|
||||
LinuxMusicPlayer* LinuxMusicPlayer::get_instance(void) {
|
||||
|
@ -121,6 +121,7 @@ public:
|
||||
virtual void stop_sound(AudioTraits::SoundClass*,
|
||||
AudioTraits::PlayingClass*);
|
||||
virtual void set_volume(AudioTraits::PlayingClass*, float);
|
||||
virtual void adjust_volume(AudioTraits::PlayingClass*);
|
||||
public:
|
||||
// used by the readers
|
||||
static LinuxSamplePlayer* get_instance(void);
|
||||
@ -138,6 +139,7 @@ public:
|
||||
virtual void stop_sound(AudioTraits::SoundClass*,
|
||||
AudioTraits::PlayingClass*);
|
||||
virtual void set_volume(AudioTraits::PlayingClass*, float);
|
||||
virtual void adjust_volume(AudioTraits::PlayingClass*);
|
||||
public:
|
||||
// used by the readers
|
||||
static LinuxMusicPlayer* get_instance(void);
|
||||
|
@ -95,4 +95,101 @@ INLINE bool AudioManager::get_loop(AudioSound* sound) {
|
||||
// directly; there's only supposed to be one AudioManager
|
||||
// in the universe and it constructs itself.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE AudioManager::AudioManager(void) {}
|
||||
INLINE AudioManager::AudioManager(void) {
|
||||
_sfx_active = audio_sfx_active;
|
||||
_music_active = audio_music_active;
|
||||
_master_sfx_volume = audio_master_sfx_volume;
|
||||
_master_music_volume = audio_master_music_volume;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: AudioManager::set_master_sfx_volume
|
||||
// Access: Public, Static
|
||||
// Description: set the overall volume of SFX
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void AudioManager::set_master_sfx_volume(float v) {
|
||||
AudioManager::_master_sfx_volume = v;
|
||||
AudioManager::_master_volume_change = true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: AudioManager::set_master_music_volume
|
||||
// Access: Public, Static
|
||||
// Description: set the overall volume of music
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void AudioManager::set_master_music_volume(float v) {
|
||||
AudioManager::_master_music_volume = v;
|
||||
AudioManager::_master_volume_change = true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: AudioManager::get_master_sfx_volume
|
||||
// Access: Public, Static
|
||||
// Description: return the overall volume of SFX
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE float AudioManager::get_master_sfx_volume(void) {
|
||||
return AudioManager::_master_sfx_volume;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: AudioManager::get_master_music_volume
|
||||
// Access: Public, Static
|
||||
// Description: return the overall volume of music
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE float AudioManager::get_master_music_volume(void) {
|
||||
return AudioManager::_master_music_volume;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: AudioManager::set_all_sound_active
|
||||
// Access: Public, Static
|
||||
// Description: turn on/off all audio
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void AudioManager::set_all_sound_active(bool f) {
|
||||
audio_is_active = f;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: AudioManager::set_all_sound_active
|
||||
// Access: Public, Static
|
||||
// Description: turn on/off all audio
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool AudioManager::get_all_sound_active(void) {
|
||||
return audio_is_active;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: AudioManager::set_sfx_active
|
||||
// Access: Public, Static
|
||||
// Description: turn on/off SFX
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void AudioManager::set_sfx_active(bool f) {
|
||||
AudioManager::_sfx_active = f;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: AudioManager::set_music_active
|
||||
// Access: Public, Static
|
||||
// Description: turn on/off music
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void AudioManager::set_music_active(bool f) {
|
||||
AudioManager::_music_active = f;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: AudioManager::get_sfx_active
|
||||
// Access: Public, Static
|
||||
// Description: return the state of SFX playing
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool AudioManager::get_sfx_active(void) {
|
||||
return AudioManager::_sfx_active;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: AudioManager::get_music_active
|
||||
// Access: Public, Static
|
||||
// Description: return the state of music playing
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool AudioManager::get_music_active(void) {
|
||||
return AudioManager::_music_active;
|
||||
}
|
||||
|
@ -16,6 +16,11 @@ bool* AudioManager::_quit = (bool*)0L;
|
||||
thread* AudioManager::_spawned = (thread*)0L;
|
||||
AudioManager::LoopSet* AudioManager::_loopset = (AudioManager::LoopSet*)0L;
|
||||
AudioManager::LoopSet* AudioManager::_loopcopy = (AudioManager::LoopSet*)0L;
|
||||
bool AudioManager::_sfx_active = false;
|
||||
bool AudioManager::_music_active = false;
|
||||
bool AudioManager::_master_volume_change = false;
|
||||
float AudioManager::_master_sfx_volume = 0.;
|
||||
float AudioManager::_master_music_volume = 0.;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: AudioManager::destructor
|
||||
@ -68,8 +73,10 @@ void AudioManager::ns_update(void) {
|
||||
audio_cat->debug() << "AudioManager::ns_update looping '"
|
||||
<< sound->get_name() << "'" << endl;
|
||||
AudioManager::play(sound);
|
||||
}
|
||||
} else if (AudioManager::_master_volume_change)
|
||||
sound->get_player()->adjust_volume(sound->get_state());
|
||||
}
|
||||
AudioManager::_master_volume_change = false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -112,6 +119,7 @@ void AudioManager::ns_play(AudioSound* sound, float start_time) {
|
||||
this->ns_stop(sound);
|
||||
sound->get_player()->play_sound(sound->get_sound(), sound->get_state(),
|
||||
start_time);
|
||||
sound->get_player()->adjust_volume(sound->get_state());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -168,7 +176,8 @@ void* AudioManager::spawned_update(void* data) {
|
||||
ipc_traits::sleep(0, audio_auto_update_delay);
|
||||
}
|
||||
*flag = false;
|
||||
audio_cat->debug() << "exiting update thread" << endl;
|
||||
if (audio_cat->is_debug())
|
||||
audio_cat->debug() << "exiting update thread" << endl;
|
||||
return (void*)0L;
|
||||
}
|
||||
|
||||
@ -226,6 +235,7 @@ void AudioManager::ns_shutdown(void) {
|
||||
(*_shutdown_func)();
|
||||
if (_spawned != (thread*)0L)
|
||||
while (*_quit);
|
||||
audio_cat->debug() << "update thread has shutdown" << endl;
|
||||
if (audio_cat->is_debug())
|
||||
audio_cat->debug() << "update thread has shutdown" << endl;
|
||||
delete _quit;
|
||||
}
|
||||
|
@ -33,7 +33,6 @@ private:
|
||||
|
||||
typedef void UpdateFunc(void);
|
||||
typedef void ShutdownFunc(void);
|
||||
// typedef set<PT(AudioSound)> LoopSet;
|
||||
typedef set<AudioSound*> LoopSet;
|
||||
static AudioManager* _global_ptr;
|
||||
static UpdateFunc* _update_func;
|
||||
@ -43,6 +42,11 @@ private:
|
||||
static thread* _spawned;
|
||||
static LoopSet* _loopset;
|
||||
static LoopSet* _loopcopy;
|
||||
static bool _sfx_active;
|
||||
static bool _music_active;
|
||||
static float _master_sfx_volume;
|
||||
static float _master_music_volume;
|
||||
static bool _master_volume_change;
|
||||
public:
|
||||
virtual ~AudioManager(void);
|
||||
|
||||
@ -58,6 +62,16 @@ PUBLISHED:
|
||||
INLINE static void update(void);
|
||||
INLINE static void spawn_update(void);
|
||||
INLINE static void shutdown(void);
|
||||
INLINE static void set_master_sfx_volume(float);
|
||||
INLINE static void set_master_music_volume(float);
|
||||
INLINE static float get_master_sfx_volume(void);
|
||||
INLINE static float get_master_music_volume(void);
|
||||
INLINE static void set_all_sound_active(bool);
|
||||
INLINE static bool get_all_sound_active(void);
|
||||
INLINE static void set_sfx_active(bool);
|
||||
INLINE static void set_music_active(bool);
|
||||
INLINE static bool get_sfx_active(void);
|
||||
INLINE static bool get_music_active(void);
|
||||
};
|
||||
|
||||
#include "audio_manager.I"
|
||||
|
@ -293,6 +293,8 @@ void MikModSamplePlayer::play_sound(AudioTraits::SoundClass* sample,
|
||||
// cast to the correct type
|
||||
MikModSample* msample = (MikModSample*)sample;
|
||||
MikModSamplePlaying* mplay = (MikModSamplePlaying*)playing;
|
||||
if (!AudioManager::get_sfx_active())
|
||||
return;
|
||||
// fire it off
|
||||
mplay->set_voice(Sample_Play(msample->get_sample(), 0, 0));
|
||||
Voice_SetFrequency(mplay->get_voice(), msample->get_freq());
|
||||
@ -312,7 +314,20 @@ void MikModSamplePlayer::set_volume(AudioTraits::PlayingClass* state,
|
||||
float v) {
|
||||
initialize();
|
||||
MikModSamplePlaying* mplay = (MikModSamplePlaying*)state;
|
||||
Voice_SetVolume(mplay->get_voice(), v);
|
||||
if (!AudioManager::get_sfx_active())
|
||||
return;
|
||||
Voice_SetVolume(mplay->get_voice(),
|
||||
v * AudioManager::get_master_sfx_volume());
|
||||
state->set_volume(v);
|
||||
}
|
||||
|
||||
void MikModSamplePlayer::adjust_volume(AudioTraits::PlayingClass* state) {
|
||||
initialize();
|
||||
MikModSamplePlaying* mplay = (MikModSamplePlaying*)state;
|
||||
if (!AudioManager::get_sfx_active())
|
||||
return;
|
||||
Voice_SetVolume(mplay->get_voice(),
|
||||
state->get_volume() * AudioManager::get_master_sfx_volume());
|
||||
}
|
||||
|
||||
MikModSamplePlayer* MikModSamplePlayer::get_instance(void) {
|
||||
@ -340,9 +355,16 @@ void MikModFmsynthPlayer::stop_sound(AudioTraits::SoundClass*,
|
||||
AudioTraits::PlayingClass*) {
|
||||
}
|
||||
|
||||
void MikModFmsynthPlayer::set_volume(AudioTraits::PlayingClass*, float) {
|
||||
void MikModFmsynthPlayer::set_volume(AudioTraits::PlayingClass* p, float v) {
|
||||
audio_cat->error()
|
||||
<< "trying to set volume on a sample with a MikModFmsynthPlayer" << endl;
|
||||
p->set_volume(v);
|
||||
}
|
||||
|
||||
void MikModFmsynthPlayer::adjust_volume(AudioTraits::PlayingClass*) {
|
||||
audio_cat->error()
|
||||
<< "trying to adjust volume on a sample with a MikModFmsynthPlayer"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
MikModFmsynthPlayer* MikModFmsynthPlayer::get_instance(void) {
|
||||
@ -369,9 +391,15 @@ void MikModMidiPlayer::stop_sound(AudioTraits::SoundClass*,
|
||||
AudioTraits::PlayingClass*) {
|
||||
}
|
||||
|
||||
void MikModMidiPlayer::set_volume(AudioTraits::PlayingClass*, float) {
|
||||
void MikModMidiPlayer::set_volume(AudioTraits::PlayingClass* p, float v) {
|
||||
audio_cat->error()
|
||||
<< "trying to set volume on a sample with a MikModMidiPlayer" << endl;
|
||||
p->set_volume(v);
|
||||
}
|
||||
|
||||
void MikModMidiPlayer::adjust_volume(AudioTraits::PlayingClass*) {
|
||||
audio_cat->error()
|
||||
<< "trying to adjust volume on a sample with a mikModMidiPlayer" << endl;
|
||||
}
|
||||
|
||||
MikModMidiPlayer* MikModMidiPlayer::get_instance(void) {
|
||||
|
@ -106,6 +106,7 @@ public:
|
||||
virtual void stop_sound(AudioTraits::SoundClass*,
|
||||
AudioTraits::PlayingClass*);
|
||||
virtual void set_volume(AudioTraits::PlayingClass*, float);
|
||||
virtual void adjust_volume(AudioTraits::PlayingClass*);
|
||||
public:
|
||||
// used by the readers
|
||||
static MikModSamplePlayer* get_instance(void);
|
||||
@ -123,6 +124,7 @@ public:
|
||||
virtual void stop_sound(AudioTraits::SoundClass*,
|
||||
AudioTraits::PlayingClass*);
|
||||
virtual void set_volume(AudioTraits::PlayingClass*, float);
|
||||
virtual void adjust_volume(AudioTraits::PlayingClass*);
|
||||
public:
|
||||
// used by the readers
|
||||
static MikModFmsynthPlayer* get_instance(void);
|
||||
@ -140,6 +142,7 @@ public:
|
||||
virtual void stop_sound(AudioTraits::SoundClass*,
|
||||
AudioTraits::PlayingClass*);
|
||||
virtual void set_volume(AudioTraits::PlayingClass*, float);
|
||||
virtual void adjust_volume(AudioTraits::PlayingClass*);
|
||||
public:
|
||||
// used by the readers
|
||||
static MikModMidiPlayer* get_instance(void);
|
||||
|
@ -74,10 +74,15 @@ void NullPlayer::stop_sound(AudioTraits::SoundClass*,
|
||||
audio_cat->debug() << "in stop sound in Null audio driver" << endl;
|
||||
}
|
||||
|
||||
void NullPlayer::set_volume(AudioTraits::PlayingClass*, float) {
|
||||
void NullPlayer::set_volume(AudioTraits::PlayingClass* p, float v) {
|
||||
if (audio_cat->is_debug())
|
||||
audio_cat->debug() << "in set volume in Null audio driver"
|
||||
<< endl;
|
||||
audio_cat->debug() << "in set volume in Null audio driver" << endl;
|
||||
p->set_volume(v);
|
||||
}
|
||||
|
||||
void NullPlayer::adjust_volume(AudioTraits::PlayingClass*) {
|
||||
if (audio_cat->is_debug())
|
||||
audio_cat->debug() << "in adjust volume in Null audio driver" << endl;
|
||||
}
|
||||
|
||||
#endif /* AUDIO_USE_NULL */
|
||||
|
@ -43,6 +43,7 @@ public:
|
||||
virtual void stop_sound(AudioTraits::SoundClass*,
|
||||
AudioTraits::PlayingClass*);
|
||||
virtual void set_volume(AudioTraits::PlayingClass*, float);
|
||||
virtual void adjust_volume(AudioTraits::PlayingClass*);
|
||||
};
|
||||
|
||||
#include "audio_null_traits.I"
|
||||
|
@ -55,3 +55,7 @@ void AudioTraits::PlayerClass::stop_sound(AudioTraits::SoundClass*,
|
||||
void AudioTraits::PlayerClass::set_volume(AudioTraits::PlayingClass*, float) {
|
||||
audio_cat->error() << "In abstract PlayerClass::set_volume!" << endl;
|
||||
}
|
||||
|
||||
void AudioTraits::PlayerClass::adjust_volume(AudioTraits::PlayingClass*) {
|
||||
audio_cat->error() << "In abstract PlayerClass::adjust_volume!" << endl;
|
||||
}
|
||||
|
@ -31,13 +31,16 @@ public:
|
||||
class EXPCL_PANDA PlayingClass {
|
||||
protected:
|
||||
SoundClass* _sound;
|
||||
float _volume;
|
||||
public:
|
||||
PlayingClass(SoundClass* s) : _sound(s) {}
|
||||
PlayingClass(SoundClass* s) : _sound(s), _volume(1.) {}
|
||||
virtual ~PlayingClass(void);
|
||||
|
||||
enum PlayingStatus { BAD, READY, PLAYING } ;
|
||||
|
||||
virtual PlayingStatus status(void) = 0;
|
||||
INLINE void set_volume(float v) { _volume = v; }
|
||||
INLINE float get_volume(void) const { return _volume; }
|
||||
};
|
||||
class EXPCL_PANDA PlayerClass {
|
||||
public:
|
||||
@ -47,6 +50,7 @@ public:
|
||||
virtual void play_sound(SoundClass*, PlayingClass*, float) = 0;
|
||||
virtual void stop_sound(SoundClass*, PlayingClass*) = 0;
|
||||
virtual void set_volume(PlayingClass*, float) = 0;
|
||||
virtual void adjust_volume(PlayingClass*) = 0;
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -32,6 +32,22 @@ static IDirectSound* musicDirectSound = NULL;
|
||||
return; \
|
||||
}
|
||||
|
||||
#define CHECK_RESULT_SFX(_result, _msg) \
|
||||
if (FAILED(_result)) { \
|
||||
audio_cat->error() << _msg << " at " << __FILE__ << ":" << __LINE__ \
|
||||
<< endl; \
|
||||
AudioManager::set_sfx_active(false); \
|
||||
return; \
|
||||
}
|
||||
|
||||
#define CHECK_RESULT_MUSIC(_result, _msg) \
|
||||
if (FAILED(_result)) { \
|
||||
audio_cat->error() << _msg << " at " << __FILE__ << ":" << __LINE__ \
|
||||
<< endl; \
|
||||
AudioManager::set_music_active(false); \
|
||||
return; \
|
||||
}
|
||||
|
||||
// #define MULTI_TO_WIDE(_in, _out) MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, _in, -1, _out, DMUS_MAX_FILENAME)
|
||||
#define MULTI_TO_WIDE(x,y) MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, y, -1, x, _MAX_PATH);
|
||||
|
||||
@ -62,7 +78,7 @@ static void initialize(void) {
|
||||
|
||||
// create a direct sound object
|
||||
result = DirectSoundCreate(NULL, &soundDirectSound, NULL);
|
||||
CHECK_RESULT(result, "could not create a Direct Sound (tm) object (c)");
|
||||
CHECK_RESULT_SFX(result, "could not create a Direct Sound (tm) object (c)");
|
||||
|
||||
// set the cooperative level
|
||||
result = soundDirectSound->SetCooperativeLevel(global_hwnd, DSSCL_PRIORITY);
|
||||
@ -70,7 +86,7 @@ static void initialize(void) {
|
||||
audio_cat->warning() << "could not set Direct Sound co-op level to "
|
||||
<< "DSSCL_PRIORITY, trying DSSCL_NORMAL" << endl;
|
||||
result = soundDirectSound->SetCooperativeLevel(global_hwnd, DSSCL_NORMAL);
|
||||
CHECK_RESULT(result, "failed setting to DSSCL_NORMAL");
|
||||
CHECK_RESULT_SFX(result, "failed setting to DSSCL_NORMAL");
|
||||
}
|
||||
|
||||
// Move any unused portions of onboard sound memory to a contiguous block
|
||||
@ -84,7 +100,7 @@ static void initialize(void) {
|
||||
dsbd.dwFlags = DSBCAPS_PRIMARYBUFFER;
|
||||
result = soundDirectSound->CreateSoundBuffer(&dsbd, &soundPrimaryBuffer,
|
||||
NULL);
|
||||
CHECK_RESULT(result, "could not create primary buffer");
|
||||
CHECK_RESULT_SFX(result, "could not create primary buffer");
|
||||
|
||||
// set primary buffer format to 22kHz and 16-bit output
|
||||
// COME BACK LATER TO MAKE THIS CONFIG
|
||||
@ -467,7 +483,7 @@ void WinMusic::init(void) {
|
||||
// initialize performance object
|
||||
// result = _performance->Init(&musicDirectMusic, NULL, NULL);
|
||||
result = _performance->Init(NULL, NULL, NULL);
|
||||
CHECK_RESULT(result, "could not initialize performance object");
|
||||
CHECK_RESULT_MUSIC(result, "could not initialize performance object");
|
||||
|
||||
/*
|
||||
// create the output synth object
|
||||
@ -518,7 +534,7 @@ void WinMusic::init(void) {
|
||||
audio_cat->error() << "got E_OUTOFMEMORY" << endl;
|
||||
else if (result == E_POINTER)
|
||||
audio_cat->error() << "got E_POINTER" << endl;
|
||||
CHECK_RESULT(result, "failed to add synth to performance");
|
||||
CHECK_RESULT_MUSIC(result, "failed to add synth to performance");
|
||||
|
||||
/*
|
||||
// allocate performance channels
|
||||
@ -625,10 +641,12 @@ WinMusic* WinMusic::load_midi(Filename filename) {
|
||||
*/
|
||||
string stmp = filename.to_os_specific();
|
||||
MULTI_TO_WIDE(fdesc.wszFileName, stmp.c_str());
|
||||
audio_cat->debug() << "os_specific name '" << stmp << "'" << endl;
|
||||
if (audio_cat->is_debug())
|
||||
audio_cat->debug() << "os_specific name '" << stmp << "'" << endl;
|
||||
if (filename.is_local()) {
|
||||
fdesc.dwValidData = DMUS_OBJ_CLASS | DMUS_OBJ_FILENAME;
|
||||
audio_cat->debug() << "is local" << endl;
|
||||
if (audio_cat->is_debug())
|
||||
audio_cat->debug() << "is local" << endl;
|
||||
char szDir[2] = ".";
|
||||
WCHAR wszDir[2];
|
||||
MULTI_TO_WIDE(wszDir, szDir);
|
||||
@ -643,7 +661,8 @@ WinMusic* WinMusic::load_midi(Filename filename) {
|
||||
}
|
||||
} else {
|
||||
fdesc.dwValidData = DMUS_OBJ_CLASS | DMUS_OBJ_FILENAME | DMUS_OBJ_FULLPATH;
|
||||
audio_cat->debug() << "is not local" << endl;
|
||||
if (audio_cat->is_debug())
|
||||
audio_cat->debug() << "is not local" << endl;
|
||||
}
|
||||
result = loader->GetObject(&fdesc, IID_IDirectMusicSegment2,
|
||||
(void**)&(ret->_music));
|
||||
@ -657,8 +676,6 @@ WinMusic* WinMusic::load_midi(Filename filename) {
|
||||
ret->_music->SetParam(GUID_StandardMIDIFile, -1, 0, 0,
|
||||
(void*)(ret->_performance));
|
||||
ret->_music->SetParam(GUID_Download, -1, 0, 0, (void*)(ret->_performance));
|
||||
// ret->_buffer->SetVolume(0);
|
||||
// ret->_buffer->SetPan(0);
|
||||
if (audio_cat->is_debug())
|
||||
audio_cat->debug() << "out of WinMusic::load_midi() _music = "
|
||||
<< (void*)ret->_music << endl;
|
||||
@ -824,6 +841,8 @@ void WinSamplePlayer::play_sound(AudioTraits::SoundClass* sample,
|
||||
initialize();
|
||||
if (!audio_is_active)
|
||||
return;
|
||||
if (!AudioManager::get_sfx_active())
|
||||
return;
|
||||
WinSample* wsample = (WinSample*)sample;
|
||||
WinSamplePlaying* wplay = (WinSamplePlaying*)play;
|
||||
LPDIRECTSOUNDBUFFER chan = wplay->get_channel();
|
||||
@ -851,6 +870,8 @@ void WinSamplePlayer::stop_sound(AudioTraits::SoundClass*,
|
||||
initialize();
|
||||
if (!audio_is_active)
|
||||
return;
|
||||
if (!AudioManager::get_sfx_active())
|
||||
return;
|
||||
WinSamplePlaying* wplay = (WinSamplePlaying*)play;
|
||||
LPDIRECTSOUNDBUFFER chan = wplay->get_channel();
|
||||
if (chan)
|
||||
@ -863,10 +884,31 @@ void WinSamplePlayer::set_volume(AudioTraits::PlayingClass* play, float v) {
|
||||
initialize();
|
||||
if (!audio_is_active)
|
||||
return;
|
||||
if (!AudioManager::get_sfx_active())
|
||||
return;
|
||||
WinSamplePlaying* wplay = (WinSamplePlaying*)play;
|
||||
LPDIRECTSOUNDBUFFER chan = wplay->get_channel();
|
||||
float tmpv = v * AudioManager::get_master_sfx_volume();
|
||||
if (chan) {
|
||||
LONG v2 = (v * (DSBVOLUME_MAX - DSBVOLUME_MIN)) + DSBVOLUME_MIN;
|
||||
LONG v2 = (tmpv * (DSBVOLUME_MAX - DSBVOLUME_MIN)) + DSBVOLUME_MIN;
|
||||
chan->SetVolume(v2);
|
||||
}
|
||||
play->set_volume(v);
|
||||
}
|
||||
|
||||
void WinSamplePlayer::adjust_volume(AudioTraits::PlayingClass* play) {
|
||||
if (audio_cat->is_debug())
|
||||
audio_cat->debug() << "winsampleplayer adjust_volume" << endl;
|
||||
initialize();
|
||||
if (!audio_is_active)
|
||||
return;
|
||||
if (!AudioManager::get_sfx_active())
|
||||
return;
|
||||
WinSamplePlaying* wplay = (WinSamplePlaying*)play;
|
||||
LPDIRECTSOUNDBUFFER chan = wplay->get_channel();
|
||||
float tmpv = play->get_volume() * AudioManager::get_master_sfx_volume();
|
||||
if (chan) {
|
||||
LONG v2 = (tmpv * (DSBVOLUME_MAX - DSBVOLUME_MIN)) + DSBVOLUME_MIN;
|
||||
chan->SetVolume(v2);
|
||||
}
|
||||
}
|
||||
@ -896,6 +938,8 @@ void WinMusicPlayer::play_sound(AudioTraits::SoundClass* music,
|
||||
initialize();
|
||||
if (!audio_is_active)
|
||||
return;
|
||||
if (!AudioManager::get_music_active())
|
||||
return;
|
||||
WinMusic* wmusic = (WinMusic*)music;
|
||||
IDirectMusicPerformance* _perf = wmusic->get_performance();
|
||||
IDirectMusicSegment* _msc = wmusic->get_music();
|
||||
@ -935,6 +979,8 @@ void WinMusicPlayer::stop_sound(AudioTraits::SoundClass* music,
|
||||
IDirectMusicPerformance* _perf = wmusic->get_performance();
|
||||
IDirectMusicSegment* _msc = wmusic->get_music();
|
||||
|
||||
if (!AudioManager::get_music_active())
|
||||
return;
|
||||
if (_perf && _msc) {
|
||||
HRESULT result = _perf->Stop(_msc, 0, 0, 0);
|
||||
if (result != S_OK)
|
||||
@ -947,8 +993,26 @@ void WinMusicPlayer::set_volume(AudioTraits::PlayingClass* play, float v) {
|
||||
audio_cat->debug() << "WinMusicPlayer::set_volume()" << endl;
|
||||
WinMusicPlaying* wplay = (WinMusicPlaying*)play;
|
||||
IDirectMusicPerformance* perf = wplay->get_performance();
|
||||
float tmpv = v * AudioManager::get_master_music_volume();
|
||||
if (!AudioManager::get_music_active())
|
||||
return;
|
||||
if (perf) {
|
||||
LONG v2 = (v * (DSBVOLUME_MAX - DSBVOLUME_MIN)) + DSBVOLUME_MIN;
|
||||
LONG v2 = (tmpv * (DSBVOLUME_MAX - DSBVOLUME_MIN)) + DSBVOLUME_MIN;
|
||||
perf->SetGlobalParam(GUID_PerfMasterVolume, &v2, sizeof(LONG));
|
||||
}
|
||||
play->set_volume(v);
|
||||
}
|
||||
|
||||
void WinMusicPlayer::adjust_volume(AudioTraits::PlayingClass* play) {
|
||||
if (audio_cat->is_debug())
|
||||
audio_cat->debug() << "WinMusicPlayer::adjust_volume()" << endl;
|
||||
WinMusicPlaying* wplay = (WinMusicPlaying*)play;
|
||||
IDirectMusicPerformance* perf = wplay->get_performance();
|
||||
float tmpv = play->get_volume() * AudioManager::get_master_music_volume();
|
||||
if (!AudioManager::get_music_active())
|
||||
return;
|
||||
if (perf) {
|
||||
LONG v2 = (tmpv * (DSBVOLUME_MAX - DSBVOLUME_MIN)) + DSBVOLUME_MIN;
|
||||
perf->SetGlobalParam(GUID_PerfMasterVolume, &v2, sizeof(LONG));
|
||||
}
|
||||
}
|
||||
|
@ -100,6 +100,7 @@ public:
|
||||
virtual void stop_sound(AudioTraits::SoundClass*,
|
||||
AudioTraits::PlayingClass*);
|
||||
virtual void set_volume(AudioTraits::PlayingClass*, float);
|
||||
virtual void adjust_volume(AudioTraits::PlayingClass*);
|
||||
public:
|
||||
// used by the readers
|
||||
static WinSamplePlayer* get_instance(void);
|
||||
@ -117,6 +118,7 @@ public:
|
||||
virtual void stop_sound(AudioTraits::SoundClass*,
|
||||
AudioTraits::PlayingClass*);
|
||||
virtual void set_volume(AudioTraits::PlayingClass*, float);
|
||||
virtual void adjust_volume(AudioTraits::PlayingClass*);
|
||||
public:
|
||||
// used by the readers
|
||||
static WinMusicPlayer* get_instance(void);
|
||||
|
@ -22,6 +22,12 @@ string* audio_device;
|
||||
int audio_auto_update_delay = config_audio.GetInt("audio-auto-update-delay",
|
||||
1000000);
|
||||
bool audio_is_active = config_audio.GetBool("audio-is-active", true);
|
||||
bool audio_sfx_active = config_audio.GetBool("audio-sfx-active", true);
|
||||
bool audio_music_active = config_audio.GetBool("audio-music-active", true);
|
||||
float audio_master_sfx_volume =
|
||||
config_audio.GetFloat("audio-master-sfx-volume", 1.);
|
||||
float audio_master_music_volume =
|
||||
config_audio.GetFloat("audio-master-music-volume", 1.);
|
||||
int audio_thread_priority;
|
||||
|
||||
ConfigureFn(config_audio) {
|
||||
|
@ -20,6 +20,10 @@ extern EXPCL_PANDA int audio_buffer_size;
|
||||
extern EXPCL_PANDA string* audio_device;
|
||||
extern EXPCL_PANDA int audio_auto_update_delay;
|
||||
extern EXPCL_PANDA bool audio_is_active;
|
||||
extern EXPCL_PANDA bool audio_sfx_active;
|
||||
extern EXPCL_PANDA bool audio_music_active;
|
||||
extern EXPCL_PANDA float audio_master_sfx_volume;
|
||||
extern EXPCL_PANDA float audio_master_music_volume;
|
||||
extern EXPCL_PANDA int audio_thread_priority;
|
||||
|
||||
extern EXPCL_PANDA void audio_load_loaders(void);
|
||||
|
Loading…
x
Reference in New Issue
Block a user