-
Notifications
You must be signed in to change notification settings - Fork 0
/
win_mp3.cpp
69 lines (53 loc) · 1.14 KB
/
win_mp3.cpp
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
/****************************************************************
xerxes engine
win_mp3.cpp
mp3 playback using amp11lib
****************************************************************/
#include "xerxes.h"
#include "amp11lib.h"
/***************************** data *****************************/
bool amp11lib_open = false;
ALhandle hPlayer = 0, hFile = 0, hDecoder = 0;
/***************************** code *****************************/
void mp3_Close()
{
if (amp11lib_open)
{
alEndLibrary();
amp11lib_open = false;
}
}
void mp3_Init()
{
if (amp11lib_open) return;
alInitLibrary();
hPlayer = alOpenPlayer(-1, 44100, ALtrue, 0.05f);
alEnableRedirection(0.025f);
atexit(mp3_Close);
}
void mp3_Stop()
{
if (hDecoder)
{
alSetRedirection(hDecoder, 0);
alClose(hDecoder); hDecoder = 0;
alClose(hFile); hFile = 0;
}
}
void mp3_Play(char *fn)
{
if (hFile) mp3_Stop();
hFile = alOpenInputFile(fn);
hDecoder = alOpenDecoder(hFile);
alSetRedirection(hDecoder, hPlayer);
}
void mp3_Pause()
{
if (hDecoder)
alSetRedirection(hDecoder, 0);
}
void mp3_Resume()
{
if (hPlayer && hDecoder)
alSetRedirection(hDecoder, hPlayer);
}