Author Topic: How heavy module music is?  (Read 719 times)

Offline RyanBram

  • Active artist
  • *
  • Posts: 30
  • Operating System: Windows
How heavy module music is?
« on: April 08, 2017, 10:37:19 »
Hi, community.
I have plan to use libopenmpt.js for creating web based game. I am using tool that make non programmer like me to fullfilll the task. The only problem is the tool/engine doesn't support module music format and I prefer it over ogg because of filesize. I have 2 questions.
The questions are:
1. How much computer resources are needed to playback format like IT or MPTM compared to MIDI or OGG Vorbis?
2. How fast is libopenmpt.js to playback module music file? Can it be use for real time playback without lag or performance penalty?

Thanks.
« Last Edit: April 11, 2017, 03:30:25 by RyanBram »

Offline manx

  • OpenMPT Developers
  • *****
  • Posts: 105
Re: How heavy module music is?
« Reply #1 on: April 08, 2017, 12:07:59 »
Hi, community.
I have plan to use libopenmpt.js for creating web based game. I am using tool that make non programmer like me to fullfilll the task. The only problem is the tool/engine doesn't support module music format and I prefer it over ogg because of filesize. Before I invest my money for programmer, I have 2 qustions.

libopenmpt.js comes at a size cost itself, thus you probably have to include that also in your calculations (it may very well still be less in size than ogg or mp3 tracks).

1. How much computer resources are needed to playback format like IT or MPTM compared to MIDI or OGG Vorbis?

libopenmpt.js is rather big (about 2.4MB of Javascript code). Additionally, the whole module file has to be loaded by libopenmpt.js, which (temporarily during loading) requires (roughly) twice the amount of memory as the module file consumes on disk. During playback, roughly the module size plus some internal structures (which are not really that big) of memory is required. If the module uses sample compression, all sample data will be uncompressed during loading and be stored uncompressed in memory.

2. How fast is libopenmpt.js to playback module music file? Can it be use for real time playback without lag or performance penalty?

I am not aware of anyone using libopenmpt.js in a Javascript game engine so far. Realtime playback is certainly possible and used by various websites (although for module playback only, without a game engine running additionally). CPU consumption is (depending on the Javascript engine and browser) roughly at worst 2 times the CPU consumption of native playback (so far, noone has done precise benchmarks, afaik).
Rather technical aspect: I am not sure if it would be possible to put libopenmpt.js rendering into a separate WebWorker (I am not a Javascript expert and thus I have never tried that). That would allow libopenmpt.js to run in a separate thread than the game engine, which would allow it to use a separate CPU core concurrently. If that is not possible (or not implemented by your game), libopenmpt.js will have to compete with the rest of your game for CPU time.

Even though we would certainly like to see people experimenting with libopenmpt.js in web-based games, I am not quite sure if I could recommend that usage. You will certainly have less hassle if you are using AAC or Ogg Vorbis playback provided by the browsers and your game engine.

Offline Saga Musix

  • OpenMPT Developers
  • *****
  • Posts: 6,128
  • aka Jojo
    • Download music, samples, VST plugins: Saga Musix Website
  • Operating System: Windows 7 x64
Re: How heavy module music is?
« Reply #2 on: April 08, 2017, 12:47:09 »
As manx says, you would have to experiment and check if libopenmpt can be run in a WebWorker, as running libopenmpt in the main JavaScript thread is really unsuitable for the game. It's one of the reasons why e.g. libopenmpt playback via chiptune2.js often stalls when switching tabs - the browser is ismply busy doing other things in the main thread.
» No support, bug reports, feature requests via private messages - they will not be answered. Use the forums and the issue tracker so that everyone can benefit from your post.

Offline RyanBram

  • Active artist
  • *
  • Posts: 30
  • Operating System: Windows
