MusIT

Deeper dive in MPTK


*** Under construction ***

Enable debug features

Maestro MPTK is a sophisticated application: real-time music playback requires significant optimization and intricate algorithms. We utilize specific functions to assist us during the testing phase. However, you can also utilize these features. With this information, you’ll be able to delve into the internal settings of both the MIDI Sequencer and the MIDI Synth, check the playing accuracy, monitor CPU usage …

Scripting symbols

Maestro MPTK debug functions can be activated with scripting define symbols.
You can define these symbols in Unity menu Edit / Project Settings … and Player tab.
Don’t forget to click on button apply when modifying the symbols, that will compiling the C# scripts and unlock debug features.

Unity menu Edit / Project Settings …

Warning: enabling these debug functions will consume more CPU and memory. Remove them when you want to publish a version of your app.

DEBUG_PERF_MIDI

Calculate time around the MIDI sequencer execution.

  • StatDeltaThreadMidiMS: The time between two call of the MIDI sequencer. An important information, it’s a measure of the music accuracy. A value of 10 ms is very good, above 30 ms you might notice some rhyme variations. Displayed: Delta
  • StatDeltaThreadMidiMIN, StatDeltaThreadMidiMAX, StatDeltaThreadMidiMA: minimum, maximum, average for StatDeltaThreadMidiMS.
  • StatDeltaTimeMidi: The time between reading two groups of event. Displayed: TimeBetweenMidi
  • StatReadMidiMS: The time to read a group of MIDI event (same ticks). In general close to 0. Displayed: Read
  • StatProcessMidiMS: The time to process the group of events read. For example with a note-on event, create (or use from cache) each voice and initialize synthesizer parameters. Displayed: Treat

DEBUG_PERF_AUDIO

  • DeltaTimeAudioCall: The time between call to audio synth. An important information, this time measures how often the audio data is built and sent to the sound card. It’s the measure of the latency. A value of 10 ms is good, above 30 ms you might notice some delay between a user action and the sound. Displayed: Delta.
  • StatAudioFilterReadMS: The time taken by the MIDI synthesizer to generate the audio data. Displayed: Time.
  • StatAudioFilterReadMIN, StatAudioFilterReadMAX, StatAudioFilterReadAVG: minimum, maximum, average for StatAudioFilterReadMS.

DEBUG_STATUS_STAT

  • Calculate and display the state of each voice: On / Sustain / Release which is related to the processing of the volume envelope: ADSR. Display voices count:
    • Voice On for voice in Attack or Decay phase,
    • Sustain,
    • Release (the volume of the  sound when the note is released, generally decrease quickly)

DEBUG_HISTO_SYNTH

  • Calculate and display the historic for three main statistics for the last 21 frames build by the MIDI synthesizer. There is three values for each frames enclose in []
    • Audio buffer length: Set by DspBufferSize in bytes.
    • DeltaTimeAudioCall: measure of the audio latency. Time scale: 100 = 1 millisecond.
    • StatAudioFilterReadMS: time taken by the MIDI synthesizer to generate the audio data. Time scale: 100 = 1 millisecond.

Display in the user interface

Display stats in a MPTK demo.

All these statistics are displayed when the demo TestMidiFilePlayerScripting is run.
Use Alt-D or Cmd-D to select this demo in the list: “Play MIDI with Script and Explore Features”.

Display stat in your app

With the MPTK API, you can retrieve the content of this display.

// Build synth information
// -----------------------
StringBuilder infoSynth = midiFilePlayer.synthInfo.MPTK_BuildInfoSynth(midiFilePlayer);

// Display synth information, here in a UnityEngine.UI.Text component.
TxtInfo.text = infoSynth.ToString();

Display Stat in the Oboe Demo

This demo has been created specifically to evaluate the performance of Oboe on Android: latency with different configuration of the buffer size and the frequency. However, it can also be utilized without Oboe, including in desktop applications!

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!