Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

RageSoundManager.h

Go to the documentation of this file.
00001 #ifndef RAGE_SOUND_MANAGER_H 00002 #define RAGE_SOUND_MANAGER_H 00003 00004 #include <set> 00005 #include <map> 00006 #include "RageUtil_CircularBuffer.h" 00007 00008 class RageSound; 00009 class RageSoundBase; 00010 class RageSoundDriver; 00011 struct RageSoundParams; 00012 00013 class RageSoundManager 00014 { 00015 /* Set of sounds that we've taken over (and are responsible for deleting 00016 * when they're finished playing): */ 00017 set<RageSound *> owned_sounds; 00018 00019 /* A list of all sounds that currently exist, by ID. */ 00020 map<int,RageSound *> all_sounds; 00021 00022 RageSoundDriver *driver; 00023 00024 /* Prefs: */ 00025 float MixVolume; 00026 struct queued_pos_map_t 00027 { 00028 int ID, pos, got_frames; 00029 int64_t frameno; 00030 }; 00031 00032 CircBuf<queued_pos_map_t> pos_map_queue; 00033 00034 public: 00035 RageSoundManager(); 00036 ~RageSoundManager(); 00037 00038 /* This may be called when shutting down, in order to stop all sounds. This 00039 * should be called before shutting down threads that may have running sounds, 00040 * in order to prevent DirectSound delays and glitches. Further attempts to 00041 * start sounds will do nothing, and threads may be shut down. */ 00042 void Shutdown(); 00043 00044 void Init( CString drivers ); 00045 00046 float GetMixVolume() const { return MixVolume; } 00047 void SetPrefs(float MixVol); 00048 00049 void Update(float delta); 00050 void StartMixing( RageSoundBase *snd ); /* used by RageSound */ 00051 void StopMixing( RageSoundBase *snd ); /* used by RageSound */ 00052 int64_t GetPosition( const RageSoundBase *snd ) const; /* used by RageSound */ 00053 void RegisterSound( RageSound *p ); /* used by RageSound */ 00054 void UnregisterSound( RageSound *p ); /* used by RageSound */ 00055 int GetUniqueID(); /* used by RageSound */ 00056 void CommitPlayingPosition( int ID, int64_t frameno, int pos, int got_bytes ); /* used by drivers */ 00057 float GetPlayLatency() const; 00058 int GetDriverSampleRate( int rate ) const; 00059 00060 /* When deleting a sound from any thread except the one calling Update(), this 00061 * must be used to prevent race conditions. */ 00062 void DeleteSound( RageSound *p ); 00063 void DeleteSoundWhenFinished( RageSound *pSound ); 00064 00065 void PlayOnce( CString sPath ); 00066 00067 RageSound *PlaySound( RageSound &snd, const RageSoundParams *params = NULL ); 00068 RageSound *PlayCopyOfSound( RageSound &snd, const RageSoundParams *params = NULL ); 00069 00070 static void AttenuateBuf( int16_t *buf, int samples, float vol ); 00071 00072 private: 00073 void FlushPosMapQueue(); 00074 RageSound *GetSoundByID( int ID ); 00075 }; 00076 00077 extern RageSoundManager *SOUNDMAN; 00078 00079 #endif 00080 00081 /* 00082 * Copyright (c) 2002-2004 Glenn Maynard 00083 * All rights reserved. 00084 * 00085 * Permission is hereby granted, free of charge, to any person obtaining a 00086 * copy of this software and associated documentation files (the 00087 * "Software"), to deal in the Software without restriction, including 00088 * without limitation the rights to use, copy, modify, merge, publish, 00089 * distribute, and/or sell copies of the Software, and to permit persons to 00090 * whom the Software is furnished to do so, provided that the above 00091 * copyright notice(s) and this permission notice appear in all copies of 00092 * the Software and that both the above copyright notice(s) and this 00093 * permission notice appear in supporting documentation. 00094 * 00095 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00096 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00097 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF 00098 * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS 00099 * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT 00100 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 00101 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 00102 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 00103 * PERFORMANCE OF THIS SOFTWARE. 00104 */

Generated on Thu Jan 27 20:57:28 2005 for StepMania by doxygen 1.3.7