def init(freq, stereo, samples, status=False, equal_mono=False): """ Initializes the audio system with the given parameters. The parameter are just informational - the audio system should be able to play all supported files. `freq` The sample frequency to play back at. `stereo` Should we play in stereo (generally true). `samples` The length of the sample buffer. `status` If true, the sound system will print errors out to the console. ` """ renpy.config.debug_sound = True js = renpy.loader.load("_audio.js").read() emscripten.run_script(js) return True
def call(function, *args): """ Calls a method on `function`. """ emscripten.run_script("renpyAudio.{}.apply(null, {});".format( function, dumps(args)))
def load_script(): """ Loads the javascript required for webaudio to work. """ global loaded if not loaded: js = renpy.loader.load("_audio.js").read() emscripten.run_script(js) loaded = True
def end(): """ Called just before we initialize the display to hide the presplash. """ global window if renpy.emscripten: # presplash handled on the JavaScript side, because emscripten # currently does not support destroying/recreating GL contexts import emscripten emscripten.run_script(r"""presplashEnd();""") if window is None: return window.destroy() window = None
def end(): """ Called just before we initialize the display to hide the presplash. """ global window if renpy.emscripten: # presplash handled on the JavaScript side, because emscripten # currently does not support destroying/recreating GL contexts; # in addition browsers support animated webp import emscripten emscripten.run_script(r"""presplashEnd();""") if window is None: return window.destroy() window = None # Remove references to presplash images global progress_bar progress_bar = None
def end(): """ Called just before we initialize the display to hide the presplash. """ global keep_running global event_thread global window if renpy.emscripten: # presplash handled on the JavaScript side, because emscripten # currently does not support destroying/recreating GL contexts import emscripten emscripten.run_script(r"""presplashEnd();""") if window is None: return keep_running = False event_thread.join() window.destroy() window = None
def __del__(self): emscripten.run_script(r'''RenPyWeb.dl_free({});'''.format(self.id))
emscripten.run_script(r"""RenPyWeb = { xhr_id: 0, xhrs: {}, dl_new: function(path) { var xhr = new XMLHttpRequest(); xhr.responseType = 'arraybuffer'; xhr.onerror = function() { console.log("Network error", xhr); }; xhr.onload = function() { if (xhr.status == 200 || xhr.status == 304 || xhr.status == 206 || (xhr.status == 0 && xhr.response)) { // Create file reusing XHR's buffer (no-copy) try { FS.unlink(path); } catch(error) {} FS.writeFile(path, new Uint8Array(xhr.response), {canOwn:true}); } else { console.log("Download error", xhr); } }; xhr.open('GET', path); xhr.send(); RenPyWeb.xhrs[RenPyWeb.xhr_id] = xhr; var ret = RenPyWeb.xhr_id; RenPyWeb.xhr_id++; return ret; }, dl_get: function(xhr_id) { return RenPyWeb.xhrs[xhr_id]; }, dl_free: function(xhr_id) { delete RenPyWeb.xhrs[xhr_id]; // Note: xhr.response kept alive until file is unlinked }, }; """)