Survivalcraft API 1.8.2.3
v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
BaseSound.cs
浏览该文件的文档.
1
#if BROWSER
2
using
DistanceModelEnum
=
Engine
.
Browser
.
AL
.
DistanceModelEnum
;
3
using
SourceFloat =
Engine
.
Browser
.
AL
.
SourceFloat
;
4
using
SourceVector3 =
Engine
.
Browser
.
AL
.
SourceVector3
;
5
#else
6
using
Silk.NET.OpenAL;
7
using
DistanceModelEnum
= Silk.NET.OpenAL.DistanceModel;
8
#endif
9
10
namespace
Engine.Audio
{
11
public
abstract
class
BaseSound
: IDisposable {
12
float
m_volume
= 1f;
13
14
float
m_pitch
= 1f;
15
16
float
m_pan
;
17
18
internal
object
m_lock
=
new
();
19
20
internal
bool
m_isLooped
;
21
22
internal
bool
m_disposeOnStop
;
23
24
public
int
m_source
;
25
26
public
SoundState
State
{
get
;
set
; }
27
28
public
int
ChannelsCount
{
get
;
set
; }
29
30
public
int
SamplingFrequency
{
get
;
set
; }
31
32
public
float
Volume
{
33
get
=>
m_volume
;
34
set
{
35
value =
MathUtils
.
Saturate
(value);
36
if
(value !=
m_volume
) {
37
m_volume
= value;
38
InternalSetVolume
(value);
39
}
40
}
41
}
42
43
public
float
Pitch
{
44
get
=>
m_pitch
;
45
set
{
46
value = Math.Clamp(value, 0.5f, 2f);
47
if
(value !=
m_pitch
) {
48
m_pitch
= value;
49
InternalSetPitch
(value);
50
}
51
}
52
}
53
54
public
float
Pan
{
55
get
=>
m_pan
;
56
set
{
57
if
(
ChannelsCount
== 1) {
58
value = Math.Clamp(value, -1f, 1f);
59
if
(value !=
m_pan
) {
60
m_pan
= value;
61
InternalSetPan
(value);
62
}
63
}
64
}
65
}
66
67
public
bool
IsLooped
{
68
get
=>
m_isLooped
;
69
set
{
70
lock (
m_lock
) {
71
if
(
State
==
SoundState
.Stopped) {
72
m_isLooped
= value;
73
}
74
}
75
}
76
}
77
78
public
bool
DisposeOnStop
{
79
get
=>
m_disposeOnStop
;
80
set
{
81
lock (
m_lock
) {
82
if
(
State
==
SoundState
.Stopped) {
83
m_disposeOnStop
= value;
84
}
85
}
86
}
87
}
88
89
public
void
Play
() {
90
lock (
m_lock
) {
91
if
(
State
==
SoundState
.Stopped
92
||
State
==
SoundState
.Paused) {
93
State
=
SoundState
.Playing;
94
InternalPlay
(
Vector3
.
Zero
);
95
}
96
}
97
}
98
99
public
void
Play
(
Vector3
direction) {
100
lock (
m_lock
) {
101
if
(
State
==
SoundState
.Stopped
102
||
State
==
SoundState
.Paused) {
103
State
=
SoundState
.Playing;
104
InternalPlay
(direction);
105
}
106
}
107
}
108
109
public
void
Pause
() {
110
lock (
m_lock
) {
111
if
(
State
==
SoundState
.Playing) {
112
State
=
SoundState
.Paused;
113
InternalPause
();
114
}
115
}
116
}
117
118
public
void
Stop
() {
119
if
(
m_disposeOnStop
) {
120
Dispose
();
121
}
122
lock (
m_lock
) {
123
if
(
State
==
SoundState
.Playing
124
||
State
==
SoundState
.Paused) {
125
State
=
SoundState
.Stopped;
126
InternalStop
();
127
}
128
}
129
}
130
131
public
virtual
void
Dispose
() {
132
if
(
State
!=
SoundState
.Disposed) {
133
State
=
SoundState
.Disposed;
134
InternalDispose
();
135
}
136
}
137
138
internal
BaseSound
() {
139
uint source =
Mixer
.
AL
.GenSource();
140
m_source
= (int)source;
141
Mixer
.
CheckALError
();
142
Mixer
.
AL
.DistanceModel(
DistanceModelEnum
.None);
143
Mixer
.
CheckALError
();
144
}
145
146
void
InternalSetVolume
(
float
volume) {
147
if
(
m_source
!= 0) {
148
Mixer
.
AL
.SetSourceProperty((uint)
m_source
, SourceFloat.Gain, volume);
149
Mixer
.
CheckALError
();
150
}
151
}
152
153
void
InternalSetPitch
(
float
pitch) {
154
if
(
m_source
!= 0) {
155
Mixer
.
AL
.SetSourceProperty((uint)
m_source
, SourceFloat.Pitch, pitch);
156
Mixer
.
CheckALError
();
157
}
158
}
159
160
void
InternalSetPan
(
float
pan) {
161
if
(
m_source
!= 0) {
162
float
value = 0f;
163
float
value2 = -0.1f;
164
Mixer
.
AL
.SetSourceProperty((uint)
m_source
, SourceVector3.Position, pan, value, value2);
165
Mixer
.
CheckALError
();
166
}
167
}
168
169
internal
abstract
void
InternalPlay
(
Vector3
direction);
170
internal
abstract
void
InternalPause
();
171
172
internal
abstract
void
InternalStop
();
173
174
internal
virtual
void
InternalDispose
() {
175
if
(
m_source
!= 0) {
176
uint source = (uint)
m_source
;
177
Mixer
.
AL
.SourceStop(source);
178
Mixer
.
CheckALError
();
179
Mixer
.
AL
.DeleteSource(source);
180
Mixer
.
CheckALError
();
181
m_source
= 0;
182
}
183
}
184
}
185
}
DistanceModelEnum
Silk.NET.OpenAL.DistanceModel DistanceModelEnum
定义
BaseSound.cs:7
Engine.Audio.BaseSound.InternalPause
void InternalPause()
Engine.Audio.BaseSound.DisposeOnStop
bool DisposeOnStop
定义
BaseSound.cs:78
Engine.Audio.BaseSound.m_pan
float m_pan
定义
BaseSound.cs:16
Engine.Audio.BaseSound.Stop
void Stop()
定义
BaseSound.cs:118
Engine.Audio.BaseSound.SamplingFrequency
int SamplingFrequency
定义
BaseSound.cs:30
Engine.Audio.BaseSound.m_volume
float m_volume
定义
BaseSound.cs:12
Engine.Audio.BaseSound.ChannelsCount
int ChannelsCount
定义
BaseSound.cs:28
Engine.Audio.BaseSound.Pitch
float Pitch
定义
BaseSound.cs:43
Engine.Audio.BaseSound.InternalSetVolume
void InternalSetVolume(float volume)
定义
BaseSound.cs:146
Engine.Audio.BaseSound.BaseSound
BaseSound()
定义
BaseSound.cs:138
Engine.Audio.BaseSound.m_source
int m_source
定义
BaseSound.cs:24
Engine.Audio.BaseSound.Play
void Play()
定义
BaseSound.cs:89
Engine.Audio.BaseSound.InternalDispose
virtual void InternalDispose()
定义
BaseSound.cs:174
Engine.Audio.BaseSound.IsLooped
bool IsLooped
定义
BaseSound.cs:67
Engine.Audio.BaseSound.m_lock
object m_lock
定义
BaseSound.cs:18
Engine.Audio.BaseSound.m_disposeOnStop
bool m_disposeOnStop
定义
BaseSound.cs:22
Engine.Audio.BaseSound.Play
void Play(Vector3 direction)
定义
BaseSound.cs:99
Engine.Audio.BaseSound.m_isLooped
bool m_isLooped
定义
BaseSound.cs:20
Engine.Audio.BaseSound.Pause
void Pause()
定义
BaseSound.cs:109
Engine.Audio.BaseSound.InternalPlay
void InternalPlay(Vector3 direction)
Engine.Audio.BaseSound.Dispose
virtual void Dispose()
定义
BaseSound.cs:131
Engine.Audio.BaseSound.Volume
float Volume
定义
BaseSound.cs:32
Engine.Audio.BaseSound.InternalSetPan
void InternalSetPan(float pan)
定义
BaseSound.cs:160
Engine.Audio.BaseSound.InternalStop
void InternalStop()
Engine.Audio.BaseSound.InternalSetPitch
void InternalSetPitch(float pitch)
定义
BaseSound.cs:153
Engine.Audio.BaseSound.Pan
float Pan
定义
BaseSound.cs:54
Engine.Audio.BaseSound.m_pitch
float m_pitch
定义
BaseSound.cs:14
Engine.Audio.BaseSound.State
SoundState State
定义
BaseSound.cs:26
Engine.Audio.Mixer
定义
Mixer.cs:13
Engine.Audio.Mixer.CheckALError
static AudioError CheckALError()
定义
Mixer.cs:102
Engine.Audio.Mixer.AL
static AL AL
定义
Mixer.cs:14
Engine.Browser.AL
定义
AL.cs:2
Engine.Browser.AL.DistanceModelEnum
DistanceModelEnum
定义
AL.cs:56
Engine.Browser.AL.SourceVector3
SourceVector3
定义
AL.cs:27
Engine.Browser.AL.SourceFloat
SourceFloat
定义
AL.cs:13
Engine.MathUtils
定义
MathUtils.cs:2
Engine.MathUtils.Saturate
static float Saturate(float x)
定义
MathUtils.cs:163
Engine.Audio
定义
BaseSound.cs:10
Engine.Audio.SoundState
SoundState
定义
SoundState.cs:2
Engine.Browser
定义
AL.cs:1
Engine
定义
BaseSound.cs:10
Engine.Vector3
定义
Vector3.cs:2
Engine.Vector3.Zero
static readonly Vector3 Zero
定义
Vector3.cs:9
SurvivalcraftApi 1.8.2.3
Engine
Engine.Audio
BaseSound.cs
制作者
1.16.1