-
Notifications
You must be signed in to change notification settings - Fork 7
/
base.sfx.soundmanager.rtaudio.bmx
executable file
·223 lines (164 loc) · 5.15 KB
/
base.sfx.soundmanager.rtaudio.bmx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
SuperStrict
Import brl.Map
Import brl.WAVLoader
'Import brl.OGGLoader
'the needed module files are located in "external/maxmod2_lite.mod.zip"
Import MaxMod2.ogg
Import MaxMod2.rtaudio
'Import MaxMod2.rtaudionopulse
Import MaxMod2.WAV
'MaxModVerbose True
Import "base.sfx.soundmanager.base.bmx"
Type TSoundManager_RtAudio Extends TSoundManager
Function Create:TSoundManager_RtAudio()
Local manager:TSoundManager_RtAudio = New TSoundManager_RtAudio
SetAudioDriver("RtAudio")
'initialize sound system
If audioEngineEnabled Then manager.InitAudioEngine()
manager.defaultSfxDynamicSettings = TSfxSettings.Create()
Return manager
End Function
Function GetInstance:TSoundManager_RtAudio()
If Not TSoundManager_RtAudio(instance) Then instance = TSoundManager_RtAudio.Create()
Return TSoundManager_RtAudio(instance)
End Function
Method FillAudioEngines:Int()
engineKeys = ["AUTOMATIC", "NONE"]
engineNames = ["Automatic", "None"]
engineDriverNames = ["AUTOMATIC", "NONE"]
?linux
engineKeys :+ ["LINUX_ALSA", "LINUX_PULSE", "LINUX_OSS"]
engineDriverNames :+ ["LINUX_ALSA", "LINUX_PULSE", "LINUX_OSS"]
engineNames :+ ["ALSA", "PulseAudio", "OSS"]
?MacOS
engineKeys :+ ["MACOSX_CORE"]
engineDriverNames :+ ["MACOSX_CORE"]
engineNames :+ ["CoreAudio"]
?Win32
engineKeys :+ ["WINDOWS_ASIO", "WINDOWS_DS"]
engineDriverNames :+ ["WINDOWS_ASIO", "WINDOWS_DS"]
engineNames :+ ["ASIO", "DirectSound"]
?
End Method
Method InitSpecificAudioEngine:Int(engine:String)
TMaxModRtAudioDriver.Init(engine)
'
If Not SetAudioDriver("MaxMod RtAudio")
If engine = audioEngine
TLogger.Log("SoundManager.SetAudioEngine()", "audio engine ~q"+engine+"~q (configured) failed.", LOG_ERROR)
Else
TLogger.Log("SoundManager.SetAudioEngine()", "audio engine ~q"+engine+"~q failed.", LOG_ERROR)
EndIf
Return False
Else
SetAudioStreamDriver("MaxMod RtAudio")
Return True
EndIf
End Method
Method InitAudioEngine:Int()
'reenable rtAudio-messages
TMaxModRtAudioDriver.showWarnings(False)
Super.InitAudioEngine()
'reenable rtAudio-messages
TMaxModRtAudioDriver.showWarnings(True)
Return True
End Method
Method CreateDigAudioStreamOgg:TDigAudioStream(uri:String, loop:Int)
Return New TDigAudioStream_RtAudio_Ogg.CreateWithFile(uri, loop)
End Method
End Type
'===== CONVENIENCE ACCESSORS =====
'convenience instance getter
Function GetSoundManager:TSoundManager()
Return TSoundManager_RtAudio.GetInstance()
End Function
'type to store music files (ogg) in it
'(no longer) data is stored in bank
'Play-Method is adopted from maxmod2.bmx-Function "play"
Type TDigAudioStream_RtAudio Extends TDigAudioStream
'Field bank:TBank
Field url:String
Field volume:Float = 1.0
Field channel:TChannel
Function Create:TDigAudioStream_RtAudio(url:Object, loop:Int=False)
Local obj:TDigAudioStream_RtAudio = New TDigAudioStream_RtAudio
'obj.bank = LoadBank(url)
obj.loop = loop
obj.url = "unknown"
If String(url) Then obj.url=String(url)
Return obj
End Function
'override
Method Clone:TDigAudioStream_RtAudio(deepClone:Int = False)
Local c:TDigAudioStream_RtAudio = New TDigAudioStream_RtAudio
'c.bank = Self.bank
c.loop = Self.loop
c.url = Self.url
Return c
End Method
Method isValid:Int()
If url
Return FileType(url) <> 1
Else
Return False
EndIf
'If Not Self.bank Then Return False
'Return True
End Method
Method CreateChannel:TChannel(volume:Float)
Self.volume = volume
'just return the channel
' return GetChannel()
If Not url Then Throw "no url to play"
channel = CueMusic(Self.url, loop)
If Not channel
Throw "TDigAudioStream.GetChannel() failed to CueMusic"
EndIf
lastChannelTime = Time.MillisecsLong()
SetPlaying(True)
channel.SetVolume(volume)
SetLoopedPlaytime( GetChannelLength(channel, MM_MILLISECS) )
Return channel
End Method
Method GetChannel:TChannel()
If Not url Then Throw "no url to play"
Local channel:TChannel = CueMusic(Self.url, loop)
If Not channel
Throw "TDigAudioStream_RtAudio.GetChannel() failed to CueMusic"
EndIf
lastChannelTime = Time.MillisecsLong()
SetPlaying(True)
channel.SetVolume(volume)
Return channel
End Method
'returns time left in milliseconds
Method GetTimeLeft:Int()
Return GetTimeTotal() - GetTimePlayed()
End Method
'returns time of a track in milliseconds
Method GetTimeTotal:Int()
If Not channel Then Return 0
Return GetChannelLength(channel, MM_MILLISECS)
End Method
'returns time left in milliseconds
Method GetTimePlayed:Int()
If Not channel Then Return 0
Return maxmod2.maxmod2.GetChannelPosition(channel, MM_MILLISECS)
End Method
End Type
Type TDigAudioStream_RtAudio_Ogg Extends TDigAudioStream_RtAudio
Method CreateWithFile:TDigAudioStream_RtAudio_Ogg(url:Object, loop:Int = False, useMemoryStream:Int = False)
'Self.bank = LoadBank(url)
Self.loop = loop
Self.url = "unknown"
If String(url) Then Self.url=String(url)
Return Self
End Method
Method Clone:TDigAudioStream_RtAudio_Ogg(deepClone:Int = False)
Local c:TDigAudioStream_RtAudio_Ogg = New TDigAudioStream_RtAudio_Ogg
'c.bank = Self.bank
c.loop = Self.loop
c.url = Self.url
Return c
End Method
End Type