Re: How heavy module music is?
« Reply #3 on: April 10, 2017, 06:58:22 »
Thank you, Manx and Saga for the detailed explanation and suggestion.
I will take your suggestions and tell my programmer, especially about WebWorker and will inform you about the result, so everyone will get benefit from the information.

Best regards,
RyanBram

Offline RyanBram

  • Active artist
  • *
  • Posts: 30
  • Operating System: Windows
Re: How heavy module music is?
« Reply #4 on: June 16, 2017, 03:22:50 »
Hi, everyone.

My programmer has finished the engine for my game. When I tried the result, some modules can be played flawlessly, but some modules will sounds noised for the first time they are played. If they are played second time, they will be played flawlessly. Then I tried to playback my module using chiptune2.js sample project from GitHub and the problem also appear.

My questions are:
1. Does the problem come because the complexity of my module music?
2. Does the problem related to the CPU that I use (Intel Atom X5-Z8300)?
3. Is it possible to improve libopenmpt for better performance in Javascript?

Thank you for your attention.

Note:
I attached my MPTM music if somebody want to analyze it using Chiptune2.js.

Offline manx

  • OpenMPT Developers
  • *****
  • Posts: 105
Re: How heavy module music is?
« Reply #5 on: June 16, 2017, 07:58:06 »
My programmer has finished the engine for my game. When I tried the result, some modules can be played flawlessly, but some modules will sounds noised for the first time they are played. If they are played second time, they will be played flawlessly.

This can have various reasons:
1. The Javascript VM Just-in-Time compiler might have to recompile parts of libopenmpt multiple times when it encouters previously unexercised code paths during playback.
2. The Javascript VM garbage collector kicking in and stalling the whole Javascript execution at unfortunate times or for unfortunately long intervals.

Then I tried to playback my module using chiptune2.js sample project from GitHub and the problem also appear.

Very likely exactly the same issue. I can also hear occasional stutter.

1. Does the problem come because the complexity of my module music?

Maybe, maybe not. If less time is consumed for rendering the module by libopenmpt, it is more likely that whatever the Javascript VM has to do additionally still manages to finish in time.

2. Does the problem related to the CPU that I use (Intel Atom X5-Z8300)?

That CPU is REALLY slow. So trying with a faster CPU will almost certainly improve things. Also, do try different Javascript VMs or browsers. They all have very different performance characteristics that might or might not also affect this.

3. Is it possible to improve libopenmpt for better performance in Javascript?

There is nothing Javascript specific being done in libopenmpt at the moment and I doubt that anything Javascript-specific would help here. Short of the CPU being just too slow (which can be fixed by either using a faster CPU or general libopenmpt performance optimizations (which generally always happen, we certainly do not make libopenmpt slower for no reason)), there is probably nothing that can be done here. Your developer might want to look into the issue from the Javascript side and analyse where exactly the cause for not rendering timely is. libopenmpt itself does not do anything that would explain the stuttering.

Offline RyanBram

  • Active artist
  • *
  • Posts: 30
  • Operating System: Windows
Re: How heavy module music is?
« Reply #6 on: June 20, 2017, 03:57:15 »
OK.
Thanks a lot for every information you gave to me. ;D

Offline Saga Musix

  • OpenMPT Developers
  • *****
  • Posts: 6,128
  • aka Jojo
    • Download music, samples, VST plugins: Saga Musix Website
  • Operating System: Windows 7 x64
Re: How heavy module music is?
« Reply #7 on: June 21, 2017, 00:29:11 »
I cannot stress enough once again that if all you want to use in your game are simple MIDI-to-MOD conversions, then you would be better off using something like MIDI.js with an optimized soundfont. Since this library uses the browsers' built-in WebAudio mixing capabilities, its performance will most likely be much better than libopenmpt which has to do all the mixing in JavaScript. Currently you are taking a detour that is both bigger and slower than using a proper JavaScript solution.
» No support, bug reports, feature requests via private messages - they will not be answered. Use the forums and the issue tracker so that everyone can benefit from your post.