DDraceNetwork Docs
sound.h
Go to the documentation of this file.
1/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2/* If you are missing that file, acquire a complete release at teeworlds.com. */
3#ifndef ENGINE_SOUND_H
4#define ENGINE_SOUND_H
5
6#include <engine/kernel.h>
7#include <engine/storage.h>
8
9#include <base/vmath.h>
10
11class ISound : public IInterface
12{
13 MACRO_INTERFACE("sound")
14public:
15 enum
16 {
17 FLAG_LOOP = 1 << 0,
18 FLAG_POS = 1 << 1,
20 FLAG_PREVIEW = 1 << 3,
22 };
23
24 enum
25 {
28 };
29
30 // unused
32 {
34 };
35
37 {
38 float m_Radius;
39 };
40
42 {
43 float m_Width;
44 float m_Height;
45 };
46
48 {
49 friend class ISound;
50 int m_Id;
51 int m_Age;
52
53 public:
55 m_Id(-1), m_Age(-1)
56 {
57 }
58
59 bool IsValid() const { return (Id() >= 0) && (Age() >= 0); }
60 int Id() const { return m_Id; }
61 int Age() const { return m_Age; }
62
63 bool operator==(const CVoiceHandle &Other) const { return m_Id == Other.m_Id && m_Age == Other.m_Age; }
64 };
65
66 virtual bool IsSoundEnabled() = 0;
67
68 virtual int LoadOpus(const char *pFilename, int StorageType = IStorage::TYPE_ALL) = 0;
69 virtual int LoadWV(const char *pFilename, int StorageType = IStorage::TYPE_ALL) = 0;
70 virtual int LoadOpusFromMem(const void *pData, unsigned DataSize, bool ForceLoad = false) = 0;
71 virtual int LoadWVFromMem(const void *pData, unsigned DataSize, bool ForceLoad = false) = 0;
72 virtual void UnloadSample(int SampleId) = 0;
73
74 virtual float GetSampleTotalTime(int SampleId) = 0; // in s
75 virtual float GetSampleCurrentTime(int SampleId) = 0; // in s
76 virtual void SetSampleCurrentTime(int SampleId, float Time) = 0;
77
78 virtual void SetChannel(int ChannelId, float Volume, float Panning) = 0;
79 virtual void SetListenerPosition(vec2 Position) = 0;
80
81 virtual void SetVoiceVolume(CVoiceHandle Voice, float Volume) = 0;
82 virtual void SetVoiceFalloff(CVoiceHandle Voice, float Falloff) = 0;
83 virtual void SetVoicePosition(CVoiceHandle Voice, vec2 Position) = 0;
84 virtual void SetVoiceTimeOffset(CVoiceHandle Voice, float TimeOffset) = 0; // in s
85
86 virtual void SetVoiceCircle(CVoiceHandle Voice, float Radius) = 0;
87 virtual void SetVoiceRectangle(CVoiceHandle Voice, float Width, float Height) = 0;
88
89 virtual CVoiceHandle PlayAt(int ChannelId, int SampleId, int Flags, float Volume, vec2 Position) = 0;
90 virtual CVoiceHandle Play(int ChannelId, int SampleId, int Flags, float Volume) = 0;
91 virtual void Pause(int SampleId) = 0;
92 virtual void Stop(int SampleId) = 0;
93 virtual void StopAll() = 0;
94 virtual void StopVoice(CVoiceHandle Voice) = 0;
95 virtual bool IsPlaying(int SampleId) = 0;
96
97 virtual int MixingRate() const = 0;
98 virtual void Mix(short *pFinalOut, unsigned Frames) = 0;
99
100 // useful for thread synchronization
101 virtual void PauseAudioDevice() = 0;
102 virtual void UnpauseAudioDevice() = 0;
103
104protected:
105 inline CVoiceHandle CreateVoiceHandle(int Index, int Age)
106 {
107 CVoiceHandle Voice;
108 Voice.m_Id = Index;
109 Voice.m_Age = Age;
110 return Voice;
111 }
112};
113
114class IEngineSound : public ISound
115{
116 MACRO_INTERFACE("enginesound")
117public:
118 virtual int Init() = 0;
119 virtual int Update() = 0;
120 virtual void Shutdown() override = 0;
121};
122
124
125#endif
Definition: sound.h:115
virtual int Init()=0
virtual void Shutdown() override=0
virtual int Update()=0
Definition: kernel.h:10
Definition: sound.h:48
CVoiceHandle()
Definition: sound.h:54
int m_Age
Definition: sound.h:51
int Id() const
Definition: sound.h:60
int Age() const
Definition: sound.h:61
bool operator==(const CVoiceHandle &Other) const
Definition: sound.h:63
int m_Id
Definition: sound.h:50
bool IsValid() const
Definition: sound.h:59
Definition: sound.h:12
virtual void UnloadSample(int SampleId)=0
virtual CVoiceHandle PlayAt(int ChannelId, int SampleId, int Flags, float Volume, vec2 Position)=0
virtual void StopAll()=0
virtual int LoadWVFromMem(const void *pData, unsigned DataSize, bool ForceLoad=false)=0
virtual void SetVoiceFalloff(CVoiceHandle Voice, float Falloff)=0
virtual void SetVoiceVolume(CVoiceHandle Voice, float Volume)=0
virtual void Pause(int SampleId)=0
virtual void UnpauseAudioDevice()=0
virtual void SetVoiceTimeOffset(CVoiceHandle Voice, float TimeOffset)=0
CVoiceHandle CreateVoiceHandle(int Index, int Age)
Definition: sound.h:105
@ FLAG_LOOP
Definition: sound.h:17
@ FLAG_POS
Definition: sound.h:18
@ FLAG_NO_PANNING
Definition: sound.h:19
@ FLAG_PREVIEW
Definition: sound.h:20
@ FLAG_ALL
Definition: sound.h:21
virtual bool IsPlaying(int SampleId)=0
virtual void Mix(short *pFinalOut, unsigned Frames)=0
virtual int LoadWV(const char *pFilename, int StorageType=IStorage::TYPE_ALL)=0
virtual int MixingRate() const =0
virtual void SetVoiceRectangle(CVoiceHandle Voice, float Width, float Height)=0
virtual CVoiceHandle Play(int ChannelId, int SampleId, int Flags, float Volume)=0
virtual void SetVoicePosition(CVoiceHandle Voice, vec2 Position)=0
@ SHAPE_RECTANGLE
Definition: sound.h:27
@ SHAPE_CIRCLE
Definition: sound.h:26
virtual int LoadOpusFromMem(const void *pData, unsigned DataSize, bool ForceLoad=false)=0
virtual void StopVoice(CVoiceHandle Voice)=0
virtual int LoadOpus(const char *pFilename, int StorageType=IStorage::TYPE_ALL)=0
virtual void Stop(int SampleId)=0
virtual void SetSampleCurrentTime(int SampleId, float Time)=0
virtual void SetChannel(int ChannelId, float Volume, float Panning)=0
virtual float GetSampleTotalTime(int SampleId)=0
virtual bool IsSoundEnabled()=0
virtual float GetSampleCurrentTime(int SampleId)=0
virtual void SetListenerPosition(vec2 Position)=0
virtual void SetVoiceCircle(CVoiceHandle Voice, float Radius)=0
virtual void PauseAudioDevice()=0
@ TYPE_ALL
Definition: storage.h:26
IEngineSound * CreateEngineSound()
Definition: sound.cpp:984
#define MACRO_INTERFACE(Name)
Definition: kernel.h:25
Definition: sound.h:32
int m_SampleId
Definition: sound.h:33
Definition: sound.h:37
float m_Radius
Definition: sound.h:38
Definition: sound.h:42
float m_Width
Definition: sound.h:43
float m_Height
Definition: sound.h:44