MusIT

WebGL build with Maestro MPTK


So late!

Why now? The persistent and frustrating Unity issue with looping inside a sample from a web build has finally been resolved by Unity. https://issuetracker.unity3d.com/issues/webgl-a-looping-audio-sounds-different-on-webgl-than-in-the-editor-slash-native-desktop-player

MPTK web build has been tested with Unity  6 and Unity 2022.3.

Working mode

When WebGL build is selected in the editor, some changes are applied to MPTK version 2.16 (coming soon):

  • Core mode is set to false: each couple note / instrument are played in a dedicated AudioSource.
  • Coroutines are used for MIDI sequencer (threads are not allowed with webGL, perhaps one day …).

The MPTK non core mode was the legacy mode for playing generated samples. The initial version released in 2018 achieved significant success, despite sound quality was suboptimal. So, I have decided to build a real synth process based on the OnAudioFilterRead callback. With core mode enabled, one AudioSource is able to play all samples (so, for each note-on) with a very low latency and an excellent stable timing. With core mode, there is only one AudioSource for each MIDI Synth (MidiFilePlayer, MisiStreamPlayer, …).

The legacy mode was notified as deprecated and to be removed in a future major version.

Unfortunately, callback OnAudioFilterRead with AudioSource is not implemented for web. Therefore, non core mode is mandatory for web build … and finally this mode will be retained with next MPTK version!

Limitations

  • Coroutine for MIDI sequencer is not perfect for accurate tempo.
  • Unity sound effects real-time modification by the MPTK API when playing is not unavailable (but there is a solution, perhaps for a future version). Happily SoundFont effects are working!
  • The sound quality is inferior to other platforms such as macOS, iOS Windows, and Android. Look above Working Mode chapter to understand why.
  • Select “Decompress On Load” when importing a SoundFont. MPTK Pro is needed for this action.
  • Audio Spatializer plugins like Steam Audio seems not implemented.
  • Prefab MidiSpatializer will not work.
  • Real-time loading soundfont from the web is not working (not yet compliant with non-core mode) but switching on local soundfont do the job.

Good points

  • The interactivity between your gameplay and the music works well. This is one of Maestro MPTK’s strengths: influencing the music by script (or the inverse!) according to the scenarios you have imagined.
  • Spatialization based on distance between MPTK Prefab and Listener is working.
  • Real-time loading soundfont from local soundfont is working.
  • SoundFont effects by the MPTK API is working but not dynamic change.

Quick how-to from a newer project

  1. Create a fresh project with Unity version >= 2022.3.
  2. Import Maestro MPTK Pro.
  3. Switch to Desktop build (Build settings) if not already done.
  4. From the menu Maestro / SoundFont setup,
    1. import a SoundFont,
    2. extract samples with “Decompress On Load”
  5. Switch platform to WebGL in Unity “Building setting”.
  6. Select the project you want to build  (try with MPTK demo like TestMidiFilePlayerScript).
  7. Build and run your project. When the webpage pop up, your project will be loaded and run. A first user action is requested to activate the sound in the web page.
Check samples from the soundfont are defined as “Decompress On Load”

*** to be continued ***

Have any Question or Comment?

Leave a Reply

Your email address will not be published. Required fields are marked *

I accept that my given data and my IP address is sent to a server in the USA only for the purpose of spam prevention through the Akismet program.More information on Akismet and GDPR.

Get MPTK from the Unity store

If you like Midi Player Tool Kit, please leave a review on the Asset Store. It’s very appreciated!!!

Maestro MPTK on ChatGPT!

From various MPTK documentation sources, @DarkSky42 has created a custom LLM based on ChatGPT. You can now ask all the questions you want and get a good level of answer: request code example, verify your source code, explain the MPTK demo …

Contact

If you have questions, please don’t hesitate to contact us via the dedicated Unity forum or our Discord  channel.

Reach the Discord archive by topic.

We are always happy to discuss your projects!