-
Notifications
You must be signed in to change notification settings - Fork 0
/
NRAudio.bas
80 lines (66 loc) · 1.6 KB
/
NRAudio.bas
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
#include "SDL/SDL.bi"
#include "SDL/SDL_mixer.bi"
dim shared music as Mix_Music ptr
music = NULL
dim audio_rate as integer
dim audio_format as Uint16
dim audio_channels as integer
dim audio_buffers as integer
audio_rate = 44100
audio_format = AUDIO_S16
audio_channels = 2
audio_buffers = 4096
SDL_Init(SDL_INIT_AUDIO)
if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)) then
print "Unable to open audio!"
cleaning
end 1
end if
Mix_QuerySpec(@audio_rate, @audio_format, @audio_channels)
declare sub loadMusic(MusicFile as string)
declare sub playSong
sub cycleMusic cdecl ()
dim as short ActualNum, TurnRef
TurnRef = TurnNum - 1
if TurnWIP then
if QueueNextSong = 0 then
QueueNextSong = 1
end if
elseif GameID = 0 OR FileExists("Ambient 1.ogg") = 0 then
loadMusic("Menu")
else
for Cap as byte = 10 to 1 step -1
ActualNum = remainder(TurnRef,Cap) + 1
if FileExists("Ambient "+str(ActualNum)+".ogg") then
loadMusic("Ambient "+str(ActualNum))
exit for
end if
next Cap
end if
end sub
sub playSong
' This begins playing the music
Mix_PlayMusic(music, 0)
/'
' We want to know when our music has stopped playing so we
' can cycle it.
'/
Mix_HookMusicFinished(@cycleMusic)
end sub
sub loadMusic(MusicFile as string)
if (music) then
' Stop the music from playing
Mix_HaltMusic
/'
' Unload the music from memory, since we don't need it
' anymore
'/
Mix_FreeMusic(music)
music = NULL
end if
' Loads up the music, if file exists
if FileExists(MusicFile + ".ogg") then
music = Mix_LoadMUS(MusicFile + ".ogg")
playSong
end if
end sub