2010-11-20 10:37:14 +00:00
|
|
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
2010-05-29 07:25:38 +00:00
|
|
|
#ifndef ENGINE_SOUND_H
|
|
|
|
#define ENGINE_SOUND_H
|
|
|
|
|
|
|
|
#include "kernel.h"
|
|
|
|
|
|
|
|
class ISound : public IInterface
|
|
|
|
{
|
|
|
|
MACRO_INTERFACE("sound", 0)
|
|
|
|
public:
|
|
|
|
enum
|
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
FLAG_LOOP = 1 << 0,
|
|
|
|
FLAG_POS = 1 << 1,
|
|
|
|
FLAG_NO_PANNING = 1 << 2,
|
|
|
|
FLAG_ALL = FLAG_LOOP | FLAG_POS | FLAG_NO_PANNING,
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
2014-11-29 13:29:40 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
SHAPE_CIRCLE,
|
|
|
|
SHAPE_RECTANGLE,
|
|
|
|
};
|
|
|
|
|
2020-10-09 07:07:05 +00:00
|
|
|
// unused
|
|
|
|
struct CSampleHandle
|
|
|
|
{
|
|
|
|
int m_SampleID;
|
|
|
|
};
|
|
|
|
|
2014-11-29 13:29:40 +00:00
|
|
|
struct CVoiceShapeCircle
|
|
|
|
{
|
|
|
|
float m_Radius;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CVoiceShapeRectangle
|
|
|
|
{
|
|
|
|
float m_Width;
|
|
|
|
float m_Height;
|
|
|
|
};
|
|
|
|
|
2014-10-12 14:12:13 +00:00
|
|
|
class CVoiceHandle
|
|
|
|
{
|
|
|
|
friend class ISound;
|
|
|
|
int m_Id;
|
|
|
|
int m_Age;
|
2020-09-26 19:41:58 +00:00
|
|
|
|
2014-10-12 14:12:13 +00:00
|
|
|
public:
|
2020-09-26 19:41:58 +00:00
|
|
|
CVoiceHandle() :
|
|
|
|
m_Id(-1), m_Age(-1)
|
|
|
|
{
|
|
|
|
}
|
2014-10-12 14:12:13 +00:00
|
|
|
|
|
|
|
bool IsValid() const { return (Id() >= 0) && (Age() >= 0); }
|
|
|
|
int Id() const { return m_Id; }
|
|
|
|
int Age() const { return m_Age; }
|
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
bool operator==(const CVoiceHandle &Other) const { return m_Id == Other.m_Id && m_Age == Other.m_Age; }
|
2014-10-12 14:12:13 +00:00
|
|
|
};
|
|
|
|
|
2011-06-27 20:57:06 +00:00
|
|
|
virtual bool IsSoundEnabled() = 0;
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual int LoadWV(const char *pFilename) = 0;
|
2014-10-27 15:23:53 +00:00
|
|
|
virtual int LoadOpus(const char *pFilename) = 0;
|
2014-10-24 23:23:39 +00:00
|
|
|
virtual int LoadWVFromMem(const void *pData, unsigned DataSize, bool FromEditor = false) = 0;
|
2014-10-27 15:23:53 +00:00
|
|
|
virtual int LoadOpusFromMem(const void *pData, unsigned DataSize, bool FromEditor = false) = 0;
|
2014-10-11 11:38:08 +00:00
|
|
|
virtual void UnloadSample(int SampleID) = 0;
|
2011-08-11 08:59:14 +00:00
|
|
|
|
2014-10-11 11:55:13 +00:00
|
|
|
virtual float GetSampleDuration(int SampleID) = 0; // in s
|
|
|
|
|
2011-02-12 10:40:36 +00:00
|
|
|
virtual void SetChannel(int ChannelID, float Volume, float Panning) = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void SetListenerPos(float x, float y) = 0;
|
2011-08-11 08:59:14 +00:00
|
|
|
|
2014-10-12 14:12:13 +00:00
|
|
|
virtual void SetVoiceVolume(CVoiceHandle Voice, float Volume) = 0;
|
2014-11-29 13:29:40 +00:00
|
|
|
virtual void SetVoiceFalloff(CVoiceHandle Voice, float Falloff) = 0;
|
2014-10-12 14:12:13 +00:00
|
|
|
virtual void SetVoiceLocation(CVoiceHandle Voice, float x, float y) = 0;
|
2014-10-18 13:21:13 +00:00
|
|
|
virtual void SetVoiceTimeOffset(CVoiceHandle Voice, float offset) = 0; // in s
|
2014-10-11 15:55:22 +00:00
|
|
|
|
2014-11-29 13:29:40 +00:00
|
|
|
virtual void SetVoiceCircle(CVoiceHandle Voice, float Radius) = 0;
|
|
|
|
virtual void SetVoiceRectangle(CVoiceHandle Voice, float Width, float Height) = 0;
|
|
|
|
|
2014-10-12 14:12:13 +00:00
|
|
|
virtual CVoiceHandle PlayAt(int ChannelID, int SampleID, int Flags, float x, float y) = 0;
|
|
|
|
virtual CVoiceHandle Play(int ChannelID, int SampleID, int Flags) = 0;
|
2011-04-13 18:00:54 +00:00
|
|
|
virtual void Stop(int SampleID) = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void StopAll() = 0;
|
2014-10-18 13:21:13 +00:00
|
|
|
virtual void StopVoice(CVoiceHandle Voice) = 0;
|
2014-10-12 14:12:13 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
inline CVoiceHandle CreateVoiceHandle(int Index, int Age)
|
|
|
|
{
|
|
|
|
CVoiceHandle Voice;
|
|
|
|
Voice.m_Id = Index;
|
|
|
|
Voice.m_Age = Age;
|
|
|
|
return Voice;
|
|
|
|
}
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class IEngineSound : public ISound
|
|
|
|
{
|
|
|
|
MACRO_INTERFACE("enginesound", 0)
|
|
|
|
public:
|
|
|
|
virtual int Init() = 0;
|
|
|
|
virtual int Update() = 0;
|
|
|
|
virtual int Shutdown() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern IEngineSound *CreateEngineSound();
|
|
|
|
|
|
|
|
#endif
|