Page 1 of 1

[SOLVED] bug?: SDL2 doesn't play music

Posted: Fri Apr 22, 2016 2:18 am
by filbo
This has been true for months. I'm playing EMC levels (currently "/usr/share/games/rocksndiamonds/levels/Emerald Mine Club/emc_cosmos_mine_10/22"). These have a startup music (which I don't actually like very much), sounds sort of like "bam bam BAMP bam bam BAMP ...".

SDL1 binaries play that music at startup, until I hit <ESC> to shut them up and get to the main menu.

SDL2 binaries don't.

According to Settings -> Sound & music, I have all three types of sound (normal, looping & music) enabled, with respective volume levels of 2%, 2% and 100%.

Ah -- think I've observed this before -- if I capture stderr of both binaries, the SDL2 output includes these two extra lines:

Code: Select all

rocksndiamonds: warning: cannot read music file '/usr/share/games/rocksndiamonds/levels/Emerald Mine Club/mus_classic_em/music/./em_title.mp3': Unrecognized music format
rocksndiamonds: warning: cannot load artwork file 'em_title.mp3'
I would sort of expect that just about anything purporting to play music would recognize MP3 format. What the heck?

Well, perhaps this:

Code: Select all

$ strings -fa /usr/lib/x86_64-linux-gnu/libSDL*mixer*.so.0 | grep -i mp3
/usr/lib/x86_64-linux-gnu/libSDL_mixer-1.2.so.0: Mixer not built with MP3 support
/usr/lib/x86_64-linux-gnu/libSDL2_mixer-2.0.so.0: Mixer not built with MP3 support
... which leads to a different "What the heck?" -- how come -SDL1 can play MP3?!?

Re: bug?: SDL2 doesn't play music

Posted: Fri Apr 22, 2016 6:07 pm
by Holger
These have a startup music (which I don't actually like very much), sounds sort of like "bam bam BAMP bam bam BAMP ...".
You probably have to have played Emerald Mine in 1987 to like that music... ;-)
I would sort of expect that just about anything purporting to play music would recognize MP3 format. What the heck?
Building SDL_mixer with external SMPEG library support (for MP3 support) has always been a bit tricky in the past. (Even *finding* a version of SMPEG that does not refuse to compile with SDL_mixer was part of the challenge sometimes.)

Recent versions of SDL2_mixer now include SMPEG directly in the (external libraries) source tree and compile just fine, so MP3 support in SDL2 is now easier than before.
/usr/lib/x86_64-linux-gnu/libSDL2_mixer-2.0.so.0: Mixer not built with MP3 support
OK, that perfectly explains why R'n'D, when compiled against SDL2, does not play MP3s...
... which leads to a different "What the heck?" -- how come -SDL1 can play MP3?!?
Does R'n'D, when compiled against SDL1, really use this library? Not sure how your SDL1 installation behaves, but at least SDL2 dlopen()'s SDL2_mixer, so you may have to strace R'n'D to see what libSDL_mixer.so file it really uses.

Re: bug?: SDL2 doesn't play music

Posted: Fri Apr 22, 2016 10:03 pm
by filbo

Code: Select all

$ ldd rocksndiamonds-SDL? | grep -i sdl
rocksndiamonds-SDL1:
	libSDL_image-1.2.so.0 => /usr/lib/x86_64-linux-gnu/libSDL_image-1.2.so.0 (0x00007f52714b9000)
	libSDL_mixer-1.2.so.0 => /usr/lib/x86_64-linux-gnu/libSDL_mixer-1.2.so.0 (0x00007f5271256000)
	libSDL_net-1.2.so.0 => /usr/lib/x86_64-linux-gnu/libSDL_net-1.2.so.0 (0x00007f5271052000)
	libSDL-1.2.so.0 => /usr/lib/x86_64-linux-gnu/libSDL-1.2.so.0 (0x00007f5270db8000)
rocksndiamonds-SDL2:
	libSDL2_image-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libSDL2_image-2.0.so.0 (0x00007fac0cd14000)
	libSDL2_mixer-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libSDL2_mixer-2.0.so.0 (0x00007fac0cac5000)
	libSDL2_net-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libSDL2_net-2.0.so.0 (0x00007fac0c8c0000)
	libSDL2-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0 (0x00007fac0c5c2000)
Running each under `strace`, I see that they of course open each of those shared objects; and no other *SDL* libraries.

