三个音频模块升级不再依赖全局变量SETTING
但更新音量的时候必须需手动调用setVol 整理代码
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
local SFX={
|
||||
vol=1,
|
||||
stereo=1,
|
||||
getCount=function()return 0 end,
|
||||
load=function()error("Cannot load before init!")end,
|
||||
fieldPlay=NULL,
|
||||
@@ -6,6 +8,14 @@ local SFX={
|
||||
fplay=NULL,
|
||||
reset=NULL,
|
||||
}
|
||||
function SFX.setVol(v)
|
||||
assert(type(v)=='number'and v>=0 and v<=1)
|
||||
SFX.vol=v
|
||||
end
|
||||
function SFX.setStereo(v)
|
||||
assert(type(v)=='number'and v>=0 and v<=1)
|
||||
SFX.stereo=v
|
||||
end
|
||||
function SFX.init(list)
|
||||
SFX.init=nil
|
||||
local rem=table.remove
|
||||
@@ -23,7 +33,7 @@ function SFX.init(list)
|
||||
end
|
||||
|
||||
function SFX.play(s,vol,pos)
|
||||
if SETTING.sfx==0 or vol==0 then return end
|
||||
if SFX.vol==0 or vol==0 then return end
|
||||
local S=Sources[s]--Source list
|
||||
if not S then return end
|
||||
local n=1
|
||||
@@ -38,13 +48,13 @@ function SFX.init(list)
|
||||
S=S[n]--AU_SRC
|
||||
if S:getChannelCount()==1 then
|
||||
if pos then
|
||||
pos=pos*SETTING.stereo
|
||||
pos=pos*SFX.stereo
|
||||
S:setPosition(pos,1-pos^2,0)
|
||||
else
|
||||
S:setPosition(0,0,0)
|
||||
end
|
||||
end
|
||||
S:setVolume(((vol or 1)*SETTING.sfx)^1.626)
|
||||
S:setVolume(((vol or 1)*SFX.vol)^1.626)
|
||||
S:play()
|
||||
end
|
||||
function SFX.fplay(s,vol,pos)
|
||||
@@ -62,7 +72,7 @@ function SFX.init(list)
|
||||
S=S[n]--AU_SRC
|
||||
if S:getChannelCount()==1 then
|
||||
if pos then
|
||||
pos=pos*SETTING.stereo
|
||||
pos=pos*SFX.stereo
|
||||
S:setPosition(pos,1-pos^2,0)
|
||||
else
|
||||
S:setPosition(0,0,0)
|
||||
|
||||
Reference in New Issue
Block a user