-
Notifications
You must be signed in to change notification settings - Fork 0
/
qaudio.lua
58 lines (48 loc) · 1.11 KB
/
qaudio.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
Quadio = {}
love.audio.setEffect('reverb', {
type = 'reverb',
gain = 0.3,
decaytime = 2.0,
})
love.audio.setEffect('delay', {
type = 'echo',
volume = 0.2,
delay = 0.157,
tapdelay = 0.044,
damping = 0.5,
feedback = .3,
spread = 1.0,
})
function Quadio.load()
bitDepth = 16
samplingRate = 44100
channelCount = 1
bufferSize = 1024
pointer = 0
sd = love.sound.newSoundData(bufferSize, samplingRate, bitDepth, channelCount)
qs = love.audio.newQueueableSource(samplingRate, bitDepth, channelCount)
qs:setEffect('reverb')
--qs:setEffect('delay')
dspTime = 0.0
fun = nil
end
function Quadio.setCallback(f)
fun = f
end
function Quadio.update()
if qs:getFreeBufferCount() == 0 then return end -- only render if we can.
local samplesToMix = bufferSize -- easy way of doing things.
for smp = 0, samplesToMix-1 do
lambda1 = smp/samplesToMix
lambda2 = (smp+0.5)/samplesToMix
-- put your generator function here.
sd:setSample(pointer, fun(dspTime))
pointer = pointer + 1
dspTime = dspTime + (1 / samplingRate)
if pointer >= sd:getSampleCount() then
pointer = 0
qs:queue(sd)
qs:play()
end
end
end