00001 #ifndef _SOUNDMANAGER_H_
00002 #define _SOUNDMANAGER_H_ //buy mum pc microphone
00003
00004 #include "TSingleton.h"
00005 #include "IEventListener.h"
00006 #include "SDL.h"
00007
00008 #include <vector>
00009
00010 typedef short int Sint16;
00011 typedef unsigned short int Uint16;
00012 typedef unsigned char Uint8;
00013 typedef unsigned int SoundID;
00014 typedef unsigned int SoundInstanceID;
00015 typedef unsigned int UInt;
00016
00017 class ISound;
00018
00019 class SoundManager : public TSingleton<SoundManager>, public IEventListener
00020 {
00021 public:
00022 SoundManager();
00023 ~SoundManager();
00024
00025 void Initialise(int freq = 44100, Uint16 samples = 1024, Uint8 channels = 1);
00026 void Shutdown();
00027
00028 SoundID CreateSoundSong(const bool &bPreCreate, const UInt &bpm, const UInt &numUniqueSections, const UInt &lengthInSections, const UInt &timePerSection);
00029
00030 SoundInstanceID PlaySoundID(const SoundID &sid, bool loop = false);
00031 bool PauseSound(const SoundInstanceID &siid);
00032 bool StopSound(const SoundInstanceID &siid);
00033
00034 void Update();
00035
00036 void Output();
00037 void IncreaseVolume();
00038 void DecreaseVolume();
00039
00040 void HandleAudioBuffer(void* userdata, Uint8* stream, int len);
00041 SDL_AudioSpec* GetAudioSpec() { return m_pAudioSpec; }
00042
00043 virtual bool HandleEvent(IEvent* pEvent);
00044
00045
00046 static void MixBuffers(Sint16* pBuf1, Sint16* pBuf2, size_t sz);
00047
00048
00049 static void SDLAudioCallback(void *userdata, Uint8 *stream, int len);
00050
00051 protected:
00052 void ApplyVolumeToStream(Sint16* pStream, size_t sz);
00053 struct SoundInstance
00054 {
00055 SoundInstance() : pSound(0), isPaused(true), isLooping(false) {}
00056 ISound* pSound;
00057 bool isPaused;
00058 bool isLooping;
00059 unsigned long position;
00060 };
00061
00062 std::vector<ISound*> m_vSounds;
00063 std::vector<SoundInstance*> m_vInstances;
00064
00065 unsigned long m_lastUpdate;
00066 SDL_AudioSpec* m_pAudioSpec;
00067 int m_volume;
00068 };
00069
00070
00071
00072
00073
00074
00075
00076 #endif