Repository navigation
Expand file tree
/
Copy pathBASSMusic3D.nut
More file actions
91 lines (75 loc) · 1.84 KB
/
Copy pathBASSMusic3D.nut
File metadata and controls
91 lines (75 loc) · 1.84 KB
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
class BASSMusic3D {
file = "";
playingTime = 0.0;
volume = 0.0;
looping = false;
radius = 0.0;
coneAngle = 0.0;
reverbLevel = 0.0;
vobTarget = null;
playerTarget = null;
handle = null;
constructor(fileName){
if(!BASS_Init(-1, 44100, BASS_DEVICE_INIT)) {
throw format("Can't initialize BASS with 3D support! (code %d): %s", BASS_ErrorGetCode(), BASS_ErrorGetMessage());
}
BASS_Init(-1, 44000, BASS_DEVICE_INIT);
this.handle = BASS_StreamCreateFile(fileName, 0);
this.file = fileName;
}
function play(){
if(this.handle == 0){
throw format("Can't load file (code %d): %s", BASS_ErrorGetCode(), BASS_ErrorGetMessage());
}
if(this.looping){
BASS_ChannelFlags(this.handle, BASS_SAMPLE_LOOP, BASS_SAMPLE_LOOP);
}
this.apply3DAttributes();
BASS_ChannelPlay(this.handle, true);
}
function stop() {
if(this.handle != null) {
BASS_ChannelStop(this.handle);
}
}
function setVolume(volume) {
if(this.handle != null) {
BASS_ChannelSetAttribute(this.handle, BASS_ATTRIB_VOL, volume / 100.0);
}
}
function isPlaying() {
if(this.handle != null) {
local status = BASS_ChannelIsActive(this.handle);
return status == BASS_ACTIVE_PLAYING;
}
return false;
}
function apply3DAttributes() {
if (this.handle != null) {
BASS_ChannelSet3DAttributes(
this.handle,
-1,
this.radius > 0 ? 0 : this.radius,
this.radius,
this.coneAngle,
-1,
this.reverbLevel
);
}
}
function setVobTarget(vob){
this.vobTarget = vob;
setTargetVob(vob);
}
function setPlayerTarget(playerId){
this.playerTarget = playerId;
setTargetPlayer(playerId);
}
function release() {
if(this.handle != null) {
BASS_StreamFree(this.handle);
this.handle = null;
}
BASS_Free();
}
}