Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pygame.mixer.music.fadeout() for MIDI music causes all sounds to fade out (766) #561

Open
GalacticEmperor1 opened this issue Feb 12, 2023 · 0 comments
Labels
fluidsynth mixer.music pygame.mixer.music mixer pygame.mixer Windows

Comments

@GalacticEmperor1
Copy link
Collaborator

Issue №766 opened by dlon at 2019-01-25 13:26:13

An example to demonstrate this:

import pygame


pygame.init()
pygame.mixer.music.load('MIDI_sample.mid')
pygame.mixer.music.play(-1)

sound = pygame.mixer.Sound('test.wav')

surf = pygame.display.set_mode((20,20))


running = True

while running:
    for ev in pygame.event.get():
        if ev.type == pygame.QUIT:
            running = False
        elif ev.type == pygame.KEYDOWN:
            if ev.key == pygame.K_f:
                pygame.mixer.music.fadeout(1000)
            elif ev.key == pygame.K_s:
                sound.play()

    pygame.display.flip()

musictest.zip

'S' stops working after you press 'F'.

System:
Windows 10
Python 3.7.2
pygame 1.9.4+
SDL1+SDL2

Related Docs: https://www.pygame.org/docs/ref/music.html# pygame.mixer.music.fadeout


Comments

# # dlon commented at 2019-01-25 13:31:52

Looks like this may be a bug in SDL_mixer.


# # MyreMylar commented at 2020-04-30 15:16:50

After some research I believe I have determined that this is a generic, long standing volume bug with midi drivers used on Windows.

This is still present in 1.9.6 & 2.0.0.dev7 as described in the original report and can also be observed if you just set the volume very low:

import pygame


pygame.init()
pygame.mixer.music.load('data/MIDI_sample.mid')
pygame.mixer.music.play(-1)

sound = pygame.mixer.Sound('data/test.wav')

surf = pygame.display.set_mode((20,20))


running = True

while running:
    for ev in pygame.event.get():
        if ev.type == pygame.QUIT:
            running = False
        elif ev.type == pygame.KEYDOWN:
            if ev.key == pygame.K_f:
                #  Sound will not be audible after setting music volume low
                pygame.mixer.music.set_volume(0.01)
            elif ev.key == pygame.K_g:
                pygame.mixer.music.set_volume(1.0)
            elif ev.key == pygame.K_s:
                sound.play()

    pygame.display.flip()

See an old report about it here:
https://stackoverflow.com/questions/5864603/sdl-mixer-midi-volume-issues-on-windows-vista-7

It seems it is well known in the community of people maintaining old windows games.

It looks like there is one other person on the internet looking at the issue recently here:
WohlSoft/SDL-Mixer-X#7

While that issue is them trying to resolve the issue generically, I also notice this version of SDL Mixer has support for using MIDI drivers other than the platform default - like FluidSynth which we could perhaps then bundle with pygame and load on windows.

I also notice that there is a chance this fork will be merged into the main branch of SDL:
WohlSoft/SDL-Mixer-X#8

So, perhaps the best solution for now is just to record this as a known issue with MIDI playback on windows and wait to see if SDL Mixer is updated with changes from SDL-Mixer-X, pull those into pygame via the usual route and then see about changing the MIDI driver back-end for Windows.


# # illume commented at 2020-05-01 11:35:40

Nice detective work. I found these two issues on the SDL https://bugzilla.libsdl.org/


# # MyreMylar commented at 2021-11-28 11:44:15

Looked at this again and it looks like the alternative default windows MIDI code didn't make it into SDL_mixer.

If we want to fix this in pygame then the only solution solution I can see is to change the midi back end on windows. For fluidsynth that involves:

  1. building SDL-mixer with the fluidsynth backend, rather than the default, on windows.
  2. Supplying a default soundfont file with pygame and adding it to the pygame SDL code with the SDL_SOUNDFONTS environment variable.
  3. Expose the SDL_SOUNDFONTS variable so users can choose their own preferred soundfont.

Fluidsynth:
https://github.com/FluidSynth/fluidsynth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fluidsynth mixer.music pygame.mixer.music mixer pygame.mixer Windows
Projects
None yet
Development

No branches or pull requests

3 participants