MOAI 1.5 LINUX SDL HOST W/FMOD

FMOD / Untz / Native

Moderators: ezraanderson, ibisum

MOAI 1.5 LINUX SDL HOST W/FMOD

Postby naturally » Fri Apr 21, 2017 5:27 am

Recently with the help of halfnelson and vavius I added FMOD to my 1.5 Linux host.
It's not that hard, but here are my notes.

STEPS

Register at FMOD and download the API
- copy api/lowlevel/lib/x86_64 to 3rdparty/fmod-studio/lib/linux
- copy api/lowlevel/inc to 3rdparty/fmod-studio/headers

Clone https://github.com/Vavius/moai-fmod-studio
- copy to src/moai-fmod-studio

Edit src/moai-fmod-studio/CMakeLists.txt
Add:
Code: Select all
  1. elseif (BUILD_LINUX)

  2.     set (FMOD_LIB ${FMOD_LIB_ROOT}/linux/libfmod.so")



Edit cmake/CMakeLists.txt and add where appropriate:
Code: Select all
  1. option ( MOAI_FMOD_STUDIO    TRUE )

  2. SETUP_MODULE(MOAI_FMOD_STUDIO MOAI_WITH_FMOD_STUDIO)

  3. SETUP_MODULE(MOAI_FMOD_STUDIO AKU_WITH_FMOD_STUDIO)



Edit cmake/host-modules/CMakeLists.txt and add where appropriate:
Code: Select all
  1. #FMOD_STUDIO

  2. if ( MOAI_FMOD_STUDIO )

  3.   target_link_libraries ( host-modules moai-fmod-studio )

  4. endif ( MOAI_FMOD_STUDIO )



If fails to build, try:
PLUGIN_ROOT is set to hard-coded driectory

Note: there is a newer FMOD wrapper in the cloudteampro fork, for newer versions of moai.

LUA-SIDE WRAPPER

This is an example of Lua usage:

Code: Select all
  1. ----------------------------------------------------------------------------------------------------

  2. -- @type FmodSoundEngine

  3. --

  4. -- This is FmodSoundEngine class using MOAIFmodStudio

  5. ----------------------------------------------------------------------------------------------------

  6. FmodSoundEngine = class()

  7. SoundMgr.FmodSoundEngine = FmodSoundEngine

  8.  

  9. FmodSoundEngine.CHANNELS = 100

  10.  

  11. ---

  12. -- Constructor.

  13. function FmodSoundEngine:init()

  14.     MOAIFmodStudio.init(FmodSoundEngine.CHANNELS)

  15.  

  16.     local sfxChannel = MOAIFmodStudioChannel.new()

  17.     sfxChannel:setReusable(true)

  18.     self.sfxChannel = sfxChannel

  19.     self.bgmChannel = MOAIFmodStudioChannel.new()

  20.  

  21.     self.initialized = true

  22.     self._soundCache = {}

  23. end

  24.  

  25. ---

  26. -- Load the MOAIFmodSound

  27. function FmodSoundEngine:loadSound(filePath, bgm)

  28.     local sound = MOAIFmodStudioSound.new()

  29.     if bgm then

  30.         sound:loadBGM(filePath)

  31.     else

  32.         sound:loadSFX(filePath)

  33.     end

  34.     return sound

  35. end

  36.  

  37. ---

  38. -- Return the cached sound

  39. function FmodSoundEngine:getSound(filePath, bgm)

  40.     local path = ResourceMgr:getResourceFilePath(filePath)

  41.     assert(path, "sound not found: " .. filePath)

  42.  

  43.     if not self._soundCache[path] then

  44.         self._soundCache[path] = self:loadSound(path, bgm)

  45.     end

  46.    

  47.     return self._soundCache[path]

  48. end

  49.  

  50. ---

  51. -- Release the MOAIFmodSound.

  52. -- @param filePath file path.

  53. -- @return cached sound.

  54. function FmodSoundEngine:release(filePath)

  55.     local sound = self._soundCache[filePath]

  56.     if sound then

  57.         sound:release()

  58.     end

  59.     self._soundCache[filePath] = nil

  60.     return sound

  61. end

  62.  

  63. ---

  64. --

  65. function FmodSoundEngine:playBGM(sound, volume, looping)

  66.     sound = type(sound) == "string" and self:getSound(sound, true) or sound

  67.     volume = volume or 1

  68.     looping = looping and true or false

  69.    

  70.     local channel = self.bgmChannel

  71.     channel:setVolume(volume)

  72.     channel:setLooping(looping)

  73.     channel:play(sound)

  74.    

  75.     return channel

  76. end

  77.  

  78. ---

  79. --

  80. function FmodSoundEngine:playSFX(sound, volume, looping, createChannel)

  81.     sound = type(sound) == "string" and self:getSound(sound, false) or sound

  82.     volume = volume or 1

  83.     looping = looping and true or false

  84.    

  85.     local channel = self.sfxChannel

  86.     if looping or createChannel then

  87.         channel = MOAIFmodStudioChannel.new()

  88.     end

  89.  

  90.     channel:setVolume(volume)

  91.     channel:setLooping(looping)

  92.     channel:play(sound)

  93.  

  94.     return channel

  95. end

  96.  

  97. function FmodSoundEngine:mute(flag)

  98.     MOAIFmodStudio.mute(flag)

  99. end

  100.  

  101. function FmodSoundEngine:muteSFX(flag)

  102.     MOAIFmodStudio.muteSFX(flag)

  103. end

  104.  

  105. function FmodSoundEngine:muteBGM(flag)

  106.     MOAIFmodStudio.muteBGM(flag)

  107. end

  108.  

  109. ---

  110. -- Set the system level volume.

  111. -- @param volume

  112. function FmodSoundEngine:setVolume(volume)

  113.     MOAIFmodStudio.setVolume(volume)

  114. end

  115.  

  116. ---

  117. -- Return the system level volume.

  118. -- @return volume

  119. function FmodSoundEngine:getVolume()

  120.     return MOAIFmodStudio.getVolume()

  121. end

  122.  

  123. ---

  124. --

  125. function FmodSoundEngine:setSFXVolume(volume)

  126.     MOAIFmodStudio.setSFXVolume(volume)

  127.     MOAIFmodStudio.sfxVolume = volume

  128. end

  129.  

  130. ---

  131. --

  132. function FmodSoundEngine:setBGMVolume(volume)

  133.     MOAIFmodStudio.setBGMVolume(volume)

  134.     MOAIFmodStudio.bgmVolume = volume

  135. end

  136.  

  137. ---

  138. --

  139. function FmodSoundEngine:getSFXVolume()

  140.     return MOAIFmodStudio.sfxVolume or 1

  141. end

  142.  

  143. ---

  144. --

  145. function FmodSoundEngine:getBGMVolume()

  146.     return MOAIFmodStudio.bgmVolume or 1

  147. end

  148.  

  149.  

  150. return FmodSoundEngine



UNTZ-STYLE

FMOD has a different paradigm than Untz, so to get Untz style sound, you can do something like this:

Code: Select all
  1.  

  2. function Audio:PlaySound(name, volume, force, duplicate)

  3. if duplicate then

  4.         local channel = MOAIFmodStudioChannel.new()

  5.         channel:play(sound)

  6.         channel:setVolume(volume)

  7. elseif force then

  8.         if Audio.fmod_channels[name] then

  9.                 local channel = Audio.fmod_channels[name]

  10.                 channel:stop()

  11.                 channel:play(sound)

  12.                 channel:setVolume(volume)                                              

  13.         else

  14.                 local channel = MOAIFmodStudioChannel.new()

  15.                 channel:play(sound)

  16.                 channel:setVolume(volume)

  17.         end

  18. else

  19.         if not Audio.fmod_channels[name] then

  20.                 local channel = MOAIFmodStudioChannel.new()

  21.                 channel:play(sound)

  22.                 channel:setVolume(volume)                                      

  23.                 Audio.fmod_channels[name] = channel

  24.         else

  25.                 local channel = Audio.fmod_channels[name]

  26.                 if not channel:isPlaying() then

  27.                         channel:play(sound)

  28.                         channel:setVolume(volume)                                              

  29.                 end

  30.         end

  31. end



Chat room log:
Code: Select all
  1. naturally [9:28 AM]

  2. uploaded this image: Play Page (beta)

  3. Add Comment

  4.  

  5. halfnelson [2:15 PM]

  6. Nice

  7.  

  8. ezraanderson [2:25 PM]

  9. cool

  10.  

  11. ezraanderson [2:58 PM]

  12. I like the icon

  13.  

  14. halfnelson [3:46 PM]

  15. Would love to try it on android. Let me know when it is up

  16.  

  17.  

  18. ----- March 29th -----

  19. vavius [12:38 PM]

  20. joined #build

  21.  

  22.  

  23. ----- April 18th -----

  24. naturally [10:15 AM]

  25. At a loss as to how to add FMOD to SDL hosts...

  26.  

  27. [10:16]

  28. I did look through cloudteampro but I think its just fmod for android+ios (which will be useful later)

  29.  

  30. vavius [10:18 AM]

  31. and osx

  32.  

  33. [10:19]

  34. no windows

  35.  

  36. naturally [10:19 AM]

  37. i think i need to make a cmake file for it

  38.  

  39. vavius [10:19 AM]

  40. but basically you just get fmod libs from their site

  41.  

  42. [10:19]

  43. cmake is there for android, it’s the same

  44.  

  45. naturally [10:22 AM]

  46. i cant seem to find that

  47.  

  48. naturally [10:33 AM]

  49. I tried writing a cmake like so: https://pastebin.com/xPMnS3PE and put it in cmake/thid-party/fmod-studio (edited)

  50.  

  51. [10:33]

  52. CMake Error at third-party/fmod-studio/CMakeLists.txt:21 (target_link_libraries):

  53.   Cannot specify link libraries for target "fmod-studio" which is not built

  54.   by this project.

  55.  

  56. [10:35]

  57. then i added "option ( MOAI_FMOD_STUDIO    TRUE )" to the base cmakelists.txt

  58.  

  59. [10:35]

  60. SETUP_MODULE(MOAI_FMOD_STUDIO MOAI_WITH_FMOD_STUDIO)

  61. SETUP_MODULE(MOAI_FMOD_STUDIO AKU_WITH_FMOD_STUDIO)

  62.  

  63. [10:35]

  64. add_subdirectory ( moai-fmod-studio )

  65.  

  66. [10:36]

  67. and to third-party/cmakelists: add_subdirectory ( fmod-studio )

  68.  

  69. naturally [10:54 AM]

  70. it really doesnt like "add_subdirectory ( moai-fmod-studio )".,.. even tho the files are in /src

  71.  

  72. [10:56]

  73. Scanning dependencies of target fmod-studio

  74. make[2]: *** No rule to make target 'third-party/fmod-studio/CMakeFiles/fmod-studio.dir/build'.  Stop.

  75. CMakeFiles/Makefile2:1877: recipe for target 'third-party/fmod-studio/CMakeFiles/fmod-studio.dir/all' failed

  76. make[1]: *** [third-party/fmod-studio/CMakeFiles/fmod-studio.dir/all] Error 2

  77.  

  78. [10:58]

  79. Cannot determine link language of fmod-studio

  80.  

  81.  

  82. ----- April 19th -----

  83. ibisum [1:47 AM]

  84. cmake hell

  85.  

  86. [1:47]

  87. i kind of miss it to be honest

  88.  

  89. [1:47]

  90. tried to build moai-1.7.5 community last night, and i just wanted to kill myself.

  91.  

  92. naturally [5:45 AM]

  93. what platform?

  94.  

  95. [5:45]

  96. did you try to build for

  97.  

  98. ibisum [6:14 AM]

  99. android, ios, macos.  didn’t try linux, i just gave up instead and went back to 1.5

  100.  

  101. [6:14]

  102. but, i wish to register the complaint that, out of the box, 1.7.5-community is a mess.

  103.  

  104. naturally [6:31 AM]

  105. i found 1.7.5 to work fine on osx+ios.  android was crazy and i never got that working.  did you try cloudteampro for mobile?  i havent tried it myself.  eventually i have 1.7.5 working on linux.  ps. if you do get it working, i found anim:pause() is broken/changed, replace with anim:stop()

  106.  

  107. ibisum [6:32 AM]

  108. yeah, unfortunately that is all a real, big, drag.

  109.  

  110. [6:32]

  111. i dunno why we’ve never managed to get this stabilized as a community

  112.  

  113. [6:32]

  114. i can only hope that 2.0 will be different, eventually.  one day.  maybe.

  115.  

  116. naturally [6:33 AM]

  117. its compounded by many people using different versions and the build processes keep changing.  thank god for halfnelson

  118.  

  119. ibisum [6:34 AM]

  120. hmm.  yeah.

  121.  

  122. naturally [6:36 AM]

  123. i feel really stuck now tho.  i have my hosts stabilized but Untz is a source of crashes, even with the 1.6 fixes.  i dont want to rebuild any hosts but need to move to FMOD.  i'll rebuild them all if i can figure out how to do that.  willing to pay for help :wink:

  124.  

  125. [6:37]

  126. for android im still on 1.5, i just replaced libpng and removed opensll.  google isnt complaining...

  127.  

  128. ibisum [6:37 AM]

  129. yeah, i’m in the same boat actually.

  130.  

  131. [6:38]

  132. having to juggle all this is a real bummer.  i love MOAI so much, but at the moment its a real liability trying to get a new host project started.

  133.  

  134. halfnelson [6:45 AM]

  135. Naturally what host are you trying to add fmod too?

  136.  

  137. [6:45]

  138. 1.5 android?

  139.  

  140. naturally [6:46 AM]

  141. i'm starting with 1.5 linux.  i figured i could get it working from there.  altho i do have 1.7.5 working on linux so thats an option

  142.  

  143. [6:47]

  144. (tho im on 1.5 for windows still, so hoping not to upgrade that...)

  145.  

  146. halfnelson [6:47 AM]

  147. 1.5 is super easy. I'll have a look

  148.  

  149. naturally [6:47 AM]

  150. :slightly_smiling_face: ... i thought maybe i should fork 1.5 on git and just do the fmod stuff in that fork

  151.  

  152. halfnelson [6:48 AM]

  153. Cmake plugin system

  154.  

  155. [6:48]

  156. Should plug right in

  157.  

  158. naturally [6:48 AM]

  159. then u or whoever would be able to see what im doing wrong

  160.  

  161. halfnelson [6:50 AM]

  162. yeah looking now

  163.  

  164. [6:50]

  165. https://github.com/moaiforge/moai-fmod-studio/blob/master/plugin.CMake are you using this thing?

  166. GitHub

  167. moaiforge/moai-fmod-studio

  168. moai-fmod-studio - Fmod studio API plugin for MOAI. Crossplatform sound support using the new fmod API that is free for Indies.

  169.  

  170.  

  171. naturally [6:51 AM]

  172. no - didnt see this one

  173.  

  174. halfnelson [6:51 AM]

  175. looking for my plugin docs

  176.  

  177. [6:52]

  178. think it is just adding a -DPLUGIN_DIR to the cmake command line

  179.  

  180. [6:52]

  181. (i used to just let moaicli do it all)

  182.  

  183. [6:52]

  184. happy to try and track down bug in untz too

  185.  

  186. [6:52]

  187. if you have stack traces to share

  188.  

  189. naturally [6:52 AM]

  190. i think untz is ok for a while but after 5-10+ minutes of the app running, it sometimes crashes

  191.  

  192. halfnelson [6:53 AM]

  193. hrm

  194.  

  195. [6:53]

  196. that sucks

  197.  

  198. [6:53]

  199. i have been deep in the untz code

  200.  

  201. [6:53]

  202. does this happen on all platforms?

  203.  

  204. [6:53]

  205. or just android?

  206.  

  207. [6:53]

  208. (the untz crashes)

  209.  

  210. [6:53]

  211. https://github.com/halfnelson/moai-sdk/wiki/Using-Plugins

  212. GitHub

  213. halfnelson/moai-sdk

  214. moai-sdk - Moaiforge branch of the Zipline Moai SDK

  215.  

  216.  

  217. [6:53]

  218. my old plugin docs

  219.  

  220. naturally [6:53 AM]

  221. yes, its most prevalent on apple, but im getting android reports too.  i have plenty of stacktraces

  222.  

  223. halfnelson [6:54 AM]

  224. would love to have a look. at some

  225.  

  226. [6:54]

  227. since my stuff is using untz

  228.  

  229. [6:55]

  230. https://github.com/halfnelson/moai-sdk/wiki/Using-Custom-Hosts i even had the stirfire host (freedomfall) building as optional plugin :slightly_smiling_face:

  231. GitHub

  232. halfnelson/moai-sdk

  233. moai-sdk - Moaiforge branch of the Zipline Moai SDK

  234.  

  235.  

  236. [6:55]

  237. never got it going on linux though :disappointed:

  238.  

  239. [6:59]

  240. will see if I can get fmod going

  241.  

  242. naturally [6:59 AM]

  243. ok, i will check out the FMOD things in a while.  in the meantime im looking up those Untz crashes for you

  244.  

  245. [7:00]

  246. Here is one from Linux: AudioMixer::process(unsigned int, float*, unsigned int, float*, unsigned int) ()

  247. SDL_callback(void*, unsigned char*, int) ()

  248. SDL_RunAudio (devicep=0x7f9d980196d0) at sdl2-2.0.4/src/audio/SDL_audio.c:655

  249. SDL_TLSCleanup () at sdl2-2.0.4/src/thread/SDL_thread.c:90

  250. SDL_RunThread (data=0x7f9d9801b1e0) at sdl2-2.0.4/src/thread/SDL_thread.c:285

  251.  

  252. [7:01]

  253. From Android: #00 pc 003969b8  /data/app/com.dontbepatchman.episode1-1/lib/arm/libmoai.so (_ZN4UNTZ5Sound11setPositionEd+96)

  254.     #01 pc 00396c20  /data/app/com.dontbepatchman.episode1-1/lib/arm/libmoai.so (_ZN4UNTZ5Sound4playEv+88)

  255.     #02 pc 00392860  /data/app/com.dontbepatchman.episode1-1/lib/arm/libmoai.so (_ZN13MOAIUntzSound5_playEP9lua_State+120)

  256.  

  257. [7:01]

  258. From OSX, also :SetPosition is the common/only one ... but im not finding the screenshot at the moment

  259.  

  260. halfnelson [7:01 AM]

  261. hrm

  262.  

  263. [7:02]

  264. but linux dies elsewhere

  265.  

  266. naturally [7:02 AM]

  267. :setPosition seems to be the main culprit on all platforms.  usually happens when im loading a new level, but can be just anywhere

  268.  

  269. [7:02]

  270. i dont know if linux is special.  thats just hte last one i have in backtrace

  271.  

  272. [7:03]

  273. this is the Untz code from 1.6

  274.  

  275. [7:04]

  276. oddly ive never had it happen on windows, personally.  but it might be a thing

  277.  

  278. halfnelson [7:04 AM]

  279. think windows uses directsound

  280.  

  281. [7:04]

  282. not sdl

  283.  

  284. [7:04]

  285. linux and apple i think use sdl

  286.  

  287. [7:04]

  288. could be wrong

  289.  

  290. [7:05]

  291. they are the traces

  292.  

  293. [7:05]

  294. what is the actual error? SIG___?

  295.  

  296. naturally [7:06 AM]

  297. yeah, segfault

  298.  

  299. [7:06]

  300. operating on a nil

  301.  

  302. halfnelson [7:07 AM]

  303. hrm like the sound has been collected by lua already

  304.  

  305. [7:07]

  306. so the userdata is empty

  307.  

  308. [7:07]

  309. or something

  310.  

  311. [7:10]

  312. https://github.com/moai/moai-dev/commit/388ba9ac63148211870d9bf631c9488a9dfa93c8

  313. GitHub

  314. Merge pull request #1067 from moai/fix_untz · moai/moai-dev@388ba9a

  315. fix sounds never stopping in untz

  316.  

  317.  

  318. [7:12]

  319. https://github.com/halfnelson/moai-sdk/commit/4ab0f2e609a597e5692fc6eb1313478984369231 actually this one

  320. GitHub

  321. Merge pull request #1068 from moai/untz-audiomixer-fix · halfnelson/moai-sdk@4ab0f2e

  322. fix audio mixer sound stop code

  323.  

  324.  

  325. naturally [7:14 AM]

  326. yes i am using those fixes

  327.  

  328. halfnelson [7:14 AM]

  329. yeah windows uses rtaudio

  330.  

  331. naturally [7:16 AM]

  332. interesting.  thats good news to me

  333.  

  334. halfnelson [7:17 AM]

  335. https://github.com/moai/moai-dev/commit/d6f0a7aa2389d88073204db72b6b636ce259ab6e lots of mods in here

  336. GitHub

  337. fixed android build · moai/moai-dev@d6f0a7a

  338. moai-dev - This is the development repo of Moai SDK. Current, but not necessarily tested or stable.

  339.  

  340.  

  341. [7:17]

  342. 1.6

  343.  

  344. naturally [7:19 AM]

  345. i have those fixes in android

  346.  

  347. halfnelson [7:19 AM]

  348. yeah it more sounds like it is getting passed a bad userdata

  349.  

  350. naturally [7:19 AM]

  351. can i maybe just do some kind of nil check and ignore it

  352.  

  353. halfnelson [7:19 AM]

  354. will see if fmod works would be good to know

  355.  

  356. [7:19]

  357. if that solves it

  358.  

  359. naturally [7:20 AM]

  360. so funny, im bashing the app with reload after reload on osx and its not reproducing

  361.  

  362. [7:20]

  363. but i did discover i glitch (my own) with extreme closeup zoom on level start

  364.  

  365. [7:21]

  366. will try to keep reproducing.  xcode seems to give nice error trace

  367.  

  368. halfnelson [7:58 AM]

  369. will poke this tomorrow, out of awakeness for tonight

  370.  

  371. naturally [7:59 AM]

  372. thanks - should have fmod report by then - have a gooder

  373.  

  374. naturally [9:49 AM]

  375. Am getting further now with the Cmake files from moai forge...

  376.  

  377. [9:49]

  378. Added to the rules:   elseif (BUILD_LINUX)

  379.     set (FMOD_LIB "${FMOD_LIB_ROOT}/linux/libfmodstudio.so")

  380.   endif()

  381.  

  382. [9:49]

  383. Which turns to: Scanning dependencies of target moai-fmod-studio

  384. [100%] Linking CXX static library libmoai-fmod-studio.a

  385. [100%] Built target moai-fmod-studio

  386. make[2]: *** No rule to make target '../third-party/fmod-studio/../fmod-studio/lib/linux/libfmodstudio.so', needed by 'host-sdl/moai'.  Stop.

  387.  

  388. naturally [9:56 AM]

  389. i think that means i need to modify the host-sdl/CmakeLists.txt

  390.  

  391. naturally [10:13 AM]

  392. hmm, didnt seem to help, or didnt do it right

  393.  

  394. halfnelson [5:05 PM]

  395. hrm

  396.  

  397. halfnelson [5:13 PM]

  398. not sure why it is trying to link against that for host-sdl

  399.  

  400. [5:13]

  401. did you delete your cmakecache.txt

  402.  

  403. [5:13]

  404. make sure libfmodstudio doesn't appear anywhere else

  405.  

  406. [5:14]

  407. in your cmake files

  408.  

  409. [5:14]

  410. maybe make cant find it

  411.  

  412. [5:15]

  413. ah of course

  414.  

  415. [5:15]

  416. plugin_root is a relative path

  417.  

  418. [5:15]

  419. make will be run in a completely different folder

  420.  

  421. [5:15]

  422. that FMOD_LIB is just a string so its path doesnt get fixed up

  423.  

  424. [5:15]

  425. @naturally

  426.  

  427. [5:15]

  428. try setting plugin_root to absolute path

  429.  

  430. halfnelson [5:22 PM]

  431. or using this command https://cmake.org/cmake/help/v3.4/command/get_filename_component.html

  432.  

  433. [5:22]

  434. to set FMOD_LIB as full path

  435.  

  436. naturally [5:34 PM]

  437. cool - trying

  438.  

  439. naturally [5:46 PM]

  440. ok i think the cmake is correct and trying to build, but the fmod files dont match the moai version (tinkering)

  441.  

  442. halfnelson [5:47 PM]

  443. yay

  444.  

  445. naturally [5:47 PM]

  446. :slightly_smiling_face:

  447.  

  448. [5:47]

  449. i had to change something that seems broken in the original cmake (?)

  450.  

  451. halfnelson [5:47 PM]

  452. oh?

  453.  

  454. naturally [5:47 PM]

  455. file ( GLOB MOAI_FMOD_SRC should be set to the src/moai-fmod-studio directory, not the third-party directory

  456.  

  457. [5:47]

  458. at least, thats how i have it set up

  459.  

  460. halfnelson [5:48 PM]

  461. "${PLUGIN_ROOT} is the moai-fmod-studio folder

  462.  

  463. [5:48]

  464. file ( GLOB MOAI_FMOD_SRC

  465.     "${PLUGIN_ROOT}/*.cpp"

  466.  

  467. naturally [5:49 PM]

  468. hmm i guess i set it up differently.  i put the FMOD headers and .h libs in 3rdparty/fmod-studio and the moai-fmod cpp interface in src/moai-fmod-studio

  469.  

  470. halfnelson [5:49 PM]

  471. yeah, the plugin doesnt need that

  472.  

  473. [5:49]

  474. the plugin just wants to be in its own folder

  475.  

  476. naturally [5:50 PM]

  477. ok

  478.  

  479. halfnelson [5:50 PM]

  480. (if you use plugin system)

  481.  

  482. naturally [5:50 PM]

  483. i did not

  484.  

  485. halfnelson [5:50 PM]

  486. cool, then you probably did need to make the change

  487.  

  488. [5:50]

  489. just like a normal moai aku modules

  490.  

  491. [5:50]

  492. (which is what the plugin tries to emulate)

  493.  

  494. naturally [5:51 PM]

  495. i'm getting a bunch of compile errors like "‘class MOAISim’ has no member named ‘GetActionMgr’" which i think means this fmod interface is for a much later moai version than 1.5

  496.  

  497. [5:51]

  498. i wonder if there is another/older fmod interface

  499.  

  500. halfnelson [5:52 PM]

  501. what file is the actionmgr call in?

  502.  

  503. naturally [5:52 PM]

  504. MOAIFmodStudioChannel.cpp

  505.  

  506. [5:52]

  507. ‘ATTR_TYPE_FLOAT’ is not a member of ‘MOAIAttrOp’

  508.  

  509. halfnelson [5:53 PM]

  510. not seeing that

  511.  

  512. naturally [5:53 PM]

  513. MOAIFmodBeatDetector.cpp:40:21: error: ‘LOG_ERROR’ is not a member of ‘ZLLog’

  514.  

  515. halfnelson [5:53 PM]

  516. https://github.com/Vavius/moai-fmod-studio

  517. GitHub

  518. Vavius/moai-fmod-studio

  519. moai-fmod-studio - Fmod studio API plugin for MOAI. Crossplatform sound support using the new fmod API that is free for Indies.

  520.  

  521.  

  522. [5:53]

  523. where are you getting your moai-fmod stuff from

  524.  

  525. [5:53]

  526. that link doesn't have those calls

  527.  

  528. [5:54]

  529. (doesn't even have beat detector)

  530.  

  531. naturally [5:54 PM]

  532. ah - i am using the code from the cloudteampro repo

  533.  

  534. halfnelson [5:54 PM]

  535. yeah well that will be bleeding edge

  536.  

  537. [5:54]

  538. 1.6+

  539.  

  540. [5:54]

  541. that link i pasted is to an older version

  542.  

  543. [5:55]

  544. so maybe you can pinch stuff from there

  545.  

  546. [5:55]

  547. (since it is certainly for 1.5)

  548.  

  549. naturally [5:56 PM]

  550. lol k

  551.  

  552. [5:56]

  553. my hunch was right about an older vers

  554.  

  555. halfnelson [5:57 PM]

  556. yep

  557.  

  558. [5:57]

  559. on the money :slightly_smiling_face:

  560.  

  561. naturally [6:12 PM]

  562. hmm - seems a step further ... but not quite catching

  563.  

  564. [6:12]

  565. Scanning dependencies of target moai-fmod-studio

  566. [100%] Building CXX object third-party/fmod-studio/CMakeFiles/moai-fmod-studio.dir/home/sundrop/Engines/moai/15sdl/src/moai-fmod-studio/host.cpp.o

  567. [100%] Building CXX object third-party/fmod-studio/CMakeFiles/moai-fmod-studio.dir/home/sundrop/Engines/moai/15sdl/src/moai-fmod-studio/MOAIFmodStudioChannel.cpp.o

  568. [100%] Building CXX object third-party/fmod-studio/CMakeFiles/moai-fmod-studio.dir/home/sundrop/Engines/moai/15sdl/src/moai-fmod-studio/MOAIFmodStudioSound.cpp.o

  569. [100%] Building CXX object third-party/fmod-studio/CMakeFiles/moai-fmod-studio.dir/home/sundrop/Engines/moai/15sdl/src/moai-fmod-studio/MOAIFmodStudio.cpp.o

  570. [100%] Linking CXX static library libmoai-fmod-studio.a

  571. [100%] Built target moai-fmod-studio

  572. Scanning dependencies of target host-modules

  573. [100%] Linking CXX executable moai

  574. ../third-party/fmod-studio/libmoai-fmod-studio.a(MOAIFmodStudioChannel.cpp.o): In function `MOAIFmodStudioChannel::IsPlaying()':

  575. MOAIFmodStudioChannel.cpp:(.text+0x130e): undefined reference to `FMOD_Channel_IsPlaying'

  576.  

  577. naturally [6:18 PM]

  578. not sure how that is possible

  579.  

  580. naturally [6:27 PM]

  581. the function is in "fmod.h" ... how could it even compile that far

  582.  

  583. [6:31]

  584. hmmm "../third-party/fmod-studio/libmoai-fmod-studio.a" isnt the right path

  585.  

  586. [6:32]

  587. should be "../third-party/fmod-studio/lib/linux/libmoai-fmod-studio.a"

  588.  

  589. [6:34]

  590. nm thats probably cmake's dirs...

  591.  

  592. naturally [6:49 PM]

  593. somehow the .a file isnt able to see FMOD's .h header files?

  594.  

  595. halfnelson [8:23 PM]

  596. it can see the headers fine

  597.  

  598. [8:23]

  599. it cant see the implementation

  600.  

  601. [8:24]

  602. the link step seems to be missing libfmod

  603.  

  604. [8:24]

  605. for FMOD_Channel_IsPlaying isn't actually implemented in the so file you gave it

  606.  

  607. naturally [8:25 PM]

  608. maybe i need an older version of fmod?  i'm using one of the latest

  609.  

  610. halfnelson [8:27 PM]

  611. you need the one that matches the header files

  612.  

  613. [8:27]

  614. so make sure your fmod headers match the .so file

  615.  

  616. naturally [8:43 PM]

  617. ah

  618.  

  619. naturally [8:52 PM]

  620. k confusion time again... the header files included in vavius repo appear to be for api/lowlevel which match to "libfmod.so/a"... not for libfmodstudio.so/a

  621.  

  622. [8:52]

  623. so do we need to have both?

  624.  

  625. [8:53]

  626. or is the whole "studio" thing a misnomer and we are working with "lowlevel"

  627.  

  628. [8:55]

  629. rebuilding against lowlevel ...

  630.  

  631. [8:59]

  632. that was it!  builds ... seems to detect FMOD lua-side!  will test soon  :slightly_smiling_face:

  633.  

  634. [8:59]

  635. thanks halfnelson

  636.  

  637. [8:59]

  638. (will write up a little how-to for forums as well)

  639.  

  640. halfnelson [8:59 PM]

  641. groovy

  642.  

  643. [9:00]

  644. np

  645.  

  646. naturally [9:03 PM]

  647. that's actually not hard, i just messed up at pretty much every step.  par for the course lol

  648.  

  649. halfnelson [9:06 PM]

  650. if you got it first go you wouldn't have learnt anything

  651.  

  652. naturally [9:19 PM]

  653. hahah.  so optimistic.  i am getting a sound.  will have to look at FMOD a bit, seems like a slightly diff approach than untz

  654.  

  655. halfnelson [9:19 PM]

  656. but I understand how annoying it can be when you are fighting with your tools

  657.  

  658. naturally [9:19 PM]

  659. it has channels that it plays sounds thru.  not sure if needs a channel per sound or what

  660.  

  661. halfnelson [9:19 PM]

  662. it is like 100% of software only works 80% of the time and the other 20% is a pain in the arse

  663.  

  664. [9:19]

  665. sound like vavius questions, i have never used it

  666.  

  667. naturally [9:20 PM]

  668. well i have spent an uncomfortable amount of time getting tool-side stuff to work with me

  669.  

  670. [9:20]

  671. and while i have learned, i also could use those months back :stuck_out_tongue:

  672.  

  673. halfnelson [9:20 PM]

  674. yeah

  675.  

  676. [9:21]

  677. same atm for work, we are using ExtJS and it is a huge beast

  678.  

  679. [9:21]

  680. that is poorly documented

  681.  

  682. [9:21]

  683. just frustrating

  684.  

  685. naturally [10:10 PM]

  686. Uck

  687.  

  688.  

  689. ----- Yesterday April 20th, 2017 -----

  690. vavius [3:37 AM]

  691. added this C++ snippet

  692. ----------------------------------------------------------------------------------------------------

  693. -- @type FmodSoundEngine

  694. --

  695. -- This is FmodSoundEngine class using MOAIFmodStudio

  696. ----------------------------------------------------------------------------------------------------

  697. Add Comment Click to expand inline 150 lines

  698.  

  699. vavius [3:37 AM]

  700. @naturally I use this wrapper

  701.  

  702. [3:38]

  703. not usable as it is, because it depends on my `ResourceMgr` and `class()`

  704.  

  705. [3:39]

  706. You are right about that this is low-level api and has nothing to do with studio actually

  707.  

  708. [3:43]

  709. The main fmod low-level concept is Channel. This is a thing that can make sound file audible. You set volume, pan, dst effects on the channel.

  710.  

  711. [3:45]

  712. There also a channel group, it will apply volume, etc to all child channels.

  713. I haven't exposed channel groups to Lua, but use them to distinguish between background music and sound effects. You can mute them separately

  714.  

  715. [3:48]

  716. `sfxChannel:setReusable(true)` tells a MOAIFmodStudioChannel that it should create a new underlying channel when you call `play()` on it, so that any sound played by that channel will be still audible.

  717.  

  718. [3:49]

  719. There is no limit on the number of channels.

  720.  

  721. halfnelson [5:21 AM]

  722. Thanks !

  723.  

  724. naturally [6:50 AM]

  725. thanks vavius - i'm guessing playing a sound on the same channel causes the previous sound to stop then... well, i'll read the fmod docs :slightly_smiling_face:

  726.  

  727. vavius [7:03 AM]

  728. my wrapper is pretty high-level

  729.  

  730. [7:03]

  731. fmod docs won't help you much...

  732.  

  733. [7:04]

  734. load your sound files into `MOAIFmodStudioSound`. You can do it once and cache, they are meant to be reusable.

  735.  

  736. [7:05]

  737. then play them with `MOAIFmodStudioChannel`

  738.  

  739. [7:05]

  740. basically just it.

  741.  

  742. naturally [7:05 AM]

  743. ok.  im still not clear on one thing, but i think i know the answer.  one channel can only have one sound playing at a time?

  744.  

  745. vavius [7:05 AM]

  746. yes

  747.  

  748. naturally [7:07 AM]

  749. it seems like an ordeal to worry about whether new sounds will need a new channel or not...

  750.  

  751. vavius [7:07 AM]

  752. but you can have a single `MOAIFmodStudioChannel` with `:setReusable(true)`

  753.  

  754. [7:08]

  755. then it will spawn new channels if old sound is still playing

  756.  

  757. naturally [7:08 AM]

  758. ah.  perfect :slightly_smiling_face:

  759.  

  760. vavius [7:08 AM]

  761. so for sfx you always want that reusable flag

  762.  

  763. naturally [7:10 AM]

  764. for the sake of argument - what would happen if you create a channel every time u play a sound?  seems like fmod will clean up unused channels

  765.  

  766. [7:11]

  767. or would that be slower

  768.  

  769. vavius [7:18 AM]

  770. just an optimisation for mobile

  771.  

  772. [7:19]

  773. every MOAILuaObject is something about 3 or 4 tables

  774.  

  775. vavius [7:25 AM]

  776. Just my preference to reuse stuff. Less pressure on gc and less memory usage. Some time ago this made a difference when you had only 50-100mb of RAM available on iPad 1 or iPhone 4

  777.  

  778. naturally [7:28 AM]

  779. yeah. i agree.  just curious.  lol i'm at 49.3 MB on my android APK.  moving to FMOD means an extra 2mb.  i'll have to cut a song or something now

  780.  

  781. vavius [7:29 AM]

  782. nah

  783.  

  784. [7:29]

  785. limit is 100

  786.  

  787. naturally [9:16 AM]

  788. apparently they changed it back to 50

  789.  

  790. vavius [10:00 AM]

  791. sure?

  792.  

  793. [10:00]

  794. I know our guys uploaded an apk yesterday, it was ~65mb

  795.  

  796. [10:01]

  797. ah, that is dependant on android target.

  798.  

  799. [10:01]

  800. api level or smth.

  801.  

  802. [10:02]

  803. We use 15 or 16.

  804.  

  805. [10:04]

  806. https://developer.android.com/about/dashboards/index.html

  807. developer.android.com

  808. Dashboards | Android Developers

  809. An overview of device characteristics and platform versions that are active in the Android ecosystem.

  810.  

  811. [10:05]

  812. api level 16 is supported on 98% devices

  813.  

  814. naturally [11:30 AM]

  815. not 100% sure but it rejects anything over 50mb for me

  816.  

  817. naturally [2:09 PM]

  818. hmm the only way to check in fmod is a specific sound is playing, is for it to have it's own channel... to avoid having the same sound building up... like many laser blasts... in Untz i can ask "sound:isPlaying()" and then decide what to do.  i wonder if it will be too slow to have a generalized channel per sound... or maybe just flag the problem sounds as needing their own channels

  819.  

  820. [2:10]

  821. in FMOD the ":isPlaying()" call is only for the channel

  822.  

  823. naturally [2:18 PM]

  824. unless, you could get which sound is playing from the channel

  825.  

  826. [2:19]

  827. FMOD_Channel_GetCurrentSound

  828.  

  829. naturally [2:42 PM]

  830. also, playing multiple sounds at different volumes on the same channel, doesnt seem possible, since the channel controls the volume

  831.  

  832. [2:43]

  833. lots of differences.  i like how fmod is set up, its just different.  and odd to fit my current audio paradigm into a new one

  834.  

  835. [2:44]

  836. splitting my Audio class into handling two engines.  working so far, just lacking subtleties of before

  837.  

  838. [2:46]

  839. starting to wonder if fixing Untz might be better, heh

  840.  

  841. halfnelson [4:47 PM]

  842. Untz interface isn't too horrible maybe you can just write an api compatible implementation with fmod

  843.  

  844. [4:48]

  845. Vavius do you have stats on what percentage of players leave audio and music enabled

  846.  

  847.  

  848. ----- Today April 21st, 2017 -----

  849. naturally [6:11 AM]

  850. I have a successful re-creation of Untz-style sound with FMOD

  851.  

  852. [6:11]

  853. if not Audio.fmod_channels[name] then

  854.     local channel = MOAIFmodStudioChannel.new()

  855.     channel:play(sound)

  856.     channel:setVolume(volume)                    

  857.     Audio.fmod_channels[name] = channel

  858. else

  859.     local channel = Audio.fmod_channels[name]

  860.     if not channel:isPlaying() then

  861.         channel:play(sound)

  862.         channel:setVolume(volume)                        

  863.     end

  864. end

  865.  

  866. [6:12]

  867. my concern is, will this cause a memory issue?  does that look ok vavius?  at the end of every level, I :stop and release all the fmod channels

  868.  

  869. [6:15]

  870. basically, it avoids playing the same sound more than once at a time.  this would probably create ~50 channels during play, but as most of them become notPlaying, i hope fmod wont slowdown because of it... i could maybe do custom GC to release the channels that arent playing



Why FMOD? Well, Untz is great but keeps throwing random crashes here and there from :setPosition and AudioMixer::process, that I can't reproduce, even with 1.6 fixes.

:mrgreen:
Image - Don't Be Patchman - a sneak-and-grow adventure!
User avatar
naturally
 
Posts: 706
Joined: Thu Aug 29, 2013 8:05 pm
Location: Canada

Return to Sound + Music

Who is online

Users browsing this forum: No registered users and 1 guest

cron

x