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

Offline RyanBram

  • Active artist
  • *
  • Posts: 35
  • 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: 160
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,303
  • 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: 35
  • 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: 35
  • 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: 160
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: 35
  • 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,303
  • 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.

Offline RyanBram

  • Active artist
  • *
  • Posts: 35
  • Operating System: Windows
Re: How heavy module music is?
« Reply #8 on: June 27, 2017, 08:01:04 »
Hi, Saga.   :D
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. ...

Please don't misunderstanding me. I think I never mentioned about MIDI conversion in this topic. ;D
Maybe you said like that after you examined my attached module which is a converted MIDI Music. About the attached music, it just an example, because it is pretty much cheaper to convert the existing MIDI into MPTM than paying someone to create MPTM counterpart from scratch for the existing MIDI. Don't worry, the rest of my musics is true Module musics.

Actually my reason to use the following methods to test libopenmpt.js capabilities are:

  • I use nw.js for testing my game;
  • My programmer use chiptune2.js and libopenmpt.js as bases for my game module playback engine;
  • I use Intel Atom, because  I want to make sure if libopenmpt.js is suitable for mobile game or low end device;
  • I use the converted MIDI to Module to benchmark how complex the module after conversion and how good libopenmpt.js will handle;
  • I use several music from MOD Archive to do some testing, and I still heard the problem like I found in converted MIDI to Module. One of the music is FFVIII Boss Battle.

...
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.
...
This is a very valuable information. Are there any plans to add "browsers' built-in WebAudio mixing capabilities" in libopenmpt.js?

And if it really needed, I can share my game engine to you for examining purpose. I plan to make it opensource on GitHub after I am really sure it is stable enough.

Thanks :)
« Last Edit: June 27, 2017, 08:04:27 by RyanBram »

Offline manx

  • OpenMPT Developers
  • *****
  • Posts: 160
Re: How heavy module music is?
« Reply #9 on: June 27, 2017, 08:12:33 »
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.
This is a very valuable information. Are there any plans to add "browsers' built-in WebAudio mixing capabilities" in libopenmpt.js?

No, this will never happen. libopenmpt is not meant to make use of any external mixing routines and never will be (neither any hardware accelerated mixing, nor platform provided mixing (like some Javascript API in browsers)).

Offline Saga Musix

  • OpenMPT Developers
  • *****
  • Posts: 6,303
  • aka Jojo
    • Download music, samples, VST plugins: Saga Musix Website
  • Operating System: Windows 7 x64
Re: How heavy module music is?
« Reply #10 on: June 27, 2017, 10:15:14 »
To add to what manx said, if you add browser-specific mixing routines to libopenmpt, you can just as well create a whole module player in JavaScript. Please do not (mis)understand "emscripten is a supported target" as "we will do everything to make libopenmpt run the best possible way in browsers". The focus for libopenmpt is clearly on native execution. Current trends indicate that JavaScript is going to evolve further so in the future we might have just the same performance in browsers as we have with libopenmpt in a classic C/C++ environment, but this point is not reached yet.

One further random tip that should especially help with atom: libopenmpt by default uses 8-point polyphase interpolation. Reducing this to 4-point cubic spline or even 2-point linear (through openmpt_set_render_param) should greatly improve mixing performance. Even reduing the sample rate to 32kHz or so may help. You may want to add those options to your game to make the audio consume less CPU time for less powerful CPUs.
« Last Edit: June 27, 2017, 11:51:44 by Saga Musix »
» 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.