Compiling SDL2 in MSYS2 with sound?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • smbhax
    Swordsman
    • Oct 2021
    • 340

    Compiling SDL2 in MSYS2 with sound?


    I can compile the SDL2 front end from the latest source in MSYS2 and run it in Windows, following the Angband manual's instructions



    but I get no sound (fighting monsters, etc). I have "Use sound" set to "yes" in the in-game options.

    This has been discussed for more Linux-like versions here http://angband.oook.cz/forum/showthr...ght=sdl2+sound and there was a code fix around that time https://github.com/angband/angband/c...e1e6332302e51a and an issue discussing it https://github.com/angband/angband/issues/4458 --but I'm not sure how to apply configuration stuff mentioned in those pages, for instance "./configure --enable-sdl2-mixer," to compiling in MSYS2.

    Is there something I should be doing when compiling in MSYS2 to get sound working?

    All I'm doing is the manual's

    make -f Makefile.msys2.sdl2

    I installed additional packages

    pacman -S mingw-w64-x86_64-SDL2_mixer
    pacman -S mingw-w64-x86_64-SDL
    pacman -S mingw-w64-x86_64-SDL_mixer

    and tried what I think(?) does a force rebuild

    make -Bf Makefile.msys2.sdl2

    but that didn't get sound working.

    (Update 10/18: Of those three packages, only SDL2_mixer is actually needed. And I could have done

    make clean -f Makefile.msys2.sdl2
    make -f Makefile.msys2.sdl2

    instead of using -B.)

    I've tried running from a shortcut with "-msdl2" after angband.exe, but that doesn't seem to do anything different--no sound, at any rate.

    I get a repeating warning when compiling

    gcc.exe: warning: C:/msys64/mingw64/lib/libSDL2.a: linker input file unused because linking not done
    CC [filename].c

    where [filename] is various source files. It doesn't seem to result in actual errors or stop the build from completing.
    Last edited by smbhax; October 18, 2022, 20:50.
    My Angband videos
  • smbhax
    Swordsman
    • Oct 2021
    • 340

    #2
    Oh. Finally worked out to open src\Makefile.msys2.sdl2 and it says at the top

    # If you want only video (but not sound), use it like this:
    # (from angband directory)
    #
    # cd src
    # make -f Makefile.msys2.sdl
    #
    # TODO: sound is not working for windows build
    #

    Well shoot. : P

    I've tried it in Cygwin but there I get a "no available video device" message when trying to run. Some sort of Cygwin video compatibility thing, maybe? Can't find anything by Googling really. Maybe I'll finally have to run the official Windows Linux thingy or something.

    (Update: got it running with sound in Ubuntu under Windows Subsystem for Linux--but it runs a little slow, and after alt-tabbing the movement keys won't work until I hit Alt again. The Alt key thing is mildly annoying, but the slightly laggy response--the movement is very slightly delayed, and the sound is further delayed--is a real drag. Guess I'll just suck it up and stick to the messy multi-Window Windows version, ah well. ; )

    (Also: compile instructions at top of Makefile.sdl2 might be out of date? Or that whole file might be out of date? When I try to follow them in WSL Ubuntu I get a warning about no front-ends configured from ./configure, and a cascade of "undefined reference" messages and error after doing "SOUND=yes make -f Makefile.sdl2":

    ~~~~
    LINK angband
    /usr/bin/ld: main.o: in function `printf':
    /usr/include/x86_64-linux-gnu/bits/stdio2.h:107: undefined reference to `help_spoil'
    [then more undefined references]
    ~~~~

    What worked instead under Ubuntu was--as described by others in that other forum thread I linked above--

    ~~~~
    ./autogen.sh
    ./configure --with-no-install --enable-sdl2 --enable-sdl2-mixer
    make
    ./src/angband -msdl2
    ~~~~

    )
    Last edited by smbhax; October 12, 2022, 05:52.
    My Angband videos

    Comment

    • backwardsEric
      Knight
      • Aug 2019
      • 527

      #3
      This modified version of Makefile.msys2.sdl2, https://github.com/backwardsEric/ang...ile.msys2.sdl2 https://github.com/angband/angband/b...ile.msys2.sdl2 (updated compilation instructions are at the top of the file or at https://angband.readthedocs.io/en/la...2-with-mingw64), compiles and links an executable with sound for SDL2 enabled (at least when used on the Windows runner on GitHub). I don't know if sound actually works when that executable is run on Windows.

      The excess warning messages from Makefile.msys2.sdl2 aren't specific to what you did: it'd have to be modified so the options added for SDL2 don't mix those that are only needed when compiling with those that are only needed for linking.

      Thanks for pointing out the out-of-date Makefile.sdl2. I'd favor removing it entirely since "./autogen.sh ; ./configure --enable-sdl2 --with-no-install ; make" should do the trick (one can add --disable-x11 and --disable-curses options to configure if those front ends aren't desired even if the necessary libraries and headers are available; --enable-sdl2 implies --enable-sdl2-mixer so it doesn't need to be explicitly included).
      Last edited by backwardsEric; October 22, 2022, 05:24. Reason: point to version that was incorporated into Angband

      Comment

      • smbhax
        Swordsman
        • Oct 2021
        • 340

        #4
        Originally posted by backwardsEric
        This modified version of Makefile.msys2.sdl2, https://github.com/backwardsEric/ang...ile.msys2.sdl2 , compiles and links an executable with sound for SDL2 enabled (at least when used on the Windows runner on GitHub). I don't know if sound actually works when that executable is run on Windows.
        Wow! Yes, it works. Sound works in Windows through the Angband SDL2 front end with my MSYS2-compiled version now! : D And not delayed like in the Cygwin and WSL Ubuntu versions! Amazing, fantastic, excelsior!!!

        : DDDDD

        You've done it again! Thank you, thank you, thank you!!!

        ~~~~

        Doesn't matter now, but re: my flailing with Cygwin and SDL2 above, I managed to get that working--although the input response and especially sound are slightly laggy, as in WSL Ubuntu--doesn't have the Alt key thing after Alt-tab like WSL Ubuntu, though.

        So for SDL2 and Cygwin:

        - Install the "xinit," "xorg-server," and "xlaunch" packages using Cygwin's install program

        - compile Angband with
        ./autogen.sh
        ./configure --with-no-install --enable-sdl2 --enable-sdl2-mixer
        make

        With those Cygwin/X packages installed, we'll be able to run this through the X interface--EXCEPT that mouse input doesn't seem to work on the SDL2 front end through the X interface--clicking the menus does nothing. So here's the crude workaround:

        - In a version in which you can run and configure the SDL2 front-end, such as one compiled in MSYS2, run the game and set up the SDL2 Angband Term subwindows there to your liking, then CTRL+X to quit

        - copy the window.prf and sdl2init.txt from that version into the .angband/Angband folder in your Cygwin home

        - run the XLaunch program installed by the xinit Cygwin package

        - In the XLaunch launcher window, choose "Fullscreen" and "Start a program" - "Local program - xterm"

        - when the xterm terminal appears in front of the XLaunch black screen, run Angband as if you're in the Cygwin terminal (I do "cd angband" and then "./src/angband")

        ^ That should launch your Cygwin-compiled Angband in the XLaunch screen, with the Angband SDL2 front-end, with the subwindows configured as you had them in the other version, and working sound (if you enable it with the usual Angband =ab "use_sound" option menu setting).

        As in WSL Ubuntu, in this Cygwin/X thing, input response may be every so slightly sluggish, and sound response will be definitely sluggish. At least, it is for me.

        That's why getting it all working through the MSYS2 version is so nice: that lovely single-window seamless interface, sound (thanks to backwardsEric's new config!), and no input or sound delay! : D
        Last edited by smbhax; October 12, 2022, 08:06.
        My Angband videos

        Comment

        • smbhax
          Swordsman
          • Oct 2021
          • 340

          #5
          Come to think of it, the old instructions at the top of Makefile.msys2.sdl2 say

          ~~~~
          # cd src
          # make -f Makefile.msys2.sdl
          #
          # TODO: sound is not working for windows build
          ~~~~

          but that should be "sdl2," not "sdl," I guess.
          Last edited by smbhax; October 12, 2022, 10:07.
          My Angband videos

          Comment

          • smbhax
            Swordsman
            • Oct 2021
            • 340

            #6
            Originally posted by backwardsEric
            Thanks for pointing out the out-of-date Makefile.sdl2. I'd favor removing it entirely since "./autogen.sh ; ./configure --enable-sdl2 --with-no-install ; make" should do the trick (one can add --disable-x11 and --disable-curses options to configure if those front ends aren't desired even if the necessary libraries and headers are available; --enable-sdl2 implies --enable-sdl2-mixer so it doesn't need to be explicitly included).
            Yeah from that other forum thread it doesn't sound like people here, at least, were using Makefile.sdl2. It isn't mentioned in the manual's compiling instructions.
            My Angband videos

            Comment

            • smbhax
              Swordsman
              • Oct 2021
              • 340

              #7


              ^ In case anyone's unfamiliar with the silky smooth look of the SDL2 front end. : ) (Click it for full size.)

              That's with "Border" toggled off on each window. I've mostly duplicated the standard Windows version's default window layout there, except that with the "Size" and "Move" toggles in the upper right corner it's really easy to line the windows up seamlessly in SDL2.

              If you're using tiles and you're used to how they work in the standard Windows version's front end, one thing to keep in mind is that the tile scaling works a little differently in the SDL2 front end: whereas in the standard Windows front end, with the square Shockbolt tiles for instance you'd set tile scaling to 4x2, in SDL2 you'd set it to 4x4; and the size of the font you use for the main ("A/"Angband") window in SDL2 affects the tile scaling! In particular, a square font makes it a lot easier to get predictable scaling out of square tiles like Shockbolt's.

              After a little trial and error, I found that on my screen these settings for the SDL2 front-end duplicated the scale of the tiles in the standard Windows version's front end:

              "A"/"Angband" window:
              - Font - Name - 16x16x.fon
              - Tiles - Set - Shockbolt Dark
              - Tiles - Size - Tile Width 4
              - Tiles - Size - Tile Height 4

              Other windows:
              - Font - Name - 8x12x.fon

              As I mentioned, I un-selected "Borders" for all the subwindows. And I left "Fullscreen" selected in the main menu.

              If you've scrambled your subwindow settings perhaps by copying files over from a different installation, and find your subwindows keep changing their "Purpose" setting back to something else each time you load your character, well there's probably some better way to straighten that out or better yet never do whatever I did in messing around with files to get it like that in the first place--but you can straighten the "Purpose" of the windows out in the game's =w "Subwindow setup" menu, then save that to user.prf with the game's =f "Save subwindow setup to pref file" command, and they'll automatically load up the right way when you restart.

              Unlike the standard Windows version which by default prompts you to load a file when you start up, when you start the SDL2 front end it will automatically load your last character file name or something--anyway one way to set it to load a specific character file name is to put it in the "Target" command of a shortcut to angband.exe: make a Windows shortcut for angband.exe, right-click it, select Properties, and in the "Target" field of the "Details" tab, add "-u[save file name from lib\user\save]" at the end; my normal shortcut's "Target" field for instance is

              C:\msys64\home\smbhax\angband\angband.exe -uSmbhax

              Compiling with the sound-enabled version of the MSYS2 SDL2 Makefile @backwardsEric linked above requires an additional package:

              pacman -S mingw-w64-x86_64-SDL2_mixer

              The MSYS2-compiled SDL2 front end with sound can be seen and heard in action here: https://www.youtube.com/watch?v=HoSvVNSILf4&t=2855s

              There are currently a couple visual glitches: game screen blanked after Windows lock screen (toggling fonts will clear it up) (5497), and accented letters are displayed incorrectly (5498; Update 10/18: backwardsEric has fixes for this one, linked in that issue).
              Last edited by smbhax; October 18, 2022, 20:54.
              My Angband videos

              Comment

              • smbhax
                Swordsman
                • Oct 2021
                • 340

                #8
                Originally posted by backwardsEric
                This modified version of Makefile.msys2.sdl2, https://github.com/backwardsEric/ang...ile.msys2.sdl2 https://github.com/angband/angband/b...ile.msys2.sdl2 (updated compilation instructions are at the top of the file or at https://angband.readthedocs.io/en/la...2-with-mingw64), compiles and links an executable with sound for SDL2 enabled (at least when used on the Windows runner on GitHub). I don't know if sound actually works when that executable is run on Windows.
                I just synced up to the new check ins in the Angband git repository and building with sound is broken now.

                - compilation instructions at top of Makefile.msys2.sdl2 have NOT been updated (also, it says "# File: Makefile.sdl2" at the top)

                - When I try compiling without SOUND=yes, it does compile and run, but there's a new compile warning:

                Code:
                smbhax@DESKTOP-64GQN1N MINGW64 ~/angband/src
                $ make -f Makefile.msys2.sdl2
                        CC main.c
                <command-line>: warning: no previous prototype for 'SDL_main' [-Wmissing-prototypes]
                main.c:317:5: note: in expansion of macro 'main'
                  317 | int main(int argc, char *argv[])
                      |     ^~~~
                - When I compile with SOUND=yes, there are errors:

                Code:
                smbhax@DESKTOP-64GQN1N MINGW64 ~/angband/src
                $ make -f Makefile.msys2.sdl2 SOUND=yes
                        CC snd-sdl.c
                snd-sdl.c:42:17: error: unknown type name 'Mix_Chunk'
                   42 |                 Mix_Chunk *chunk;       /* Sample in WAVE format */
                      |                 ^~~~~~~~~
                snd-sdl.c:43:17: error: unknown type name 'Mix_Music'
                   43 |                 Mix_Music *music;       /* Sample in MP3 format */
                      |                 ^~~~~~~~~
                snd-sdl.c: In function 'open_audio_sdl':
                snd-sdl.c:67:9: error: unknown type name 'Uint16'; did you mean 'uint16_t'?
                   67 |         Uint16 audio_format = AUDIO_S16;
                      |         ^~~~~~
                      |         uint16_t
                snd-sdl.c:67:31: error: 'AUDIO_S16' undeclared (first use in this function)
                   67 |         Uint16 audio_format = AUDIO_S16;
                      |                               ^~~~~~~~~
                snd-sdl.c:67:31: note: each undeclared identifier is reported only once for each function it appears in
                snd-sdl.c:71:13: warning: implicit declaration of function 'SDL_Init' [-Wimplicit-function-declaration]
                   71 |         if (SDL_Init(SDL_INIT_AUDIO) < 0) {
                      |             ^~~~~~~~
                snd-sdl.c:71:13: warning: nested extern declaration of 'SDL_Init' [-Wnested-externs]
                snd-sdl.c:71:22: error: 'SDL_INIT_AUDIO' undeclared (first use in this function)
                   71 |         if (SDL_Init(SDL_INIT_AUDIO) < 0) {
                      |                      ^~~~~~~~~~~~~~
                snd-sdl.c:72:62: warning: implicit declaration of function 'SDL_GetError' [-Wimplicit-function-declaration]
                   72 |                 plog_fmt("SDL: Couldn't initialize SDL: %s", SDL_GetError());
                      |                                                              ^~~~~~~~~~~~
                snd-sdl.c:72:62: warning: nested extern declaration of 'SDL_GetError' [-Wnested-externs]
                snd-sdl.c:77:13: warning: implicit declaration of function 'Mix_OpenAudio' [-Wimplicit-function-declaration]
                   77 |         if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, 4096) < 0) {
                      |             ^~~~~~~~~~~~~
                snd-sdl.c:77:13: warning: nested extern declaration of 'Mix_OpenAudio' [-Wnested-externs]
                snd-sdl.c:79:17: warning: implicit declaration of function 'SDL_QuitSubSystem' [-Wimplicit-function-declaration]
                   79 |                 SDL_QuitSubSystem(SDL_INIT_AUDIO);
                      |                 ^~~~~~~~~~~~~~~~~
                snd-sdl.c:79:17: warning: nested extern declaration of 'SDL_QuitSubSystem' [-Wnested-externs]
                snd-sdl.c: In function 'load_sample_sdl':
                snd-sdl.c:94:53: warning: implicit declaration of function 'Mix_LoadWAV' [-Wimplicit-function-declaration]
                   94 |                         sample->sample_data.chunk = Mix_LoadWAV(filename);
                      |                                                     ^~~~~~~~~~~
                snd-sdl.c:94:53: warning: nested extern declaration of 'Mix_LoadWAV' [-Wnested-externs]
                snd-sdl.c:94:51: warning: assignment to 'int *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
                   94 |                         sample->sample_data.chunk = Mix_LoadWAV(filename);
                      |                                                   ^
                snd-sdl.c:102:53: warning: implicit declaration of function 'Mix_LoadMUS' [-Wimplicit-function-declaration]
                  102 |                         sample->sample_data.music = Mix_LoadMUS(filename);
                      |                                                     ^~~~~~~~~~~
                snd-sdl.c:102:53: warning: nested extern declaration of 'Mix_LoadMUS' [-Wnested-externs]
                snd-sdl.c:102:51: warning: assignment to 'int *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
                  102 |                         sample->sample_data.music = Mix_LoadMUS(filename);
                      |                                                   ^
                snd-sdl.c: In function 'play_sound_sdl':
                snd-sdl.c:153:54: warning: implicit declaration of function 'Mix_PlayChannel' [-Wimplicit-function-declaration]
                  153 |                                         return (0 == Mix_PlayChannel(-1, sample->sample_data.chunk, 0));
                      |                                                      ^~~~~~~~~~~~~~~
                snd-sdl.c:153:54: warning: nested extern declaration of 'Mix_PlayChannel' [-Wnested-externs]
                snd-sdl.c:158:54: warning: implicit declaration of function 'Mix_PlayMusic' [-Wimplicit-function-declaration]
                  158 |                                         return (0 == Mix_PlayMusic(sample->sample_data.music, 1));
                      |                                                      ^~~~~~~~~~~~~
                snd-sdl.c:158:54: warning: nested extern declaration of 'Mix_PlayMusic' [-Wnested-externs]
                snd-sdl.c: In function 'unload_sound_sdl':
                snd-sdl.c:180:42: warning: implicit declaration of function 'Mix_FreeChunk' [-Wimplicit-function-declaration]
                  180 |                                          Mix_FreeChunk(sample->sample_data.chunk);
                      |                                          ^~~~~~~~~~~~~
                snd-sdl.c:180:42: warning: nested extern declaration of 'Mix_FreeChunk' [-Wnested-externs]
                snd-sdl.c:186:41: warning: implicit declaration of function 'Mix_FreeMusic' [-Wimplicit-function-declaration]
                  186 |                                         Mix_FreeMusic(sample->sample_data.music);
                      |                                         ^~~~~~~~~~~~~
                snd-sdl.c:186:41: warning: nested extern declaration of 'Mix_FreeMusic' [-Wnested-externs]
                snd-sdl.c: In function 'close_audio_sdl':
                snd-sdl.c:213:9: warning: implicit declaration of function 'Mix_CloseAudio' [-Wimplicit-function-declaration]
                  213 |         Mix_CloseAudio();
                      |         ^~~~~~~~~~~~~~
                snd-sdl.c:213:9: warning: nested extern declaration of 'Mix_CloseAudio' [-Wnested-externs]
                snd-sdl.c:214:27: error: 'SDL_INIT_AUDIO' undeclared (first use in this function)
                  214 |         SDL_QuitSubSystem(SDL_INIT_AUDIO);
                      |                           ^~~~~~~~~~~~~~
                make: *** [Makefile.msys2.sdl2:142: snd-sdl.o] Error 1
                (I tried installing SDL in MSYS2

                $ pacman -S mingw-w64-x86_64-SDL
                $ pacman -S mingw-w64-x86_64-SDL_gfx
                $ pacman -S mingw-w64-x86_64-SDL_image
                $ pacman -S mingw-w64-x86_64-SDL_mixer
                $ pacman -S mingw-w64-x86_64-SDL_net
                $ pacman -S mingw-w64-x86_64-SDL_ttf

                but it didn't fix it; I removed those again.)
                My Angband videos

                Comment

                • backwardsEric
                  Knight
                  • Aug 2019
                  • 527

                  #9
                  The recently updated Makefile.msys2.sdl2 in Angband's main branch works when run on GitHub's Windows runner and building with sound enabled (output is here, https://github.com/angband/angband/a...obs/5448261777 ; it does have the warning about no prototype for SDL_main()). From your description of the contents of Makefile.msys2.sdl2, it sounds like the version in the main branch isn't what you got (compare with https://github.com/angband/angband/b...ile.msys2.sdl2 ).

                  Comment

                  • smbhax
                    Swordsman
                    • Oct 2021
                    • 340

                    #10
                    Yikes. Did I manage to get just a partial git pull or something. Weird because I was doing "git status" checks all evening and they didn't show anything out of the ordinary. Another git pull and yeah now I can compile and play with sound, although still with that new sdl compile warning.

                    Sorry for the weirdness, MANY thanks for the patient help with my endless silliness. D-argh.
                    Last edited by smbhax; October 23, 2022, 07:07.
                    My Angband videos

                    Comment

                    • backwardsEric
                      Knight
                      • Aug 2019
                      • 527

                      #11
                      There's a modified version of src/main.c at https://github.com/backwardsEric/ang...ing/src/main.c which avoids the compiler warning about the missing prototype for SDL_main(). I'd be interested to know that the resulting executable from compiling it under MSYS2 starts up as expected on Windows. If it does, it might also be worth checking if there's any impact on https://github.com/angband/angband/issues/5497 (MSYS2 compiled SDL2 front end blanks out after a Windows lock screen) and https://github.com/angband/angband/issues/5512 (MSYS2 compiled SDL2 front end doesn't deal well with display switches).

                      Comment

                      • smbhax
                        Swordsman
                        • Oct 2021
                        • 340

                        #12
                        It fixes the "missing prototype for SDL_main()" warning. : ) It doesn't fix the screen blanking stuff for MSYS2 or Cygwin/X (Cygwin/X being affected only by 5512), though.
                        My Angband videos

                        Comment

                        • smbhax
                          Swordsman
                          • Oct 2021
                          • 340

                          #13
                          Compiling with

                          $ make -f Makefile.msys2.sdl2 SOUND=yes

                          results in a 22.1 MB angband.exe, whereas the downloadable 4.2.4 Windows front end .exe is only 1.97 MB. Compiling with

                          make -f Makefile.msys2

                          gets me a I think it was 1.68 MB GCU-only .exe. But is there a way to get a slimmer SDL2 .exe? Is the additional file size due to necessary SDL2 stuff?

                          (I tried lumping on parameters that cut a 200 MB+ Hengband .exe down to 4 MB, ie

                          $ make -f Makefile.msys2.sdl2 SOUND=yes CXXFLAGS="-g0 -O2"

                          after a make "clean," but the .exe size remained 22.1 MB.)
                          Last edited by smbhax; November 18, 2022, 05:29.
                          My Angband videos

                          Comment

                          • backwardsEric
                            Knight
                            • Aug 2019
                            • 527

                            #14
                            Makefile.msys2.sdl2 is compiling with debugging symbols so that'll be part of the 22 megabytes. To avoid that, it's probably easiest to edit Makefile.msys2.sdl2 and remove "-g" from CFLAGS (it's at line 101 in the current version). For the normal Windows builds, removing the debugging symbols saved ~5 megabytes in the size of the executable.

                            With Makefile.msys2.sdl2, the SDL2 libraries are linked statically, which also bloats the executable size. I tried once to link those dynamically in the hopes that would simplify what libraries have to be specified in Makefile.msys2.sdl2 but had no success. So I don't have any easy pathway for you to avoid that part of the large executable size.

                            Comment

                            • smbhax
                              Swordsman
                              • Oct 2021
                              • 340

                              #15
                              Ah! Yeah setting -g0 there got the .exe down to 15.7 MB. Better than 22.1. : )

                              Removing the -static line (104) got the .exe down to 4 MB or so but then it just started complaining about missing dlls, four at a time, starting mostly with the SDL2 ones. ; )
                              My Angband videos

                              Comment

                              Working...
                              😀
                              😂
                              🥰
                              😘
                              🤢
                              😎
                              😞
                              😡
                              👍
                              👎