@@ -8,7 +8,7 @@ if SYSTEM=='Web' then
88 __index = function (t ,k )
99 t [k ]= NOLL
1010 return NOLL
11- end
11+ end ,
1212 })
1313end
1414
@@ -36,7 +36,7 @@ if M.C and M.C2 then
3636 require ' constants'
3737 require ' wrap'
3838 require ' errors'
39- LOG (" info" ," FMOD loaded" )
39+ LOG (' info' ," FMOD loaded" )
4040end
4141
4242---- ----------------------------------------------------------
@@ -52,11 +52,22 @@ function M.init(args)
5252 M .studio :release ()
5353 firstTime = false
5454 end
55- M .studio = M .newStudio ()
56- M .core = M .studio :getCoreSystem ()
55+
56+ local res
57+ M .studio ,res = M .newStudio ()
58+ if res ~= M .FMOD_OK then MSG .log (' error' ," fmod newStudio error: " .. M .errorString [res ]) return end
59+
60+ M .core ,res = M .studio :getCoreSystem ()
61+ if res ~= M .FMOD_OK then MSG .log (' error' ," fmod getCoreSystem error: " .. M .errorString [res ]) return end
62+
5763 studio ,core = M .studio ,M .core
58- core :setDSPBufferSize (args .DSPBufferLength or 128 ,args .DSPBufferCount or 4 )
59- studio :initialize (args .maxChannel ,args .studioFlag ,args .coreFlag )
64+
65+ res = core :setDSPBufferSize (args .DSPBufferLength or 128 ,args .DSPBufferCount or 4 )
66+ if res ~= M .FMOD_OK then MSG .log (' error' ," fmod setDSPBufferSize error: " .. M .errorString [res ]) return end
67+
68+ res = studio :initialize (args .maxChannel ,args .studioFlag ,args .coreFlag )
69+ if res ~= M .FMOD_OK then MSG .log (' error' ," fmod initialize error: " .. M .errorString [res ]) return end
70+
6071 if firstTime then
6172 TASK .new (function ()
6273 while studio do
7788--- This method can only load files visible to fmod
7889--- @param path string
7990--- @param flag ? FMOD.Const
91+ --- @return FMOD.Studio.Bank ?, string ? errInfo
8092function M .loadBank (path ,flag )
8193 if not studio then return end
8294 local bank ,res = studio :loadBankFile (path ,flag or M .FMOD_STUDIO_LOAD_BANK_NORMAL )
8395 if res ~= M .FMOD_OK then
84- MSG . errorLog ( " FMOD loadBank error: " .. M .errorString [res ])
85- return
96+ LOG ( ' error ' , " fmodstudio:loadBankFile error: " .. M .errorString [res ])
97+ return nil , M . errorString [ res ]
8698 end
8799 M .banks [path ]= bank
88100 return bank
91103--- This method uses 'loadBankMemory' instead of 'loadBankFile', which makes files visible to love2d's filesystem can be loaded
92104--- @param path string
93105--- @param flag ? FMOD.Const
94- --- @return FMOD.Studio.Bank ?
106+ --- @return FMOD.Studio.Bank ?, string ? errInfo
95107function M .loadBank2 (path ,flag )
96108 if not studio then return end
97109 if not love .filesystem .getInfo (path ) then
98- MSG . new (' warn' ," Bank file not found: " .. path )
99- return
110+ LOG (' warn' ," Bank file not found: " .. path )
111+ return nil , " Bank file not found: " .. path
100112 end
101113 local file = love .filesystem .newFile (path )
102114 local data ,size = file :read (' data' )
103115 local bank ,res = studio :loadBankMemory (data :getPointer (),size ,0 ,flag or M .FMOD_STUDIO_LOAD_BANK_NORMAL )
104116 file :close (); file :release (); data :release ()
105117 if res ~= M .FMOD_OK then
106- MSG . errorLog ( " FMOD loadBankMemory error: " .. M .errorString [res ])
107- return
118+ LOG ( ' error ' , " FMOD loadBankMemory error: " .. M .errorString [res ])
119+ return nil , M . errorString [ res ]
108120 end
109121 M .banks [path ]= bank
110122 return bank
@@ -187,13 +199,13 @@ function M.music.play(name,args)
187199 if not desc then
188200 if not unhintedBGM [name ] then
189201 unhintedBGM [name ]= true
190- MSG .new (' warn' ," No BGM named " .. name )
202+ MSG .log (' warn' ," No BGM named " .. name )
191203 end
192204 return
193205 end
194206 local event ,res = desc :createInstance ()
195207 if res ~= M .FMOD_OK then
196- MSG .new (' warn' ," Event named " .. name .. " created failed: " .. M .errorString [res ])
208+ MSG .log (' warn' ," Event named " .. name .. " created failed: " .. M .errorString [res ])
197209 return
198210 end
199211 playing = {
@@ -329,13 +341,13 @@ function M.effect.play(name,args)
329341 if not desc then
330342 if not unhintedSFX [name ] then
331343 unhintedSFX [name ]= true
332- MSG .new (' warn' ," No SE named " .. name )
344+ MSG .log (' warn' ," No SE named " .. name )
333345 end
334346 return
335347 end
336348 local event ,res = desc :createInstance ()
337349 if res ~= M .FMOD_OK then
338- MSG .new (' warn' ," Play SE '" .. name .. " ' failed: " .. M .errorString [res ])
350+ MSG .log (' warn' ," Play SE '" .. name .. " ' failed: " .. M .errorString [res ])
339351 return
340352 end
341353
0 commit comments