SFX模块升级
This commit is contained in:
@@ -1,97 +1,102 @@
|
|||||||
local SFX={
|
local rem=table.remove
|
||||||
vol=1,
|
|
||||||
stereo=1,
|
local sfxList={}
|
||||||
getCount=function()return 0 end,
|
local Sources={}
|
||||||
load=function()error("Cannot load before init!")end,
|
local volume=1
|
||||||
fieldPlay=NULL,
|
local stereo=1
|
||||||
play=NULL,
|
|
||||||
fplay=NULL,
|
local SFX={}
|
||||||
reset=NULL,
|
|
||||||
}
|
function SFX.init(list)
|
||||||
|
assert(type(list)=='table',"Initialize SFX lib with a list of filenames!")
|
||||||
|
sfxList=list
|
||||||
|
end
|
||||||
|
function SFX.load(path)
|
||||||
|
if not sfxList then
|
||||||
|
error("Cannot load before init!")
|
||||||
|
else
|
||||||
|
for i=1,#sfxList do
|
||||||
|
local fullPath=path..sfxList[i]..'.ogg'
|
||||||
|
if love.filesystem.getInfo(fullPath)then
|
||||||
|
Sources[sfxList[i]]={love.audio.newSource(fullPath,'static')}
|
||||||
|
else
|
||||||
|
LOG("No SFX: "..sfxList[i]..'.ogg',.1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function SFX.getCount()
|
||||||
|
return #sfxList
|
||||||
|
end
|
||||||
function SFX.setVol(v)
|
function SFX.setVol(v)
|
||||||
assert(type(v)=='number'and v>=0 and v<=1)
|
assert(type(v)=='number'and v>=0 and v<=1)
|
||||||
SFX.vol=v
|
volume=v
|
||||||
end
|
end
|
||||||
function SFX.setStereo(v)
|
function SFX.setStereo(v)
|
||||||
assert(type(v)=='number'and v>=0 and v<=1)
|
assert(type(v)=='number'and v>=0 and v<=1)
|
||||||
SFX.stereo=v
|
stereo=v
|
||||||
end
|
end
|
||||||
function SFX.init(list)
|
|
||||||
SFX.init=nil
|
|
||||||
local rem=table.remove
|
|
||||||
local Sources={}
|
|
||||||
|
|
||||||
local count=#list function SFX.getCount()return count end
|
function SFX.play(name,vol,pos)
|
||||||
function SFX.load(path)
|
if volume==0 or vol==0 then return end
|
||||||
for i=1,count do
|
local S=Sources[name]--Source list
|
||||||
local fullPath=path..list[i]..'.ogg'
|
if not S then return end
|
||||||
if love.filesystem.getInfo(fullPath)then
|
local n=1
|
||||||
Sources[list[i]]={love.audio.newSource(fullPath,'static')}
|
while S[n]:isPlaying()do
|
||||||
else
|
n=n+1
|
||||||
LOG("No SFX: "..list[i]..'.ogg',.1)
|
if not S[n]then
|
||||||
end
|
S[n]=S[1]:clone()
|
||||||
|
S[n]:seek(0)
|
||||||
|
break
|
||||||
end
|
end
|
||||||
|
end
|
||||||
function SFX.play(s,vol,pos)
|
S=S[n]--AU_SRC
|
||||||
if SFX.vol==0 or vol==0 then return end
|
if S:getChannelCount()==1 then
|
||||||
local S=Sources[s]--Source list
|
if pos then
|
||||||
if not S then return end
|
pos=pos*stereo
|
||||||
local n=1
|
S:setPosition(pos,1-pos^2,0)
|
||||||
while S[n]:isPlaying()do
|
else
|
||||||
n=n+1
|
S:setPosition(0,0,0)
|
||||||
if not S[n]then
|
|
||||||
S[n]=S[1]:clone()
|
|
||||||
S[n]:seek(0)
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
S=S[n]--AU_SRC
|
|
||||||
if S:getChannelCount()==1 then
|
|
||||||
if pos then
|
|
||||||
pos=pos*SFX.stereo
|
|
||||||
S:setPosition(pos,1-pos^2,0)
|
|
||||||
else
|
|
||||||
S:setPosition(0,0,0)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
S:setVolume(((vol or 1)*SFX.vol)^1.626)
|
|
||||||
S:play()
|
|
||||||
end
|
end
|
||||||
function SFX.fplay(s,vol,pos)
|
end
|
||||||
local S=Sources[s]--Source list
|
S:setVolume(((vol or 1)*volume)^1.626)
|
||||||
if not S then return end
|
S:play()
|
||||||
local n=1
|
end
|
||||||
while S[n]:isPlaying()do
|
function SFX.fplay(name,vol,pos)
|
||||||
n=n+1
|
local S=Sources[name]--Source list
|
||||||
if not S[n]then
|
if not S then return end
|
||||||
S[n]=S[1]:clone()
|
local n=1
|
||||||
S[n]:seek(0)
|
while S[n]:isPlaying()do
|
||||||
break
|
n=n+1
|
||||||
end
|
if not S[n]then
|
||||||
end
|
S[n]=S[1]:clone()
|
||||||
S=S[n]--AU_SRC
|
S[n]:seek(0)
|
||||||
if S:getChannelCount()==1 then
|
break
|
||||||
if pos then
|
|
||||||
pos=pos*SFX.stereo
|
|
||||||
S:setPosition(pos,1-pos^2,0)
|
|
||||||
else
|
|
||||||
S:setPosition(0,0,0)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
S:setVolume(vol^1.626)
|
|
||||||
S:play()
|
|
||||||
end
|
end
|
||||||
function SFX.reset()
|
end
|
||||||
for _,L in next,Sources do
|
S=S[n]--AU_SRC
|
||||||
if type(L)=='table'then
|
if S:getChannelCount()==1 then
|
||||||
for i=#L,1,-1 do
|
if pos then
|
||||||
if not L[i]:isPlaying()then
|
pos=pos*stereo
|
||||||
rem(L,i)
|
S:setPosition(pos,1-pos^2,0)
|
||||||
end
|
else
|
||||||
end
|
S:setPosition(0,0,0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
S:setVolume(vol^1.626)
|
||||||
|
S:play()
|
||||||
|
end
|
||||||
|
function SFX.reset()
|
||||||
|
for _,L in next,Sources do
|
||||||
|
if type(L)=='table'then
|
||||||
|
for i=#L,1,-1 do
|
||||||
|
if not L[i]:isPlaying()then
|
||||||
|
rem(L,i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return SFX
|
return SFX
|
||||||
|
|||||||
Reference in New Issue
Block a user