SFX.play新增pitch参数,playSample方法允许超过音源范围(差太多了效果不好)
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
local type,rem=type,table.remove
|
local type,rem=type,table.remove
|
||||||
|
local rnd=math.random
|
||||||
|
|
||||||
local sfxList={}
|
local sfxList={}
|
||||||
local packSetting={}
|
local packSetting={}
|
||||||
@@ -55,14 +56,14 @@ function SFX.loadSample(pack)
|
|||||||
assert(type(pack)=='table',"Usage: SFX.loadsample([table])")
|
assert(type(pack)=='table',"Usage: SFX.loadsample([table])")
|
||||||
assert(pack.name,"No field: name")
|
assert(pack.name,"No field: name")
|
||||||
assert(pack.path,"No field: path")
|
assert(pack.path,"No field: path")
|
||||||
packSetting[pack.name]={
|
|
||||||
base=(_getTuneHeight(pack.base)or 37)-1,
|
|
||||||
}
|
|
||||||
local num=1
|
local num=1
|
||||||
while love.filesystem.getInfo(pack.path..'/'..num..'.ogg')do
|
while love.filesystem.getInfo(pack.path..'/'..num..'.ogg')do
|
||||||
Sources[pack.name..num]={love.audio.newSource(pack.path..'/'..num..'.ogg','static')}
|
Sources[pack.name..num]={love.audio.newSource(pack.path..'/'..num..'.ogg','static')}
|
||||||
num=num+1
|
num=num+1
|
||||||
end
|
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")
|
LOG((num-1).." "..pack.name.." samples loaded")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -88,13 +89,23 @@ function SFX.playSample(pack,...)--vol-2, sampSet1, vol-3, sampSet2, vol-1
|
|||||||
vol=arg[i]
|
vol=arg[i]
|
||||||
else
|
else
|
||||||
local tune=arg[i]
|
local tune=arg[i]
|
||||||
tune=_getTuneHeight(tune)-packSetting[pack].base
|
local r=rnd(-1,1)
|
||||||
SFX.play(pack..tune,vol)
|
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
|
||||||
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
|
if volume==0 or vol==0 then return end
|
||||||
local S=Sources[name]--Source list
|
local S=Sources[name]--Source list
|
||||||
if not S then return end
|
if not S then return end
|
||||||
@@ -117,6 +128,7 @@ function SFX.play(name,vol,pos)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
S:setVolume(((vol or 1)*volume)^1.626)
|
S:setVolume(((vol or 1)*volume)^1.626)
|
||||||
|
S:setPitch(pitch and 1.0594630943592953^pitch or 1)
|
||||||
S:play()
|
S:play()
|
||||||
end
|
end
|
||||||
function SFX.fplay(name,vol,pos)
|
function SFX.fplay(name,vol,pos)
|
||||||
|
|||||||
Reference in New Issue
Block a user