Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
Sound.cs
浏览该文件的文档.
1using Engine.Media;
2#if BROWSER
3using SourceInteger = Engine.Browser.AL.SourceInteger;
4using SourceBoolean = Engine.Browser.AL.SourceBoolean;
5using SourceVector3 = Engine.Browser.AL.SourceVector3;
6#else
7using Silk.NET.OpenAL;
8#endif
9
10namespace Engine.Audio {
11 public class Sound : BaseSound {
13
15
16 public override void Dispose() {
17 base.Dispose();
18 if (m_soundBuffer != null) {
19 m_soundBuffer.UseCount -= 1;
20 m_soundBuffer = null;
21 }
22 }
23
24 internal void Initialize(SoundBuffer soundBuffer) {
25 ArgumentNullException.ThrowIfNull(soundBuffer);
26 m_soundBuffer = soundBuffer;
27 m_soundBuffer.UseCount += 1;
28 }
29
30 public Sound(SoundBuffer soundBuffer,
31 float volume = 1f,
32 float pitch = 1f,
33 float pan = 0f,
34 bool isLooped = false,
35 bool disposeOnStop = false) {
36 ArgumentNullException.ThrowIfNull(soundBuffer);
38 Mixer.AL.SetSourceProperty((uint)m_source, SourceInteger.Buffer, soundBuffer.m_buffer);
40 }
41 Initialize(soundBuffer);
42 ChannelsCount = soundBuffer.ChannelsCount;
44 Volume = volume;
45 Pitch = pitch;
46 Pan = pan;
47 IsLooped = isLooped;
48 DisposeOnStop = disposeOnStop;
49 Mixer.m_soundsToStopPoll.Add(this);
50 }
51
52 // ReSharper disable once UnusedParameter.Local
53 public Sound(StreamingSource streamingSource,
54 SoundBuffer soundBuffer,
55 float volume = 1f,
56 float pitch = 1f,
57 float pan = 0f,
58 bool isLooped = false,
59 bool disposeOnStop = false) {
60 ArgumentNullException.ThrowIfNull(soundBuffer);
61 Mixer.AL.SetSourceProperty((uint)m_source, SourceInteger.Buffer, soundBuffer.m_buffer);
63 Initialize(soundBuffer);
64 ChannelsCount = soundBuffer.ChannelsCount;
66 Volume = volume;
67 Pitch = pitch;
68 Pan = pan;
69 IsLooped = isLooped;
70 DisposeOnStop = disposeOnStop;
71 Mixer.m_soundsToStopPoll.Add(this);
72 }
73
78 internal override void InternalPlay(Vector3 direction) {
79 if (m_source != 0) {
80 uint source = (uint)m_source;
81 Mixer.AL.SetSourceProperty(source, SourceVector3.Position, direction.X, direction.Y, direction.Z);
82 Mixer.AL.SetSourceProperty(source, SourceBoolean.Looping, m_isLooped);
83 Mixer.AL.SourcePlay(source);
84 }
86 }
87
88 internal override void InternalPause() {
89 if (m_source != 0) {
90 Mixer.AL.SourcePause((uint)m_source);
92 }
93 }
94
95 internal override void InternalStop() {
96 if (m_source != 0) {
97 Mixer.AL.SourceRewind((uint)m_source);
99 }
100 }
101
102 internal override void InternalDispose() {
103 base.InternalDispose();
104 Mixer.m_soundsToStopPoll.Remove(this);
105 }
106 }
107}
static HashSet< Sound > m_soundsToStopPoll
static bool m_isInitialized
static AudioError CheckALError()
void Initialize(SoundBuffer soundBuffer)
override void Dispose()
Sound(StreamingSource streamingSource, SoundBuffer soundBuffer, float volume=1f, float pitch=1f, float pan=0f, bool isLooped=false, bool disposeOnStop=false)
Sound(SoundBuffer soundBuffer, float volume=1f, float pitch=1f, float pan=0f, bool isLooped=false, bool disposeOnStop=false)
override void InternalStop()
SoundBuffer SoundBuffer
SoundBuffer m_soundBuffer
override void InternalPause()
override void InternalPlay(Vector3 direction)
在指定位置播放音频
override void InternalDispose()