均匀音量调节

This commit is contained in:
MrZ_26
2020-08-06 02:50:28 +08:00
parent 8aa40bc200
commit 018687ad19
4 changed files with 48 additions and 23 deletions

View File

@@ -3,7 +3,7 @@ local rem=table.remove
local function fadeOut(id)
local src=BGM.list[id]
local v=src:getVolume()-.025*setting.bgm*.1
local v=src:getVolume()-.025*setting.bgm*.01
src:setVolume(v>0 and v or 0)
if v<=0 then
src:stop()
@@ -12,9 +12,10 @@ local function fadeOut(id)
end
local function fadeIn(id)
local src=BGM.list[id]
local v=min(src:getVolume()+.025*setting.bgm*.1,setting.bgm*.1)
local v=setting.bgm*.01
v=min(v,src:getVolume()+.025*v)
src:setVolume(v)
if v>=setting.bgm*.1 then return true end
if v>=setting.bgm*.01 then return true end
end
local BGM={
@@ -67,7 +68,7 @@ function BGM.play(s)
end
function BGM.freshVolume()
if BGM.playing then
local v=setting.bgm*.1
local v=setting.bgm*.01
if v>0 then
BGM.playing:setVolume(v)
if BGM.suspend then

View File

@@ -34,10 +34,10 @@ function SFX.loadAll()
end
end
function SFX.fieldPlay(s,v,P)
SFX.play(s,v,(P.curX+P.sc[2]-6.5)*.15)
SFX.play(s,v,(P.curX+P.sc[2]-5.5)*.15)
end
function SFX.play(s,vol,pos,force)
if setting.sfx==0 and not force then return end
function SFX.play(s,vol,pos)
if setting.sfx==0 then return end
local S=SFX.list[s]--Source list
if not S then return end
local n=1
@@ -58,11 +58,31 @@ function SFX.play(s,vol,pos,force)
S:setPosition(0,0,0)
end
end
if not force then
S:setVolume((vol or 1)*setting.sfx*.1)
else
S:setVolume(vol*.1)
S:setVolume(((vol or 1)*setting.sfx*.01)^1.626)
S:play()
end
function SFX.fplay(s,vol,pos)
local S=SFX.list[s]--Source list
if not S then return end
local n=1
while S[n]:isPlaying()do
n=n+1
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*setting.stereo*.1
S:setPosition(pos,1-pos^2,0)
else
S:setPosition(0,0,0)
end
end
S:setVolume((vol*.01)^1.626)
S:play()
end
function SFX.reset()

View File

@@ -207,22 +207,25 @@ end
function slider:draw()
local x,y=self.x,self.y
local ATV=self.ATV
local x2=x+self.w
gc.setColor(1,1,1,.5+ATV*.06)
--Units
gc.setColor(1,1,1,.5+ATV*.06)
gc.setLineWidth(2)
local x1,x2=x,x+self.w
for p=0,self.unit do
local x=x1+(x2-x1)*p/self.unit
gc.line(x,y+7,x,y-7)
if self.showUnit then
gc.setLineWidth(2)
for p=0,self.unit do
local x=x+(x2-x)*p/self.unit
gc.line(x,y+7,x,y-7)
end
end
--Axis
gc.setLineWidth(4)
gc.line(x1,y,x2,y)
gc.line(x,y,x2,y)
--Block
local bx,by,bw,bh=x1+(x2-x1)*self.pos/self.unit-10-ATV*.5,y-16-ATV,20+ATV,32+2*ATV
local bx,by,bw,bh=x+(x2-x)*self.pos/self.unit-10-ATV*.5,y-16-ATV,20+ATV,32+2*ATV
gc.setColor(.8,.8,.8)
gc.rectangle("fill",bx,by,bw,bh)
if ATV>0 then
@@ -367,6 +370,7 @@ function WIDGET.newSlider(D)
},
unit= D.unit,
showUnit=not D.noUnit,
font= D.font,
change= D.change,
disp= D.disp,

View File

@@ -119,7 +119,7 @@ local Widgets={
newButton({name="back", x=1200,y=655,w=120,h=80,color="white", font=40,code=BACK}),
},
music={
newSlider({name="bgm", x=760, y=80, w=400, unit=10, font=35,change=function()BGM.freshVolume()end,disp=SETval("bgm"),code=SETsto("bgm")}),
newSlider({name="bgm", x=760, y=80, w=400,unit=100, noUnit=true, font=35,change=function()BGM.freshVolume()end,disp=SETval("bgm"),code=SETsto("bgm")}),
newButton({name="up", x=1100, y=200, w=120,h=120, color="white", font=55,code=pressKey("up")}),
newButton({name="play", x=1100, y=340, w=120,h=120, color="white", font=35,code=pressKey("space"),hide=function()return setting.bgm==0 end}),
newButton({name="down", x=1100, y=480, w=120,h=120, color="white", font=55,code=pressKey("down")}),
@@ -276,10 +276,10 @@ local Widgets={
setting_sound={
newButton({name="game", x=200, y=80,w=240,h=80,color="lCyan",font=35,code=function()SCN.swapTo("setting_game","swipe")end}),
newButton({name="graphic", x=1080, y=80,w=240,h=80,color="lCyan",font=35,code=function()SCN.swapTo("setting_video","swipe")end}),
newSlider({name="sfx", x=180, y=200,w=400,unit=10,font=35,change=function()SFX.play("blip_1")end, disp=SETval("sfx"), code=SETsto("sfx")}),
newSlider({name="sfx", x=180, y=200,w=400,unit=100,noUnit=true,font=35,change=function()SFX.play("blip_1")end, disp=SETval("sfx"), code=SETsto("sfx")}),
newSlider({name="stereo", x=180, y=500,w=400,unit=10,font=35,change=function()SFX.play("move",1,-1)SFX.play("lock",1,1)end, disp=SETval("stereo"), code=SETsto("stereo"),hide=function()return setting.sfx==0 end}),
newSlider({name="spawn", x=180, y=300,w=400,unit=10,font=30,change=function()SFX.play("spawn_1",setting.spawn,nil,true)end, disp=SETval("spawn"), code=SETsto("spawn")}),
newSlider({name="bgm", x=180, y=400,w=400,unit=10,font=35,change=function()BGM.freshVolume()end, disp=SETval("bgm"), code=SETsto("bgm")}),
newSlider({name="spawn", x=180, y=300,w=400,unit=10,font=30,change=function()SFX.fplay("spawn_1",setting.spawn)end, disp=SETval("spawn"), code=SETsto("spawn")}),
newSlider({name="bgm", x=180, y=400,w=400,unit=100,noUnit=true,font=35,change=function()BGM.freshVolume()end, disp=SETval("bgm"), code=SETsto("bgm")}),
newSlider({name="vib", x=750, y=200,w=400,unit=5, font=28,change=function()VIB(2)end, disp=SETval("vib"), code=SETsto("vib")}),
newSlider({name="voc", x=750, y=300,w=400,unit=10,font=32,change=function()VOC.play("nya")end, disp=SETval("voc"), code=SETsto("voc")}),
newButton({name="back", x=1140, y=650,w=200,h=80,color="white",font=40,code=BACK}),