2002-12-13 07:44:34 +00:00
|
|
|
#ifndef RAGE_SOUND_MANAGER_H
|
|
|
|
|
#define RAGE_SOUND_MANAGER_H
|
|
|
|
|
|
|
|
|
|
#include <set>
|
2002-12-21 02:19:37 +00:00
|
|
|
#include <map>
|
2003-02-14 22:50:38 +00:00
|
|
|
#include "SDL_utils.h"
|
2002-12-13 07:44:34 +00:00
|
|
|
#include "RageThreads.h"
|
|
|
|
|
|
|
|
|
|
class RageSound;
|
2004-01-15 02:33:41 +00:00
|
|
|
class RageSoundBase;
|
2003-04-23 19:49:51 +00:00
|
|
|
class RageSoundDriver;
|
2002-12-13 07:44:34 +00:00
|
|
|
|
|
|
|
|
class RageSoundManager
|
|
|
|
|
{
|
|
|
|
|
/* Set of sounds that we've taken over (and are responsible for deleting
|
|
|
|
|
* when they're finished playing): */
|
2004-01-15 03:12:18 +00:00
|
|
|
set<RageSoundBase *> owned_sounds;
|
2002-12-13 07:44:34 +00:00
|
|
|
|
|
|
|
|
/* Set of sounds that are finished and should be deleted. */
|
2004-01-15 02:33:41 +00:00
|
|
|
set<RageSoundBase *> sounds_to_delete;
|
2002-12-13 07:44:34 +00:00
|
|
|
|
|
|
|
|
RageSoundDriver *driver;
|
|
|
|
|
|
2003-01-19 19:55:24 +00:00
|
|
|
/* Prefs: */
|
|
|
|
|
float MixVolume;
|
|
|
|
|
|
2002-12-13 07:44:34 +00:00
|
|
|
public:
|
|
|
|
|
RageMutex lock;
|
|
|
|
|
|
2002-12-13 08:31:39 +00:00
|
|
|
RageSoundManager(CString drivers);
|
2002-12-13 07:44:34 +00:00
|
|
|
~RageSoundManager();
|
|
|
|
|
|
2003-01-19 19:55:24 +00:00
|
|
|
float GetMixVolume() const { return MixVolume; }
|
|
|
|
|
void SetPrefs(float MixVol);
|
|
|
|
|
|
2002-12-13 07:44:34 +00:00
|
|
|
void Update(float delta);
|
2004-01-15 03:12:18 +00:00
|
|
|
void StartMixing( RageSoundBase *snd ); /* used by RageSoundBase */
|
|
|
|
|
void StopMixing( RageSoundBase *snd ); /* used by RageSoundBase */
|
|
|
|
|
int GetPosition( const RageSoundBase *snd ) const; /* used by RageSoundBase */
|
2002-12-13 07:44:34 +00:00
|
|
|
float GetPlayLatency() const;
|
2004-01-03 02:36:14 +00:00
|
|
|
int GetDriverSampleRate( int rate ) const;
|
2003-09-27 01:47:19 +00:00
|
|
|
const set<RageSound *> &GetPlayingSounds() const { return playing_sounds; }
|
2002-12-13 07:44:34 +00:00
|
|
|
|
|
|
|
|
void PlayOnce( CString sPath );
|
|
|
|
|
|
2002-12-22 08:13:33 +00:00
|
|
|
RageSound *PlaySound(RageSound &snd);
|
|
|
|
|
void StopPlayingSound(RageSound &snd);
|
2004-01-14 08:10:37 +00:00
|
|
|
|
2002-12-13 07:44:34 +00:00
|
|
|
/* A list of all sounds that currently exist. RageSound adds and removes
|
|
|
|
|
* itself to this. */
|
|
|
|
|
set<RageSound *> all_sounds;
|
2004-01-14 08:00:51 +00:00
|
|
|
|
|
|
|
|
/* RageSound adds and removes itself to this. */
|
|
|
|
|
set<RageSound *> playing_sounds;
|
2004-01-14 08:07:42 +00:00
|
|
|
void GetCopies(RageSound &snd, vector<RageSound *> &snds);
|
2002-12-13 08:31:39 +00:00
|
|
|
|
2003-10-22 03:39:52 +00:00
|
|
|
static void AttenuateBuf( Sint16 *buf, int samples, float vol );
|
2002-12-31 01:09:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* This inputs and outputs 16-bit 44khz stereo input. */
|
|
|
|
|
class SoundMixBuffer
|
|
|
|
|
{
|
2003-04-25 19:40:49 +00:00
|
|
|
Sint32 *mixbuf;
|
|
|
|
|
unsigned bufsize; /* actual allocated samples */
|
|
|
|
|
unsigned used; /* used samples */
|
2003-10-21 21:35:58 +00:00
|
|
|
int vol; /* vol * 256 */
|
2002-12-31 01:09:31 +00:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
void write(const Sint16 *buf, unsigned size);
|
|
|
|
|
void read(Sint16 *buf);
|
2004-01-14 22:09:55 +00:00
|
|
|
void read( float *buf );
|
2003-04-25 19:40:49 +00:00
|
|
|
unsigned size() const { return used; }
|
2002-12-31 01:09:31 +00:00
|
|
|
void SetVolume(float f);
|
|
|
|
|
|
|
|
|
|
SoundMixBuffer();
|
2003-04-25 19:40:49 +00:00
|
|
|
~SoundMixBuffer();
|
2002-12-13 07:44:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
extern RageSoundManager *SOUNDMAN;
|
|
|
|
|
|
|
|
|
|
#endif
|