Author Topic: libopenmpt emscripten/wasm into AudioWorkletProcessor  (Read 356 times)

Offline jllodra

  • Active artist
  • *
  • Posts: 11
Re: libopenmpt emscripten/wasm into AudioWorkletProcessor
« Reply #15 on: January 11, 2021, 11:55:41 »
Built with the patch, and it works without the performance.now polyfill.

The thing is that the performance.now code is still there in the libopenmpt.js, but not called (at least not when loading and playing a song, which is what I'm doing).

Edit: had a look at https://github.com/emscripten-core/emscripten/blob/master/src/library.js#L2934 to see the actual code and why performance.now is there. Anyway, I have proved that with patch, _clock_gettime is called and that uses Date.now internally.
« Last Edit: January 11, 2021, 12:32:38 by jllodra »

Offline manx

  • OpenMPT Developers
  • *****
  • Posts: 278
Re: libopenmpt emscripten/wasm into AudioWorkletProcessor
« Reply #16 on: January 11, 2021, 12:36:23 »
Built with the patch, and it works without the performance.now polyfill.

Thanks for testing.

https://source.openmpt.org/browse/openmpt/?op=revision&rev=14045 will be in the next release of every branch.

Offline jllodra

  • Active artist
  • *
  • Posts: 11
Re: libopenmpt emscripten/wasm into AudioWorkletProcessor
« Reply #17 on: January 11, 2021, 12:47:48 »
Nice, thanks.

Regarding the random numbers, I can't see why emscripten can't rely on Math.random() when crypto is now found, do you happen to have an idea?
I understand that it has not enough entropy level from a cryptography point of view, but I wonder if this would have an impact.

https://github.com/emscripten-core/emscripten/issues/542

EDIT: OH, they USED TO fallback on Math.random, but not anymore: https://github.com/emscripten-core/emscripten/blob/master/src/library.js#L2858
I have just changed crypto to Math.random and it works, I cannot hear any difference in the music.
« Last Edit: January 11, 2021, 12:52:13 by jllodra »

Offline manx

  • OpenMPT Developers
  • *****
  • Posts: 278
Re: libopenmpt emscripten/wasm into AudioWorkletProcessor
« Reply #18 on: January 11, 2021, 12:50:47 »
I have added a ticket to our issue tracker for the Makefile changes: https://bugs.openmpt.org/view.php?id=1407.


Offline jllodra

  • Active artist
  • *
  • Posts: 11
Re: libopenmpt emscripten/wasm into AudioWorkletProcessor
« Reply #19 on: January 11, 2021, 12:58:07 »
This code at the beginning of the Module

Code: [Select]
const crypto = {
  getRandomValues: (array) => {
    for (let i = 0; i < array.length; i++) {
      array[i] = (Math.random()*256)|0;
    }
  }
};

and no need for third party polyfills...
« Last Edit: January 11, 2021, 14:35:32 by jllodra »