X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fsound%2Fsample_group.hxx;h=f87cb1dc10d6ee0a64084a668fd5244f0e164c9b;hb=105438fc581a9b1d65a9309f6e845f9558f3a505;hp=e98596c36f99de06f9c193e8988cfeaf04998ec7;hpb=e2b8a21ff51630ad3c437d5cde927a3879654bd6;p=simgear.git diff --git a/simgear/sound/sample_group.hxx b/simgear/sound/sample_group.hxx index e98596c3..f87cb1dc 100644 --- a/simgear/sound/sample_group.hxx +++ b/simgear/sound/sample_group.hxx @@ -1,47 +1,33 @@ -// sample_group.hxx -- Manage a group of samples relative to a base position +///@file +/// Manage a group of samples relative to a base position +/// +/// Sample groups contain all sounds related to one specific object and +/// have to be added to the sound manager, otherwise they won't get processed. // // Written for the new SoundSystem by Erik Hofman, October 2009 // // Copyright (C) 2009 Erik Hofman // -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of the -// License, or (at your option) any later version. +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Library General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. // -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. +// Library General Public License for more details. // -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software Foundation, -// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -// $Id$ - -/** - * \file sample_group.hxx - * sample groups contain all sounds related to one specific object and - * have to be added to the sound manager, otherwise they won't get processed. - */ +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. #ifndef _SG_SAMPLE_GROUP_OPENAL_HXX #define _SG_SAMPLE_GROUP_OPENAL_HXX 1 -#ifndef __cplusplus -# error This library requires C++ -#endif - -#if defined(__APPLE__) -# include -#elif defined(_WIN32) -# include -#else -# include -#endif #include +#include #include #include @@ -51,11 +37,10 @@ #include #include "sample_openal.hxx" +#include "sample_queue.hxx" -using std::map; -using std::string; -typedef map < string, SGSharedPtr > sample_map; +typedef std::map < std::string, SGSharedPtr > sample_map; typedef sample_map::iterator sample_map_iterator; typedef sample_map::const_iterator const_sample_map_iterator; @@ -78,12 +63,12 @@ public: * @param smgr Pointer to a pre-initialized sound manager class * @param refname Name of this group for reference purposes. */ - SGSampleGroup ( SGSoundMgr *smgr, const string &refname ); + SGSampleGroup ( SGSoundMgr *smgr, const std::string &refname ); /** * Destructor */ - ~SGSampleGroup (); + virtual ~SGSampleGroup (); /** * Set the status of this sample group to active. @@ -104,28 +89,33 @@ public: * @param refname Name of this audio sample for reference purposes * @return return true if successful */ - bool add( SGSoundSample *sound, const string& refname ); + bool add( SGSharedPtr sound, const std::string& refname ); /** * Remove an audio sample from this group. * @param refname Reference name of the audio sample to remove * @return return true if successful */ - bool remove( const string& refname ); + bool remove( const std::string& refname ); /** * Test if a specified audio sample is registered at this sample group * @param refname Reference name of the audio sample to test for * @return true if the specified audio sample exists */ - bool exists( const string& refname ); + bool exists( const std::string& refname ); /** * Find a specified audio sample in this sample group * @param refname Reference name of the audio sample to find * @return A pointer to the SGSoundSample */ - SGSoundSample *find( const string& refname ); + SGSoundSample *find( const std::string& refname ); + + /** + * Stop all playing samples and set the source id to invalid. + */ + void stop(); /** * Request to stop playing all audio samples until further notice. @@ -138,28 +128,28 @@ public: void resume(); /** - * Request to start playing the refered audio sample. + * Request to start playing the referred audio sample. * @param refname Reference name of the audio sample to start playing * @param looping Define if the sound should loop continuously * @return true if the audio sample exsists and is scheduled for playing */ - bool play( const string& refname, bool looping ); + bool play( const std::string& refname, bool looping = false ); /** - * Request to start playing the refered audio sample looping. + * Request to start playing the referred audio sample looping. * @param refname Reference name of the audio sample to start playing * @return true if the audio sample exsists and is scheduled for playing */ - inline bool play_looped( const string& refname ) { + inline bool play_looped( const std::string& refname ) { return play( refname, true ); } /** - * Request to start playing the refered audio sample once. + * Request to start playing the referred audio sample once. * @param refname Reference name of the audio sample to start playing - * @return true if the audio sample exsists and is scheduled for playing + * @return true if the audio sample exists and is scheduled for playing */ - inline bool play_once( const string& refname ) { + inline bool play_once( const std::string& refname ) { return play( refname, false ); } @@ -168,14 +158,14 @@ public: * @param refname Reference name of the audio sample to test for * @return True of the specified sound is currently playing */ - bool is_playing( const string& refname ); + bool is_playing( const std::string& refname ); /** - * Request to stop playing the refered audio sample. + * Request to stop playing the referred audio sample. * @param refname Reference name of the audio sample to stop - * @return true if the audio sample exsists and is scheduled to stop + * @return true if the audio sample exists and is scheduled to stop */ - bool stop( const string& refname ); + bool stop( const std::string& refname ); /** * Set the master volume for this sample group. @@ -185,23 +175,29 @@ public: /** * Set the velocity vector of this sample group. - * This is in the same coordinate system as OpenGL; y=up, z=back, x=right. + * This is in the local frame coordinate system; x=north, y=east, z=down * @param vel Velocity vector */ - void set_velocity( const SGVec3d& vel ); + void set_velocity( const SGVec3d& vel ) { + _velocity = vel; _changed = true; + } /** * Set the position of this sample group. * This is in the same coordinate system as OpenGL; y=up, z=back, x=right. * @param pos Base position */ - void set_position( const SGGeod& pos ); + void set_position_geod( const SGGeod& pos ) { + _base_pos = pos; _changed = true; + } /** * Set the orientation of this sample group. * @param ori Quaternation containing the orientation information */ - void set_orientation( const SGQuatd& ori ); + void set_orientation( const SGQuatd& ori ) { + _orientation = ori; _changed = true; + } /** * Tie this sample group to the listener position, orientation and velocity @@ -210,22 +206,30 @@ public: protected: SGSoundMgr *_smgr; - string _refname; + std::string _refname; bool _active; private: + void cleanup_removed_samples(); + void start_playing_sample(SGSoundSample *sample); + void check_playing_sample(SGSoundSample *sample); + + bool _changed; + bool _pause; float _volume; bool _tied_to_listener; SGVec3d _velocity; + SGGeod _base_pos; SGQuatd _orientation; - SGGeod _position; sample_map _samples; + std::vector< SGSharedPtr > _removed_samples; - bool testForALError(string s); - bool testForError(void *p, string s); + bool testForALError(std::string s); + bool testForError(void *p, std::string s); + void update_pos_and_orientation(); void update_sample_config( SGSoundSample *sound ); };