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 does not correctly load wave files with BWF headers (459) #427

Closed
GalacticEmperor1 opened this issue Feb 12, 2023 · 0 comments
Labels
bug Not working as intended mixer pygame.mixer

Comments

@GalacticEmperor1
Copy link
Collaborator

Issue №459 opened by Rybec at 2018-06-08 19:48:25

wav files produced by Pro Tools and some other audio editing tools do not load or play properly with the Pygame mixer and music modules. My students have come across this issue twice now, so I did some research to determine why this issue exists. This is what I found:

SO Post

Evidently, Pro Tools and some other programs save wav files with additional headers specified by the Broadcast Wave Format, an extension to the MS RIFF Wave format. Officially, this extension is supposed to be backward compatible with the original format, but looking through the specs, it seems like it is easy to make assumptions about the format that would cause problems with the extension. I appears that Pygame does this. As a work around, it is possible to load and save wav files produced with Pro Tools in Audacity, which will save the files without the BWF extensions. Doing this, however, may lose important metadata that the BFW extension was designed to track (BWF allows the storage of metadata including author, possibly copyright information, and other things that are often critical in commercial use of media).

I have tried to figure out the precise differences to figure out how to fix this issue, however I find certain parts of the documentation confusing (not to mention, I was not able to find decent documentation on BFW until around 10 minutes ago). Here is a link to the BWF specification, which includes the MS RIFF Wave specification in its appendix:

BWF Specs

I will try to look at this again when I have more time, but if someone already familiar with the pygame.mixer code could find some time, it might take them far less time than it would take me.


Comments

# # Rybec commented at 2018-06-08 19:52:17

I should add: Another work around mentioned is loading the file with the soundfile module, which loads audio into a Numpy array, and then using Pygame's sndarray module to convert the Numpy array into a Pygame Sound object. The SO post has a comment saying this works.

I mention this, because maybe the code of that module could be examined to determine how it handles BFW headers.


# # Rybec commented at 2018-06-08 20:09:30

Is this probably an upstream issue? On a hunch I looked into SDL's support for BWF, and I found an unmerged pull request. Perhaps that is where the issue is, not here...


# # Rybec commented at 2018-06-08 20:12:57

According to this bug report, this issue is fixed in SDL, in 2014. Is Pygame using an older version of SDL than that?


# # Rybec commented at 2018-06-08 20:21:50

And the answer is: Yes. Pygame currently seems to be using SDL 1.2.15, which was released in August of 2013, almost a year before SDL got BWF support.

Is this likely to be changed? If not, I guess this can be closed as a not-going-to-fix.


# # illume commented at 2018-07-29 23:35:35

@Rybec thanks for tracking this down.

I made some patches for homebrew mac. I'm looking for volunteers to apply to our manylinux builds. Also, we need to rebuild the windows dependencies with these patches. If someone does this stuff, we could do another pygame 1.9.x bugfix release. I also attached a patch to the sdl bug tracker, so it will be easier for distros(linux, homebrew etc) to also apply the patches.

There is an SDL2 branch of pygame, and this will link against sdl2 which already has a fix for this. But this could be a long time away.


# # himijendrix24 commented at 2019-05-28 05:20:32

I also can't use pygame mixer on raspbian and python3.
Around a year ago it worked without problems, so I'm really wondering what has changed?

Installation:
sudo apt-get install python3-pygame libsdl-sound1.2 libsdl-mixer1.2
(installing via pip3 didn't improve anything)

The script crashes when calling:

pygame.mixer.music.load("test.wav")
*** Error in `python3': double free or corruption (!prev): 0x01ebb620 ***

I already tried different *.wav formats and pygame.mixer.pre_init / pygame.mixer.init initialisations.

Is there anything I can do besides waiting for pygame2?


# # illume commented at 2019-05-28 05:32:24

@himijendrix24 you can compile SDL from source with the patch, or compile pygame from source using SDL2.

sudo apt-get update
sudo apt install git python3-dev python3-setuptools python3-numpy python3-opengl \
    libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev libfreetype6-dev \
    musescore-soundfont-gm libjpeg-dev libpng-dev \
    libportmidi-dev libswscale-dev libavformat-dev libavcodec-dev \
    libtiff5-dev fluid-soundfont-gm fluid-soundfont-gs fluidsynth \
    fontconfig fonts-freefont-ttf \
    libfreetype6-dev libmpg123-0 libmpg123-dev
git clone https://github.com/pygame/pygame.git
cd pygame
python3 setup.py -config -auto -sdl2
python3 setup.py install --user

In the future, I hope we can get some precompiled wheels for pygame on raspberrypi. https://github.com/bennuttall/piwheels/issues/138

@GalacticEmperor1 GalacticEmperor1 added bug Not working as intended help wanted mixer pygame.mixer labels Feb 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Not working as intended mixer pygame.mixer
Projects
None yet
Development

No branches or pull requests

1 participant