From 8ab5b4a17a9c59d1d4e081871a8224799c412ffe Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Mon, 15 Nov 2021 01:51:19 +0800 Subject: [PATCH] =?UTF-8?q?SFX=E6=A8=A1=E5=9D=97=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E9=9F=B3=E9=AB=98=E8=8E=B7=E5=8F=96=E9=9F=B3=E5=90=8D=E7=9A=84?= =?UTF-8?q?=E6=96=B9=E6=B3=95=20=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zframework/sfx.lua | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Zframework/sfx.lua b/Zframework/sfx.lua index fd7e30dd..a6d019f0 100644 --- a/Zframework/sfx.lua +++ b/Zframework/sfx.lua @@ -1,5 +1,5 @@ local type,rem=type,table.remove -local rnd=math.random +local int,rnd=math.floor,math.random local sfxList={} local packSetting={} @@ -7,7 +7,7 @@ local Sources={} local volume=1 local stereo=1 -local noteName={ +local noteVal={ C=1,c=1, D=3,d=3, E=5,e=5, @@ -16,10 +16,11 @@ local noteName={ A=10,a=10, B=12,b=12, } +local noteName={'C','C#','D','D#','E','F','F#','G','G#','A','A#','B'} local function _getTuneHeight(tune) local octave=tonumber(tune:sub(-1,-1)) if octave then - local tuneHeight=noteName[tune:sub(1,1)] + local tuneHeight=noteVal[tune:sub(1,1)] if tuneHeight then tuneHeight=tuneHeight+(octave-1)*12 local s=tune:sub(2,2) @@ -79,6 +80,15 @@ function SFX.setStereo(v) stereo=v end +function SFX.getNoteName(note) + if note<1 then + return'---' + else + note=note-1 + local octave=int(note/12)+1 + return noteName[note%12+1]..octave + end +end function SFX.playSample(pack,...)--vol-1, sampSet1, vol-2, sampSet2 if ... then local arg={...} @@ -97,8 +107,6 @@ function SFX.playSample(pack,...)--vol-1, sampSet1, vol-2, sampSet2 elseif playTune>top then--Too high notes playTune=top end - print('play:',playTune) - print('delta',tune-playTune) SFX.play(pack..playTune-base,vol,nil,tune-playTune) end end