Description
Issue №2979 opened by PavelJ at 2022-01-08 19:54:39
Environment:
- Operating system: Windows 10 Pro
- Python version : 3.7.2
- SDL version: SDL 2.0.18 and others
- PyGame version: 1.9.4, 1.9.6, 2.0.3, 2.1.2, probably others
Current behavior:
When mixer is initialized, MIDI file loaded and played, there is a delay between .play() call and music playing. Delay is about 300-700 milliseconds. This is a pretty known issue, for example discussed here: https://stackoverflow.com/questions/18273722/pygame-sound-delay/34324343# 34324343
Unfortunately I tried all possible combinations of calls and parameters (pygame.init, pygame.mixer.init, pygame.mixer.pre_init, pygame,mixer.quit, play, stop, pause, setting buffer to 1024, 64, 2) and the delay is still there.
Expected behavior:
There is no delay or very small so it cannot be detected by ear when playing MIDI file. There is no issue with .mp3 files or other, only MIDI files.
Steps to reproduce:
- Initialize mixer and pygame
- Load a MIDI file
- Play it using mixer
Test code
Following test code shows a noticable delay when playing MIDI files. Tested MIDI files had size around 700 bytes.
import pygame
from datetime import datetime
pygame.mixer.pre_init(44100, -16, 2, 64)
pygame.mixer.init()
pygame.init()
pygame.mixer.music.load("C:\\Vesele_vanocni_hody_kalimba.mid")
print(f"Before={datetime.now()}")
pygame.mixer.music.play()
print(f"After={datetime.now()}")
Comments
# # MyreMylar commented at 2022-01-08 20:13:15
I'm fairly sure this won't be fixed for as long as SDL uses the default windows MIDI synth (Microsoft GS Wavetable synthesizer) on windows.
The thing has been around for ever (1996) and has lots of issues, but I guess it also has a certain retro sound that would be lost (as Microsoft own the midi sounds) with changing to a different midi player.
I would like to experiment with SDL using the fluidsynth backend on windows to see if this helps, but haven't yet had the chance to give it a proper go.