Note: This has been done with Mac or Windows operating systems in mind. If any Linux user would like to add to this, that would be most welcomed.
You will need to install them. You do not need to install FMOD Studio for this to work. You can install only the API for your system. However, you will need FMOD Studio 1.10.20 in order to create bank files.
For your game, add a folder called python_plugins
Windows (on Windows 10):
Add all files in C:\Program Files(x86)\FMOD SoundSystem\FMOD Studio API Windows\api\lowlevel\lib to python_plugins
Add all files in C:\Program Files(x86)\FMOD SoundSystem\FMOD Studio API Windows\api\studio\lib to python_plugins
Add all files in C:\Program Files(x86)\FMOD SoundSystem\FMOD Studio API Windows\api\studio\examples\media to python_plugins
Mac:
Open DMG file that you downloaded and place the folder in a desired location, but not in your game's directory.
Add all files in FMOD Programmers API/api/lowlevel/lib
Add all files in FMOD Programmers API/studio/lib
Add all files in FMOD Programmers API/studio/examples/media
Create the following python file and have it saved in python_plugins and save it as FMOD_Studio.py or write it into a python block:
Code: Select all
import os
import platform
from sys import path
from ctypes import *
for n in range(0,len(path)):
if path[n].find(<Name of your game>) != -1:
if platform.system() == "Windows":
new_dir = path[n] + "\game\python_plugins"
if new_dir in path:
break
elif platform.system() == "Darwin":
new_dir = path[n] + "/game/python_plugins"
else:
raise NameError("Game directory/folder could not be found.")
path.append(new_dir)
break
os.chdir(path[-1])
PLATFORM_SUFFIX = '64' if sizeof(c_voidp) == 8 else ""
VERSION = 0x00011020
BANK_FILES = ["Master Bank.bank","Master Bank.strings.bank","SFX.bank"]
studio_dll = None
studio_sys = None
def check_result(r):
if r != 0:
print("ERROR: Got FMOD_Result {0}".format(r))
def studio_init():
print("Initializing FMOD Studio");
global studio_dll
global studio_sys
# Windows
if platform.system() == "Windows":
studio_dll = WinDLL("fmodstudioL" + PLATFORM_SUFFIX)
lowlevel_dll = WinDLL("fmodL" + PLATFORM_SUFFIX)
# MacOS
else:
lowlevel_dll = cdll.LoadLibrary("libfmodL.dylib")
studio_dll = cdll.LoadLibrary("libfmodstudioL.dylib")
check_result(lowlevel_dll.FMOD_Debug_Initialize(0x00000002, 1, 2, "log.txt".encode('ascii')))
studio_sys = c_voidp()
check_result(studio_dll.FMOD_Studio_System_Create(byref(studio_sys), VERSION))
check_result(studio_dll.FMOD_Studio_System_Initialize(studio_sys,256,0,0,c_voidp()))
for bankname in BANK_FILES:
print("Loading bank: " + bankname)
bank = c_voidp()
check_result(studio_dll.FMOD_Studio_System_LoadBankFile(studio_sys, bankname.encode('ascii'), 0, byref(bank)))
def play_sound(soundname):
event_desc = c_voidp()
check_result(studio_dll.FMOD_Studio_System_GetEvent(studio_sys, soundname.encode('ascii'), byref(event_desc)))
event_inst = c_voidp()
check_result(studio_dll.FMOD_Studio_EventDescription_CreateInstance(event_desc, byref(event_inst)))
check_result(studio_dll.FMOD_Studio_EventInstance_SetVolume(event_inst, c_float(0.75)))
check_result(studio_dll.FMOD_Studio_EventInstance_Start(event_inst))
check_result(studio_dll.FMOD_Studio_EventInstance_Release(event_inst))
check_result(studio_dll.FMOD_Studio_System_Update(studio_sys))
studio_init()
Running FMOD_Studio.py in Python 2.7 IDE:
Code: Select all
play_sound("event:/Weapons/Explosion")
Code: Select all
python:
from sys import path
import platform
import os
for n in range(0,len(path)):
if path[n].find(<Name of your game>) != -1:
if platform.system() == "Windows":
new_dir = path[n] + "\game\python_plugins"
if new_dir in path:
break
elif platform.system() == "Darwin":
new_dir = path[n] + "/game/python_plugins"
else:
raise NameError("Game directory/folder could not be found.")
path.append(new_dir)
break
os.chdir(path[-1])
import FMOD_Studio
This works completely fine on Mac but fails on Windows when ran in Ren'Py in a python block or attempting to import FMOD_Studio.py as a module. I have gotten it to work on Windows before
The following trackback occurs in Ren'Py:
FMOD_Studio.py:
studio_dll = WinDLL("fmodstudioL" + PLATFORM_SUFFIX)
File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/ctypes/__init__.py", line 443, in LoadLibrary
File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/ctypes/__init__.py", line 365, in __init__
WindowsError:[Error 126] The specified module could not be found
This error is not version dependent. I am using 6.99 for my game due to it being better optimized for that version than more recent iterations of Ren'Py. And attempting to run version 6.99 or 7.5 of Ren'Py always results in this error.
I would like to be able to release Python code that anyone in the Ren'Py community can use this in any Ren'Py project for any platform and/or have versions specified for one platform (e.g. Mac, Windows, or Linux).
If you want me to provide a test version of this for you to run for yourself, I will be more than happy to provide that.