Skip to content

pedrolcl/minisynth-qt

Repository files navigation

Minimalist Music Synthesizer for Qt

This project is a proof of concept, and a minimalist multiplatform music monosynth prototype, using Qt Multimedia audio output. The synthesizer generates simple sine wave tones, which sound both dry and harsh, so they are not very useful for actual musical applications, except maybe for building a crude tuner.

Screenshot

The synth is implemented in the ToneSynthesizer class, that expects an AudioFormat defining floating point samples, a single channel (mono), and a sample rate of 44100 Hz (very typical specifications). The 13 precomputed note frequencies reside on a table initialized with an equal temperament chromatic scale. The notes may be transposed from octave 0 to octave 9 in scientific pitch notation octave denomination. There is no MIDI Input here. The only way to trigger sounds is using the note buttons.

Two alternative projects using a similar architecture, but leveraging much better music synthesizers and MIDI Input are FluidLite-QtMultimedia and Multiplatform-SonivoxEAS.

The Qt Multimedia audio output classes allow raw access to the system's audio output facilities, allowing applications to write raw data to speakers or other devices. This prototype has a control to choose the audio device, the volume level and to request a buffer size (by default 50 milliseconds).

The applied buffer size sometimes is not the same as the requested buffer size, but the real latency is usually a smaller value anyway. See the debug output of the program for the real values achieved in your system. Two type of errors are detected and reported to the user:

  • Underrun errors (warnings). It happens when the audio buffer is small. It produces audible sound glitches, but can be recovered automatically.
  • Audio output stalled errors. It happens when the audio buffer is extremely small. The sound cannot be produced, and the problem will not be recovered automatically until the buffer size is high enough.

The minimal audio buffer size for each system depends on the system environment (audio hardware, CPU and software).

Results

An useful conclusion from this prototype is that the infrastructure may be usable across platforms and Qt versions. Some exceptions are Qt versions between Qt 6.0 and Qt 6.3 (both inclusive) which are not suitable on Linux.

Tests built with Qt 5.15.2, Qt 6.2.4 and Qt 6.4.x

✔️ means that it is usable.

❌ means that it is not usable.

❓ means that the results are not conclusive.

Platform: Qt 5.x Qt 6.0 - 6.3 Qt 6.4
Linux ✔️ 1 ✔️
macOS ✔️ ✔️ ✔️
Windows ✔️ ✔️ ✔️
WebAssembly ✔️

You may try a WebAssembly demo

Footnotes

  1. Very high latency. Bug closed in 6.4 ( report ).