In total they open 38 same libraries; 4-each SDL libraries (which are obviously different); and then SDL1 opens 5 unique libraries while SDL2 opens 26. Of those, I believe the following are audio-related:

Code: Select all

SDL1:

   /usr/lib/x86_64-linux-gnu/libmad.so.0
   /usr/lib/x86_64-linux-gnu/libmikmod.so.2

SDL2:

   /usr/lib/libmodplug.so.1
   /usr/lib/x86_64-linux-gnu/libfluidsynth.so.1
   /usr/lib/x86_64-linux-gnu/libjack.so.0
I know nothing about how or why, or which of those libraries are delivering the music (under SDL1) / losing it (under SDL2).

In-game sound effects work in both builds. Only music files fail (perhaps only MP3; nothing else explicitly tested).

Re: bug?: SDL2 doesn't play music

Posted: Sat Dec 10, 2016 8:24 pm
by Holger
As the root cause (SDL2 version of self-compiled new R'n'D 4 branch does not play MP3s) was found, but is beyond the scope of R'n'D development itself, I'll mark this thread as "closed" now.

The final version 4.0.0.0 (just as the already available release candidates) will be packaged with all required SDL2 libraries (including SMPEG for MP3 support), so this will hopefully be no issue anymore with the final release.

If you should encounter similar problems with the last release candidate (currently RC3), please let me know, so this thread can be re-opened.

Re: [SOLVED] bug?: SDL2 doesn't play music

Posted: Mon Dec 12, 2016 12:29 am
by filbo
I need to read back up this to refamiliarize myself with the problem...

Sounds like in part it was because the SDL2 libs I'm using are compiled without some bit of functionality? Or maybe adapt at runtime depending on whether libsmpeg.so is available, and I was missing it?

You're saying that when you build the binaries, you will package with SDL2 and smpeg .so files. But this is not suitable for distros like Debian / Ubuntu where they're going to build their own. I should investigate and make sure that binaries built out of their build env will end up with the right set of everything. And then bugreport to them "update your RnD" -- when 4.0 final is final.

Re: [SOLVED] bug?: SDL2 doesn't play music

Posted: Mon Dec 12, 2016 2:30 pm
by Holger
Sounds like in part it was because the SDL2 libs I'm using are compiled without some bit of functionality?
Yes, from your strace output, it seems they were simply compiled without SMPEG support.
Or maybe adapt at runtime depending on whether libsmpeg.so is available, and I was missing it?
Hard to tell... indeed SDL2_mixer may open libsmpeg2.so as a shared object at runtime, if it exists and if MP3 files have to be played. Do you have such a file at the same location as "libSDL2_mixer.so"? But it may also be possible that smpeg2 was compiled into SDL2_mixer directly -- it's included as an external library in a sub-directory of the SDL2_mixer source.

At least for the Android version of SDL2_mixer, smpeg2 compiles as a separate shared library that is loaded at runtime. On the Mac, it seems to be compiled directly into SDL2_mixer.dylib.

That reminds me that I have a similar problem with the last SDL2 versions with Android: I can play WAVs and MODs, but no MP3s, even though the debug log tells me that "smpeg.so" was loaded. So I continue using an older version of SDL2_mixer/smpeg2 for the Android version for now...
You're saying that when you build the binaries, you will package with SDL2 and smpeg .so files.
Yep, right. Therefore the packages are self-contained and contain everything they need to run on any Linux system that is not older than around five or six years. (Excluding things like X11 and C libraries, of course... I didn't want to be THAT self-contained... ;-) )
But this is not suitable for distros like Debian / Ubuntu where they're going to build their own.
It doesn't matter, as the libraries included in the R'n'D package do not collide with potentially already installed system wide SDL/SDL2 libraries.

In the past, I never had a Linux system with 100% working SDL/SDL2 libraries with all required/dependent sub-libraries from the distributions repositories. (I've used various SLS, Slackware, SuSE, Debian, Ubuntu and Kubuntu Linux distributions in the past 20 years, and so far I always ended up compiling my own set of SDL, SDL_image, SDL_mixer, SDL_net, mikmod/modplug and smpeg libraries, as the distribution's variants were either non-existing, incomplete or outdated.)

Nevertheless, any distribution's package maintainers are free to bundle R'n'D with all required libraries as they like, so in an ideal world my download package would only ever be a last-resort fallback solution for esoteric distributions, as everybody's using the pre-packaged version installed from the Ubuntu Software Center application (or how it is called). :-)

