SFX.play新增pitch参数,playSample方法允许超过音源范围(差太多了效果不好)

This commit is contained in:
MrZ626
2021-11-10 17:52:48 +08:00
parent 4f79ef8708
commit 168e2f80b8

View File

@@ -1,4 +1,5 @@
local type,rem=type,table.remove
local rnd=math.random
local sfxList={}
local packSetting={}
@@ -55,14 +56,14 @@ function SFX.loadSample(pack)
assert(type(pack)=='table',"Usage: SFX.loadsample([table])")
assert(pack.name,"No field: name")
assert(pack.path,"No field: path")
packSetting[pack.name]={
base=(_getTuneHeight(pack.base)or 37)-1,
}
local num=1
while love.filesystem.getInfo(pack.path..'/'..num..'.ogg')do
Sources[pack.name..num]={love.audio.newSource(pack.path..'/'..num..'.ogg','static')}
num=num+1
end
local base=(_getTuneHeight(pack.base)or 37)-1
local top=base+num-1
packSetting[pack.name]={base=base,top=top}
LOG((num-1).." "..pack.name.." samples loaded")
end
@@ -88,13 +89,23 @@ function SFX.playSample(pack,...)--vol-2, sampSet1, vol-3, sampSet2, vol-1
vol=arg[i]
else
local tune=arg[i]
tune=_getTuneHeight(tune)-packSetting[pack].base
SFX.play(pack..tune,vol)
local r=rnd(-1,1)
tune=_getTuneHeight(tune)-r
local base=packSetting[pack].base
local top=packSetting[pack].top
if tune<base then
r=base-(tune+r)
tune=base
elseif tune>top then
r=(tune+r)-top
tune=top
end
SFX.play(pack..tune-base,vol,nil,r)
end
end
end
end
function SFX.play(name,vol,pos)
function SFX.play(name,vol,pos,pitch)
if volume==0 or vol==0 then return end
local S=Sources[name]--Source list
if not S then return end
@@ -117,6 +128,7 @@ function SFX.play(name,vol,pos)
end
end
S:setVolume(((vol or 1)*volume)^1.626)
S:setPitch(pitch and 1.0594630943592953^pitch or 1)
S:play()
end
function SFX.fplay(name,vol,pos)