-
Notifications
You must be signed in to change notification settings - Fork 1
/
audio.lua
56 lines (52 loc) · 1.48 KB
/
audio.lua
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
local audio = {}
-- Expose only a subset of the love audio api so we can use the same api when exporting a video as well
local property_func_map = {
looping = { "setLooping", "getLooping" },
volume = { "setVolume", "getVolume" },
playing = "isPlaying",
pitch = "getPitch",
play = "play",
stop = "stop",
set_pitch = "setPitch",
seek = "seek",
release = "release",
}
audio.__index = function(t, k)
if rawget(t, k) then
return t[k]
elseif audio[k] then
return audio[k]
elseif property_func_map[k] then
local source = rawget(t, "source")
if type(property_func_map[k]) == "table" then
return function(_, ...)
source[property_func_map[k][2]](source, ...)
end
end
return function(_, ...)
source[property_func_map[k]](source, ...)
end
end
end
audio.__newindex = function(t, k, v)
if property_func_map[k] and type(property_func_map[k]) == "table" then
local source = rawget(t, "source")
source[property_func_map[k][1]](source, v)
else
rawset(t, k, v)
end
end
local function new(filename, read_type)
return setmetatable({
source = love.audio.newSource(filename, read_type),
filename = filename,
playing = false,
}, audio)
end
function audio.new_stream(filename)
return new(filename, "stream")
end
function audio.new_static(filename)
return new(filename, "static")
end
return audio