diff --git a/panda/src/audiotraits/Sources.pp b/panda/src/audiotraits/Sources.pp new file mode 100644 index 0000000000..bed9654905 --- /dev/null +++ b/panda/src/audiotraits/Sources.pp @@ -0,0 +1,32 @@ +#define OTHER_LIBS dtoolconfig dtool +#define DIRECTORY_IF_AUDIO yes + +#begin lib_target + #define USE_RAD_MSS yes + #define TARGET miles_audio + #define BUILDING_DLL BUILDING_MILES_AUDIO + #define LOCAL_LIBS audio + + #define SOURCES \ + config_milesAudio.cxx config_milesAudio.h \ + milesAudioManager.cxx milesAudioManager.h \ + milesAudioSound.I milesAudioSound.cxx milesAudioSound.h + +#end lib_target + +//#begin lib_target +// #define TARGET audio_linux +// #define BUILDING_DLL BUILDING_MISC +// //#define LOCAL_LIBS \ +// // audio +// +// #define SOURCES \ +// $[if $[HAVE_SYS_SOUNDCARD_H], \ +// linuxAudioManager.cxx linuxAudioManager.h \ +// linuxAudioSound.cxx linuxAudioSound.h \ +// , \ +// nullAudioManager.cxx nullAudioManager.h \ +// nullAudioSound.cxx nullAudioSound.h \ +// ] +// +//#end lib_target diff --git a/panda/src/audiotraits/config_milesAudio.cxx b/panda/src/audiotraits/config_milesAudio.cxx new file mode 100644 index 0000000000..55068885d3 --- /dev/null +++ b/panda/src/audiotraits/config_milesAudio.cxx @@ -0,0 +1,60 @@ +// Filename: config_milesAudio.cxx +// Created by: skyler +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://www.panda3d.org/license.txt . +// +// To contact the maintainers of this program write to +// panda3d@yahoogroups.com . +// +//////////////////////////////////////////////////////////////////// + +#include "config_milesAudio.h" +#include "milesAudioManager.h" +#include "milesAudioSound.h" +#include "dconfig.h" + +ConfigureDef(config_milesAudio); +NotifyCategoryDef(milesAudio, ""); + +ConfigureFn(config_milesAudio) { + init_libMilesAudio(); +} +/* +const float LinearIntegrator::_max_linear_dt = + config_milesAudio.GetFloat("default_max_linear_dt", 1.0f / 30.0f); + +const float AngularIntegrator::_max_angular_dt = + config_milesAudio.GetFloat("default_max_angular_dt", 1.0f / 30.0f); + +int LinearNoiseForce::_random_seed = + config_milesAudio.GetInt("default_noise_force_seed", 665); + +const float milesAudioObject::_default_terminal_velocity = + config_milesAudio.GetFloat("default_terminal_velocity", 400.0f);*/ + +//////////////////////////////////////////////////////////////////// +// Function: init_libMilesAudio +// Description: Initializes the library. This must be called at +// least once before any of the functions or classes in +// this library can be used. Normally it will be +// called by the static initializers and need not be +// called explicitly, but special cases exist. +//////////////////////////////////////////////////////////////////// +void +init_libMilesAudio() { + static bool initialized = false; + if (initialized) { + return; + } + initialized = true; + + AudioManager::register_AudioManager_creator(Create_AudioManager); +} diff --git a/panda/src/audiotraits/config_milesAudio.h b/panda/src/audiotraits/config_milesAudio.h new file mode 100644 index 0000000000..4e71f14576 --- /dev/null +++ b/panda/src/audiotraits/config_milesAudio.h @@ -0,0 +1,31 @@ +// Filename: config_milesAudio.h +// Created by: skyler +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://www.panda3d.org/license.txt . +// +// To contact the maintainers of this program write to +// panda3d@yahoogroups.com . +// +//////////////////////////////////////////////////////////////////// + +#ifndef CONFIG_MILESAUDIO_H +#define CONFIG_MILESAUDIO_H + +#include "pandabase.h" +#include "notifyCategoryProxy.h" +#include "dconfig.h" + +ConfigureDecl(config_milesAudio, EXPCL_MILES_AUDIO, EXPTP_MILES_AUDIO); +NotifyCategoryDecl(milesAudio, EXPCL_MILES_AUDIO, EXPTP_MILES_AUDIO); + +extern EXPCL_MILES_AUDIO void init_libMilesAudio(); + +#endif // CONFIG_MILESAUDIO_H diff --git a/panda/src/audiotraits/milesAudioManager.cxx b/panda/src/audiotraits/milesAudioManager.cxx new file mode 100644 index 0000000000..04c10c03c7 --- /dev/null +++ b/panda/src/audiotraits/milesAudioManager.cxx @@ -0,0 +1,282 @@ +// Filename: milesAudioManager.cxx +// Created by: skyler (June 6, 2001) +// Prior system by: cary +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://www.panda3d.org/license.txt . +// +// To contact the maintainers of this program write to +// panda3d@yahoogroups.com . +// +//////////////////////////////////////////////////////////////////// + +#include "pandabase.h" +#ifdef HAVE_RAD_MSS //[ + +#include "milesAudioManager.h" +#include "config_audio.h" +#include "config_util.h" + +int MilesAudioManager::_active_managers; +HDLSFILEID MilesAudioManager::_dls_field; + +AudioManager* Create_AudioManager() { + audio_debug("Create_AudioManger()"); + return new MilesAudioManager(); +} + + +//////////////////////////////////////////////////////////////////// +// Function: MilesAudioManager::MilesAudioManager +// Access: Public +// Description: set the overall volume of SFX +//////////////////////////////////////////////////////////////////// +MilesAudioManager:: +MilesAudioManager() { + audio_debug("MilesAudioManager::MilesAudioManager()"); + audio_debug(" audio_active="<c_str(), 0); + if (!_dls_field) { + audio_error(" AIL_DLS_load_memory() failed, \""<second); + } + _sounds.clear(); + --_active_managers; + if (!_active_managers) { + if (audio_software_midi) { + HDLSDEVICE dls; + AIL_quick_handles(0, 0, &dls); + AIL_DLS_unload(dls, _dls_field); + #ifndef NDEBUG //[ + // Clear _dls_field in debug version (for assert in ctor): + _dls_field=0; + #endif //] + } + AIL_quick_shutdown(); + audio_debug(" AIL_quick_shutdown()"); + } +} + +//////////////////////////////////////////////////////////////////// +// Function: MilesAudioManager::load +// Access: +// Description: +//////////////////////////////////////////////////////////////////// +HAUDIO MilesAudioManager:: +load(Filename file_name) { + string stmp = file_name.to_os_specific(); + audio_debug(" \"" << stmp << "\""); + HAUDIO audio = AIL_quick_load(stmp.c_str()); + if (!audio) { + audio_debug(" MilesAudioManager::load failed "< ib + =_sounds.insert(pair(path, audio)); + if (!ib.second) { + // The insert failed. + audio_debug(" failed map insert of "<set_active(_active); + _soundsOnLoan.insert(milesAudioSound); + audioSound=milesAudioSound; + } + audio_debug(" returning 0x" << (void*)audioSound); + return audioSound; +} + +//////////////////////////////////////////////////////////////////// +// Function: MilesAudioManager::drop_sound +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void MilesAudioManager:: +drop_sound(const string& file_name) { + audio_debug("MilesAudioManager::drop_sound(file_name=\"" + <second); + _sounds.erase(i); + } +} + +//////////////////////////////////////////////////////////////////// +// Function: MilesAudioManager::release_sound +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void MilesAudioManager:: +release_sound(MilesAudioSound* audioSound) { + audio_debug("MilesAudioManager::release_sound(audioSound=\"" + <get_name()<<"\""); + _soundsOnLoan.erase(audioSound); +} + +//////////////////////////////////////////////////////////////////// +// Function: MilesAudioManager::set_volume +// Access: Public +// Description: set the overall volume +//////////////////////////////////////////////////////////////////// +void MilesAudioManager:: +set_volume(float volume) { + audio_debug("MilesAudioManager::set_volume(volume="< +#ifdef HAVE_RAD_MSS //[ + +#include "audioManager.h" +#include "milesAudioSound.h" + +class EXPCL_MILES_AUDIO MilesAudioManager: public AudioManager { +public: + MilesAudioManager(); + ~MilesAudioManager(); + + AudioSound* get_sound(const string& file_name); + void drop_sound(const string& file_name); + + void set_volume(float volume); + float get_volume(); + + void set_active(bool active); + bool get_active(); + +private: + typedef pmap SoundMap; + SoundMap _sounds; + typedef pset AudioSet; + AudioSet _soundsOnLoan; + float _volume; + bool _active; + // keep a count for startup and shutdown: + static int _active_managers; + static HDLSFILEID _dls_field; + + HAUDIO load(Filename file_name); + // Tell the manager that the sound dtor was called. + void release_sound(MilesAudioSound* audioSound); + + friend MilesAudioSound; +}; + +EXPCL_MILES_AUDIO AudioManager* Create_AudioManager(); + + +#endif //] + +#endif //] + + diff --git a/panda/src/audiotraits/milesAudioSound.I b/panda/src/audiotraits/milesAudioSound.I new file mode 100644 index 0000000000..97356eefc4 --- /dev/null +++ b/panda/src/audiotraits/milesAudioSound.I @@ -0,0 +1,24 @@ +// Filename: milesAudioSound.I +// Created by: skyler (June 6, 2001) +// Prior system by: cary +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://www.panda3d.org/license.txt . +// +// To contact the maintainers of this program write to +// panda3d@yahoogroups.com . +// +//////////////////////////////////////////////////////////////////// + + + + + + diff --git a/panda/src/audiotraits/milesAudioSound.cxx b/panda/src/audiotraits/milesAudioSound.cxx new file mode 100644 index 0000000000..1fae55209b --- /dev/null +++ b/panda/src/audiotraits/milesAudioSound.cxx @@ -0,0 +1,224 @@ +// Filename: milesAudioSound.cxx +// Created by: skyler (June 6, 2001) +// Prior system by: cary +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://www.panda3d.org/license.txt . +// +// To contact the maintainers of this program write to +// panda3d@yahoogroups.com . +// +//////////////////////////////////////////////////////////////////// + +#include +#ifdef HAVE_RAD_MSS //[ + +#include "milesAudioSound.h" +#include "milesAudioManager.h" + + +MilesAudioSound:: +MilesAudioSound(MilesAudioManager& manager, + HAUDIO audio, string file_name) + : _manager(manager), _file_name(file_name), + _start_time(0), _volume(1.0), _balance(0), + _loop_count(1), + _active(true), _paused(false) { + nassertv(audio); + nassertv(!file_name.empty()); + audio_debug("MilesAudioSound::MilesAudioSound(manager=0x"<<(void*)&manager + <<", audio=0x"<<(void*)audio<<", file_name="< +#ifdef HAVE_RAD_MSS //[ + +#include "audioSound.h" +#include "mss.h" + + +class MilesAudioManager; + +class EXPCL_MILES_AUDIO MilesAudioSound : public AudioSound { +public: + ~MilesAudioSound(); + + // For best compatability, set the loop_count, start_time, + // volume, and balance, prior to calling play(). You may + // set them while they're playing, but it's implementation + // specific whether you get the results. + void play(); + void stop(); + + // loop: 0 = play once; 1 = play forever. + // inits to false. + void set_loop(bool loop=false); + bool get_loop() const; + + // loop_count: 0 = forever; 1 = play once; n = play n times. + // inits to 1. + void set_loop_count(unsigned long loop_count=1); + unsigned long get_loop_count() const; + + // 0 = begining; length() = end. + // inits to 0.0. + void set_time(float start_time=0.0); + float get_time() const; + + // 0 = minimum; 1.0 = maximum. + // inits to 1.0. + void set_volume(float volume=1.0); + float get_volume() const; + + // -1.0 is hard left + // 0.0 is centered + // 1.0 is hard right + // inits to 0.0. + void set_balance(float balance_right=0.0); + float get_balance() const; + + // inits to manager's state. + void set_active(bool active=true); + bool get_active() const; + + const string& get_name() const; + + // return: playing time in seconds. + float length() const; + + AudioSound::SoundStatus status() const; + +private: + HAUDIO _audio; + MilesAudioManager& _manager; + float _start_time; // 0..length() + float _volume; // 0..1.0 + float _balance; // -1..1 + unsigned long _loop_count; + string _file_name; + bool _active; + bool _paused; + + MilesAudioSound(MilesAudioManager& manager, + HAUDIO audio, string file_name); + + friend class MilesAudioManager; +}; + +#include "milesAudioSound.I" + +#endif //] + +#endif /* __MILES_AUDIO_SOUND_H__ */