-
Notifications
You must be signed in to change notification settings - Fork 4
/
efx.lua
99 lines (86 loc) · 1.89 KB
/
efx.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
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
local efx = {}
efx.__index = efx
local l = require('lume')
local defaults = {
bandpass = {
volume = 1.0,
type = 'bandpass',
lowgain = 1.0,
highgain = 1.0,
},
reverb = {
volume = 1.0,
type = 'reverb',
decaytime = 1,
},
distortion = {
gain = 0.05,
edge = 0.2,
lowcut = 8000.0,
center = 24000.0,
bandwidth = 36000.0,
type = 'distortion',
},
echo = {
volume = 1.0,
delay = 0.0,
tapdelay = 0.0,
damping = 0.0,
feedback = 0.0,
spread = 0.0,
type = 'echo',
},
tremolo = {
volume = 0.8,
frequency = 440.0,
waveform = 'sine',
highcut = 800.0,
type = 'ringmodulator',
},
flanger = {
waveform = 'triangle',
volume = 1.0,
phase = 0,
rate = 0.27,
depth = 1,
feedback = -0.5,
delay = 0.002,
type = 'flanger',
}
}
function efx.load(trackName)
local self = setmetatable({}, efx)
self.trackName = trackName or 'live'
for name, params in pairs(defaults) do
self[name] = {}
for param, value in pairs(params) do
self[name][param] = value
end
end
self.activeEffects = {}
-- nice to have a bit of reverb
self:addEffect(self.reverb)
return self
end
function efx:effectName(effect)
return self.trackName .. '_' .. effect.type
end
function efx:addEffect(effect)
table.insert(self.activeEffects, effect)
end
function efx:process()
for i,effect in ipairs(self.activeEffects) do
local ok, err = pcall(love.audio.setEffect, self:effectName(effect), effect)
--if not ok then log(err) end
end
end
function efx:applyFilter(source)
source:setFilter(self.bandpass)
for i,effect in ipairs(self.activeEffects) do
source:setEffect(self:effectName(effect))
end
end
function efx:setDryVolume(vol)
self.bandpass.volume = vol
end
return efx