(At least for Ubuntu and R'n'D 3.3.0.1, this already seems to work fine... But this version is over 6 years old, and the last stable release is over 3 years old.)
I should investigate and make sure that binaries built out of their build env will end up with the right set of everything. And then bugreport to them "update your RnD" -- when 4.0 final is final.
Yes. :-)

Re: [SOLVED] bug?: SDL2 doesn't play music

Posted: Tue Dec 13, 2016 12:39 am
by filbo
Right, so, ignore other request for reminder :)

I guess I'm probably going to have to build my own SDL2 libs, if I ever get around to it. Lack of music isn't a big deal really, just bothers my OCD...

Re: [SOLVED] bug?: SDL2 doesn't play music

Posted: Tue Dec 13, 2016 7:35 am
by Holger
I guess I'm probably going to have to build my own SDL2 libs, if I ever get around to it.
Using the current SDL2 libraries from Mercurial, it should be straight-forward, as follows:

Check out the code from Mercurial:

Code: Select all

#!/bin/bash

sudo apt-get install mercurial

hg clone http://hg.libsdl.org/SDL
hg clone http://hg.libsdl.org/SDL_image
hg clone http://hg.libsdl.org/SDL_mixer
hg clone http://hg.libsdl.org/SDL_net
Compile it:

Code: Select all

#!/bin/bash

# exec > BUILD_SDL2.log 2>&1

LIBDIRS="SDL
         SDL_image
         SDL_mixer/external/libmodplug-*
         SDL_mixer/external/smpeg2-*
         SDL_mixer
         SDL_net"

SEP1="=========="
SEP2="----------"
SEP1LINE="$SEP1$SEP1$SEP1$SEP1$SEP1$SEP1$SEP1$SEP1"
SEP2LINE="$SEP2$SEP2$SEP2$SEP2$SEP2$SEP2$SEP2$SEP2"

echo "$SEP1LINE"
echo "building SDL2 libraries"
echo "$SEP1LINE"
echo ""

cd SDL2

for i in $LIBDIRS; do

    echo "$SEP2LINE"
    echo "building library '$i'"
    echo "$SEP2LINE"
    echo ""

    cd "$i"

    if [ -x "autogen.sh" ]; then
        ./autogen.sh || exit
    fi

    ./configure         || exit
    make                || exit
    sudo make install   || exit

    cd -

    echo ""
done

echo "Done."
Just make sure to have the usual packages installed that are required for compiling C source code (which you most probably already have installed).

Re: [SOLVED] bug?: SDL2 doesn't play music

Posted: Fri Dec 16, 2016 10:19 pm
by filbo
Heh. SDL autogen.sh doesn't run if /bin/sh isn't bash (requires built-in 'pushd').

Build fails variously... poking at it...

Re: [SOLVED] bug?: SDL2 doesn't play music

Posted: Fri Dec 16, 2016 10:29 pm
by filbo
Ugh. All snarled up in ancient versions of libtool, automake etc.

Re: [SOLVED] bug?: SDL2 doesn't play music

Posted: Sun Dec 18, 2016 11:49 am
by Holger
Which system are you using?

I've used these scripts on Kubuntu 12.04, but would have expected that they also work on other not-too-old Linux distributions...

Re: [SOLVED] bug?: SDL2 doesn't play music

Posted: Mon Dec 19, 2016 1:08 pm
by filbo
It's Ubuntu 12.04, as close as possible!

All subdirs build except SDL_mixer/external/libmodplug-0.8.8.4, which builds but fails to install.

...

Ok, got it to work by a bunch of hacking.

Built with its own internal libsmpeg, I was able to get all the way to built & running RnD, which didn't complain about MP3 music, but emitted no actual audible music even with volume cranked all the way up.

I eventually rebuilt SDL_mixer with:

$ ./configure --enable-music-mp3-mad-gpl --disable-music-mp3-smpeg

and RnD it plays music!

But... in-game sounds sound weird. Higher pitched and with sharper cutoff than the SDL1 binary. This is new since building with my own built SDL2 mixer vs. the PPA one I've been using for years. -- in fact, if I run the same binary with LD_LIBRARY_PATH forcing it to either the PPA or my build, it sounds different. And my build crashes with a libc backtrace when I exit. So I'm just going to abandon it, I think...