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

3.6.0: Problems with MIDI audio (SDL_Sound / Timidity issue) #1941

Open
i30817 opened this issue Mar 7, 2023 · 59 comments
Open

3.6.0: Problems with MIDI audio (SDL_Sound / Timidity issue) #1941

i30817 opened this issue Mar 7, 2023 · 59 comments
Labels
context: audio system: linux type: bug unexpected/erroneous behavior in the existing functionality

Comments

@i30817
Copy link

i30817 commented Mar 7, 2023

Describe the bug
I placed this timidity.cfg on a game that uses midi (trilby notes special edition) - .txt extension doesn't count, it's just for github to deign to allow it:
timidity.cfg.txt

The file points to 'source /etc/timidity/fluidr3_gm.cfg'
which does exist:

$ head /etc/timidity/fluidr3_gm.cfg 
dir /usr/share/sounds/sf2

bank 0
0 %font "FluidR3_GM.sf2" 0 0 amp=29 pan=0
1 %font "FluidR3_GM.sf2" 0 1 amp=41 pan=0
2 %font "FluidR3_GM.sf2" 0 2 amp=64 pan=0
3 %font "FluidR3_GM.sf2" 0 3 amp=32 pan=0
4 %font "FluidR3_GM.sf2" 0 4 amp=35 pan=0
5 %font "FluidR3_GM.sf2" 0 5 amp=51 pan=0
6 %font "FluidR3_GM.sf2" 0 6 amp=71 pan=0

and so does the soundfount itself:

$ ls /usr/share/sounds/sf2/
default-GM.sf2@  FluidR3_GM.sf2  TimGM6mb.sf2

Therefore the game starting should have music in the main menu (it has on the current scummvm version of ags, although that one is still using allegro iirc, so it might not using timidity through sdl).

But it doesn't. Using the cmd line variable TIMIDITY_CFG doesn't have a effect either.

The output of ags is:

Adventure Game Studio v3.6 Interpreter
Copyright (c) 1999-2011 Chris Jones and 2011-2023 others
ACI version 3.6.0.44

Initializing backend libs
SDL Version: 2.0.20
Initializing game data
Located game data pak: /media/i3/Mordred/Games/Adventure Game Studio/Trilby 3 - Trilby's Notes Special Edition/notes se.exe
Opened game data file: ac2game.dta
Game data version: 27
Compiled with: 2.62
Startup directory: /media/i3/Mordred/Games/Adventure Game Studio/Trilby 3 - Trilby's Notes Special Edition
Data directory: /media/i3/Mordred/Games/Adventure Game Studio/Trilby 3 - Trilby's Notes Special Edition/
Setting up game configuration
Unable to init voice pack 'speech.vox', file not found or of unknown format.
Initializing TTF renderer
Initializing mouse: number of buttons reported is 3
Install timer
Audio driver: pulseaudio
AudioCore: opened device "Default OpenAL playback device"
Supported sound decoders:
 - Play modules through ModPlug : 669,AMF,AMS,DBM,DMF,DSM,FAR,GDM,IT,MDL,MED,MOD,MT2,MTM,OKT,PTM,PSM,S3M,STM,ULT,UMX,XM,
 - MPEG-1 Audio Layer I-III : MP3,MP2,MP1,
 - Microsoft WAVE audio format : WAV,
 - Audio Interchange File Format : AIFF,AIF,
 - Sun/NeXT audio file format : AU,
 - Ogg Vorbis audio : OGG,
 - Creative Labs Voice format : VOC,
 - Raw audio : RAW,
 - Shorten-compressed audio data : SHN,
 - Free Lossless Audio Codec : FLAC,FLA,
Install exit handler
Initialize legacy path finder library
Game title: 'Trilby's Notes SE'
Game uid (old format): `1112392103`
Game guid: ''
Game GUI version: 105
WARNING: font 'agsfnt0.wfn' has mistakes in data format, some characters may be displayed incorrectly
WARNING: font 'agsfnt0.wfn' has mistakes in data format, some characters may be displayed incorrectly
Checking for disk space
Game native resolution: 320 x 240 (8 bit) letterbox-by-design
Graphic settings: driver: OGL, windowed: no, screen size: 0 x 0, game scale: round
Running OpenGL: 4.6
Graphics mode set: 1920 x 1080 (32-bit) fullscreen desktop
Mouse speed control: enabled, unit: 1.000000, user value: 2.000000
Touch-to-mouse motion mode: absolute
Multitasking mode set: 0
Setting up window
Multitasking mode set: 0
Initialize sprites
Engine initialization complete
Starting game
Quitting the game...
***** ENGINE HAS SHUTDOWN

and the acsetup.cfg config file in the game dir is:

[sound]
midiid=AUTO
[graphics]
vsync=1
game_scale_fs=max_round
windowed=0
[language]
translation=
[mouse]
auto_lock=0
speed=2

btw, was midiid deprecated meanwhile?

AGS Version
Adventure Game Studio v3.6 Interpreter
Copyright (c) 1999-2011 Chris Jones and 2011-2023 others
ACI version 3.6.0.44

self compiled, commit 8365802

Game
https://archive.org/details/Trilbys_Notes

To Reproduce
just start game

Expected behavior
Music

Desktop (please complete the following information):

  • OS: Linux sleipnir 5.15.0-60-generic #66-Ubuntu SMP Fri Jan 20 14:29:49 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
@i30817
Copy link
Author

i30817 commented Mar 7, 2023

Apparently the scummvm downstream is still playing music. I removed patches.dat to make sure, and apparently it's still playing.

I also tried to move the game dir to a place without spaces and changed the executable name to remove the spaces there to see if it made a difference - it didn't.

@i30817
Copy link
Author

i30817 commented Mar 7, 2023

Ahah. I installed freepats.

That soundfont does produce sound possibly because it's the default one so you might not even need to configure it... but it's very bad sound. One of the worst i ever heard. Pa-Pa-Pa. Seems like either pulseaudio just hates it or something else is going on.

@ivan-mogilko ivan-mogilko added this to the 3.6.0 milestone Mar 7, 2023
@ivan-mogilko ivan-mogilko added type: bug unexpected/erroneous behavior in the existing functionality context: audio system: linux labels Mar 7, 2023
@ivan-mogilko
Copy link
Contributor

ivan-mogilko commented Mar 7, 2023

To clarify, difference with Scummvm may be irrelevant here*, because they may be using their own midi loader and audio backend.
(* - unless we use them as an example to implement something)
In regards to Allegro, we (and scummvm's ags port) use a stripped version of allegro4 code which does not have any device or audio support code, but only math, bitmap drawing, and similar utilities.

@ericoporto
Copy link
Member

ericoporto commented Mar 7, 2023

@i30817 , there is something wrong in your build, I don't see the following in your log:

Supported sound decoders:
- MIDI decoder, using a subset of TiMidity : MIDI,MID,

How did you build SDL_sound from source? We don't use any timidity you may have installed in your system, the one used is inside SDL_sound itself, so you HAVE to build SDL_sound from source if you are building by hand.

Can you explain how you are building ags?

In you acsetup

[sound]
midiid=AUTO

I think this is not used anymore, midi goes through OpenAL interface now (mojoAL is the one we use).

@i30817
Copy link
Author

i30817 commented Mar 7, 2023

I see. I'd forgotten about it, but i built SDL2_sound ages ago and installed it with checkinstall. I guess it's so out of date that not even the make picks it up for MIDI.

I'll have to redownload it all over again and build it because i lost/removed the sdl git repo i had locally ages ago.

@i30817
Copy link
Author

i30817 commented Mar 7, 2023

Oh nice, they actually released it. https://github.com/icculus/SDL_sound/releases/tag/v2.0.1

Guess i don't need git.

@ericoporto
Copy link
Member

Please build from their main and use the latest commit, I think their release is quite old. Also you need to do something there to actually include Timidity in the build.

@i30817
Copy link
Author

i30817 commented Mar 7, 2023

Do i need to do something else in the ags make file? Because i build sdl-sound with timidity support, created the deb package and installed it (removing the previous one), verified the package has playsound, include headers and libraries, both dynamic and static.

but when i try to build ags it still comes out without that line you mention.

i named the package sdl-sound, should it be another name or something, or is that irrelevant?

@i30817
Copy link
Author

i30817 commented Mar 7, 2023

Mmm, i'm not using cmake to build the ags engine, but the make file in the Engine subdir.

That's one possibility of breakage. The other is ... well, i'm not really a professional programmer so i'm ignorant about what linker names actually mean, and since i'm constructing the package, i'm worried i gave it the wrong name.

The linker (in Makefile-defs.linux for the non-cmake version) is using -lSDL2_sound

I tried package names and description 'libsdl-sound', 'libsdl2-sound', 'sdl2-sound' and 'sdl-sound', but it seems none picked it up.

The header file in the package ends up in /usr/local/include/SDL2/SDL_sound.h

@i30817
Copy link
Author

i30817 commented Mar 7, 2023

Mmm, no, that is controlled by the SDL_sound.pc file which is in the package, and appears to have all the right things... So i don't get it.

make CPATH=/usr/local/include/SDL2/ USE_BUILT_IN_LIBSRC=0 ags in the Engine dir is how i'm making it. It seems to pick up SDL2_audio (it doesn't fail linking SDL_audio.h) but it never shows that text you say it should and never plays midi. And i did build sdl_audio with timidity support and cmake says so...

@ericoporto
Copy link
Member

Is there any specific reason to not use the prebuilt AGS engine from the release packages? Does it work in your system?

The CMake build will also just build everything by default and then you can selectively tell it to use libraries from your system by using it's variables, later, after you get it working with the default config.

@i30817
Copy link
Author

i30817 commented Mar 7, 2023

Well, i like to use the git so i can report bugs with bisects.

I'm not using cmake because it's easier to automate make because i already made a script and a navi snippet (it's a cmdline command organizer) to pull branches and prs then automatically make them.

Since the script is only working with make, that's what i'm using.

@ericoporto
Copy link
Member

ericoporto commented Mar 7, 2023

Can you give the output of ldd ags (or ldd MYAGSBINARY)? This should tell where is the SDL_Sound you are linking. And can you tell the exact commit of SDL_Sound that you build?

Is there any chance there's something else that uses SDL_Sound 1 (based on SDL 1) in your system? I don't remember if the package actually changed names. Only SDL_Sound 1 is in Ubuntu repositories.

I just mentioned to try using a binary from our releases, because the claim that Midi is not working is incorrect afaict - it's not a bug.

@ivan-mogilko
Copy link
Contributor

ivan-mogilko commented Mar 7, 2023

I also use raw make in most cases (sometimes I use instructions for debian/rules in order to install ags as a package), and iirc I had to manually install SDL_sound on my system, because it did not have any installation scripts, at least at the time when I last checked. But I don't remember these details by heart unfortunately. I might try again later and see what I had to do.

@i30817
Copy link
Author

i30817 commented Mar 7, 2023

It's 'libSDL2_sound.so.2 => /usr/local/lib/libSDL2_sound.so.2 (0x00007fdb30116000)'

Which in turn is is a link to libSDL2_sound.so.2.0.1 (i put in that version in checkinstall), which is one of the two versions of the library that the package installs (the other is the .a file version).

Everything appears fine with that... i guess.

@i30817
Copy link
Author

i30817 commented Mar 7, 2023

libsdl-sound1.2 and libsdl-sound1.2-dev are also installed... but the header is on another directory (/usr/include/SDL/SDL_sound.h instead of /usr/include/SDL2/SDL_sound.h)

@ericoporto
Copy link
Member

ericoporto commented Mar 7, 2023

My suggestion would be, build libSDL2_Sound.so from main and then just mv it in place and see if it works. Don't use the release as there are several commits after that fixed different issues.

Edit: I think you can also use LD_LIBRARY_PATH to force Linux to look in the specific dir first, say if you have SDL_Sound/build you pass that dir.

@i30817
Copy link
Author

i30817 commented Mar 7, 2023

It may not be clear, but i took your advice before. I am building from main, specifically the last commit (first) then the next to last because the git log mentioned the last commit messed with the cmakefile.

I'm actually giving up. I built sdl_audio correctly at least 10 times, installing each time with make install after uninstalling the previous build, checked its make file and edited the default value of sdlsound_decoder_option(MIDI "Midi" ".MID" FALSE) to sdlsound_decoder_option(MIDI "Midi" ".MID" TRUE), tried instead to pass the required flags too, verified the ags built links to the .so, even tried the LD_LIBRARY_PATH=/SDL_sound/build/ trick, but ags never reports MIDI in its 'Supported sound decoders'.

Going to sleep and not think about this.

@i30817
Copy link
Author

i30817 commented Mar 7, 2023

Just for kicks, i tried to install the deb in the prerelease. It still didn't work (i used the full path to not be confused by the alias i have to my build dir ags)

This is what ldd said about that file:

i3@sleipnir:/media/i3/Mordred/Games/Adventure Game Studio/Trilby 3 - Trilby's Notes Special Edition$ ldd /usr/bin/ags 
	linux-vdso.so.1 (0x00007ffcf13e5000)
	libogg.so.0 => /lib/x86_64-linux-gnu/libogg.so.0 (0x00007f6682804000)
	libtheora.so.0 => /lib/x86_64-linux-gnu/libtheora.so.0 (0x00007f66827bb000)
	libvorbis.so.0 => /lib/x86_64-linux-gnu/libvorbis.so.0 (0x00007f668278e000)
	libSDL2-2.0.so.0 => /lib/x86_64-linux-gnu/libSDL2-2.0.so.0 (0x00007f66825ee000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f66825e9000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f66825e4000)
	libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f66823b8000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f66822d1000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f66822b1000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6682089000)
	libcairo.so.2 => /lib/x86_64-linux-gnu/libcairo.so.2 (0x00007f6681f61000)
	libasound.so.2 => /lib/x86_64-linux-gnu/libasound.so.2 (0x00007f6681e5e000)
	libpulse.so.0 => /lib/x86_64-linux-gnu/libpulse.so.0 (0x00007f6681e07000)
	libX11.so.6 => /lib/x86_64-linux-gnu/libX11.so.6 (0x00007f6681cc7000)
	libXext.so.6 => /lib/x86_64-linux-gnu/libXext.so.6 (0x00007f6681cb2000)
	libXcursor.so.1 => /lib/x86_64-linux-gnu/libXcursor.so.1 (0x00007f6681ca6000)
	libXinerama.so.1 => /lib/x86_64-linux-gnu/libXinerama.so.1 (0x00007f6681ca1000)
	libXi.so.6 => /lib/x86_64-linux-gnu/libXi.so.6 (0x00007f6681c8d000)
	libXfixes.so.3 => /lib/x86_64-linux-gnu/libXfixes.so.3 (0x00007f6681c83000)
	libXrandr.so.2 => /lib/x86_64-linux-gnu/libXrandr.so.2 (0x00007f6681c76000)
	libXss.so.1 => /lib/x86_64-linux-gnu/libXss.so.1 (0x00007f6681c71000)
	libXxf86vm.so.1 => /lib/x86_64-linux-gnu/libXxf86vm.so.1 (0x00007f6681c6a000)
	libdrm.so.2 => /lib/x86_64-linux-gnu/libdrm.so.2 (0x00007f6681c54000)
	libgbm.so.1 => /lib/x86_64-linux-gnu/libgbm.so.1 (0x00007f6681c43000)
	libwayland-egl.so.1 => /lib/x86_64-linux-gnu/libwayland-egl.so.1 (0x00007f6681c3c000)
	libwayland-client.so.0 => /lib/x86_64-linux-gnu/libwayland-client.so.0 (0x00007f6681c2b000)
	libwayland-cursor.so.0 => /lib/x86_64-linux-gnu/libwayland-cursor.so.0 (0x00007f6681c21000)
	libxkbcommon.so.0 => /lib/x86_64-linux-gnu/libxkbcommon.so.0 (0x00007f6681bda000)
	libdecor-0.so.0 => /lib/x86_64-linux-gnu/libdecor-0.so.0 (0x00007f6681bd0000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f668282f000)
	libpixman-1.so.0 => /lib/x86_64-linux-gnu/libpixman-1.so.0 (0x00007f6681b23000)
	libfontconfig.so.1 => /lib/x86_64-linux-gnu/libfontconfig.so.1 (0x00007f6681ad9000)
	libfreetype.so.6 => /lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007f6681a11000)
	libpng16.so.16 => /lib/x86_64-linux-gnu/libpng16.so.16 (0x00007f66819d6000)
	libxcb-shm.so.0 => /lib/x86_64-linux-gnu/libxcb-shm.so.0 (0x00007f66819d1000)
	libxcb.so.1 => /lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f66819a7000)
	libxcb-render.so.0 => /lib/x86_64-linux-gnu/libxcb-render.so.0 (0x00007f6681996000)
	libXrender.so.1 => /lib/x86_64-linux-gnu/libXrender.so.1 (0x00007f6681989000)
	libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f668196d000)
	libpulsecommon-15.99.so => /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-15.99.so (0x00007f66818e8000)
	libdbus-1.so.3 => /lib/x86_64-linux-gnu/libdbus-1.so.3 (0x00007f668189a000)
	libwayland-server.so.0 => /lib/x86_64-linux-gnu/libwayland-server.so.0 (0x00007f6681882000)
	libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007f6681851000)
	libffi.so.8 => /lib/x86_64-linux-gnu/libffi.so.8 (0x00007f6681844000)
	libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007f668183b000)
	libbrotlidec.so.1 => /lib/x86_64-linux-gnu/libbrotlidec.so.1 (0x00007f668182d000)
	libXau.so.6 => /lib/x86_64-linux-gnu/libXau.so.6 (0x00007f6681825000)
	libXdmcp.so.6 => /lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f668181d000)
	libsndfile.so.1 => /lib/x86_64-linux-gnu/libsndfile.so.1 (0x00007f668179e000)
	libX11-xcb.so.1 => /lib/x86_64-linux-gnu/libX11-xcb.so.1 (0x00007f6681799000)
	libsystemd.so.0 => /lib/x86_64-linux-gnu/libsystemd.so.0 (0x00007f66816d2000)
	libasyncns.so.0 => /lib/x86_64-linux-gnu/libasyncns.so.0 (0x00007f66816ca000)
	libapparmor.so.1 => /lib/x86_64-linux-gnu/libapparmor.so.1 (0x00007f66816b3000)
	libbrotlicommon.so.1 => /lib/x86_64-linux-gnu/libbrotlicommon.so.1 (0x00007f6681690000)
	libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007f6681678000)
	libFLAC.so.8 => /lib/x86_64-linux-gnu/libFLAC.so.8 (0x00007f668163c000)
	libvorbisenc.so.2 => /lib/x86_64-linux-gnu/libvorbisenc.so.2 (0x00007f6681591000)
	libopus.so.0 => /lib/x86_64-linux-gnu/libopus.so.0 (0x00007f6681531000)
	liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f6681506000)
	libzstd.so.1 => /lib/x86_64-linux-gnu/libzstd.so.1 (0x00007f6681437000)
	liblz4.so.1 => /lib/x86_64-linux-gnu/liblz4.so.1 (0x00007f6681417000)
	libcap.so.2 => /lib/x86_64-linux-gnu/libcap.so.2 (0x00007f668140c000)
	libgcrypt.so.20 => /lib/x86_64-linux-gnu/libgcrypt.so.20 (0x00007f66812ce000)
	libmd.so.0 => /lib/x86_64-linux-gnu/libmd.so.0 (0x00007f66812bf000)
	libgpg-error.so.0 => /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007f6681299000)

Which unlike my self build isn't even linking to sdl2_sound. Not sure if it's supposed to be a static build? Regardless, it still didn't show that text it's supposed to show when running trilby notes.

@ivan-mogilko
Copy link
Contributor

ivan-mogilko commented Mar 7, 2023

@ericoporto

@i30817 , there is something wrong in your build, I don't see the following in your log:

This line:
- MIDI decoder, using a subset of TiMidity : MIDI,MID,

Is not displayed when decoder was not initialized successfully, which may also happen if it did not find timidity config.

So maybe the problem is not that it is not built correctly, but that it cannot find timidity.cfg correctly, or for some other internal reasons.

EDIT: unfortunately it seems that SDL_Sound only logs if DEBUG_CHATTER is defined, and it does not have own verbosity settings.

EDIT2: BTW, I found that my build on linux also does not have MIDI working, so I'll have to investigate this too. (Cannot tell if that's related to @i30817's problem, or this is something separate)

@i30817
Copy link
Author

i30817 commented Mar 7, 2023

I'll admit, not in all tests i had the config file (it was only in the directory of one game, and i'm assuming it fallsback to the game directory). But the firsts, and last few tests were with one.

@ivan-mogilko
Copy link
Contributor

ivan-mogilko commented Mar 7, 2023

it was only in the directory of one game, and i'm assuming it fallsback to the game directory

If you refer to timidity.cfg, then no, it does not fallback to game dir. This is the option that we were missing, and even opened a ticket in SDL_Sound repo for this and similar purposes:
icculus/SDL_sound#69

According to the SDL_sound sources it looks in:

  • TIMIDITY_CFG env variable
  • /etc/timidity.cfg
  • /etc/timidity/freepats.cfg

@i30817
Copy link
Author

i30817 commented Mar 7, 2023

Unfortunately, TIMIDITY_CFG doesn't work either, i tried it before (and i tried it again just now).

edit: copying to /etc/timidity.cfg and renaming to /etc/timidity/freepats.cfg doesn't work either

I do remember that if i installed freepats, i had ... very bad... sound in this game. But since timidity mentions that freepats is the default soundfont that could be just that by finding nothing, it's falling back to something it understands, and the error is getting the other paths to the library.

Not sure if freepats sound being terrible is another bug, pulseaudio underruns, or just a effect of a bad soundfont for the game.

If your problem is the same as mine, installing freepats soundfont might indicate it i guess. It's a 30mb download.

Makes me wish that patches.dat in the game directory still worked, which is what i did previously to all the games that required soundfonts (i used hardlinks instead of duplicating), when allegro still was handling midi.

@i30817
Copy link
Author

i30817 commented Mar 8, 2023

Also tried the idea of using TIMIDITY_CFG to point directly to the soundfonts cfg i have, instead of using the timidity.cfg with 'source /pathtosoundfont.cfg' inside.

That didn't work either. Peace out.

@ericoporto
Copy link
Member

OK, I tested and confirm it is indeed working in Ubuntu.

Here's a self contained ags binary that should work: ags.tar.gz . It should generate a lot more log messages.

I confirmed that the midi decoder line is indeed shown. But if it fails to initialize because of TIMIDITY_CFG is not set, it' s not shown at all.

My question is, @i30817 , what is the value you set TIMIDITY_CFG and how did you set it?

I did export TIMIDITY_CFG=/home/myuser/timidity/timidity.cfg

Here is the test game I used:
larry_test.ags.zip

I used the timidity files here. Note you have to fix the PATH in timidity.cfg as I packaged the file at the time for testing on windows.

Here is the log of it running in my linux machine: log.txt

@i30817
Copy link
Author

i30817 commented Mar 8, 2023

i3@sleipnir:~/Downloads/Trilby 3 - Trilby's Notes Special Edition$ TIMIDITY_CFG=/home/i3/Downloads/Trilby\ 3\ -\ Trilby\'s\ Notes\ Special\ Edition/timidity.cfg /home/i3/Downloads/ags 
Adventure Game Studio v3.6 Interpreter
Copyright (c) 1999-2011 Chris Jones and 2011-2023 others
ACI version 3.6.0.44

Initializing backend libs
SDL Version: 2.24.1
Initializing game data
Located game data pak: /home/i3/Downloads/Trilby 3 - Trilby's Notes Special Edition/notes se.exe
Opened game data file: ac2game.dta
Game data version: 27
Compiled with: 2.62
Startup directory: /home/i3/Downloads/Trilby 3 - Trilby's Notes Special Edition
Data directory: /home/i3/Downloads/Trilby 3 - Trilby's Notes Special Edition/
Setting up game configuration
Unable to init voice pack 'speech.vox', file not found or of unknown format.
Initializing TTF renderer
Initializing mouse: number of buttons reported is 3
Install timer
Audio driver: pulseaudio
AudioCore: opened device "Default OpenAL playback device"

TIMIDITY_CFG= /home/i3/Downloads/Trilby 3 - Trilby's Notes Special Edition/timidity.cfg

init config file: /home/i3/Downloads/Trilby 3 - Trilby's Notes Special Edition/timidity.cfg

init_with_config Timidity result rc = 0
SDL : APP: INFO: Trying to open /home/i3/Downloads/Trilby 3 - Trilby's Notes Special Edition/timidity.cfg
SDL : APP: INFO: Trying to open /etc/timidity/fluidr3_gm.cfg
SDL : APP: INFO: /etc/timidity/fluidr3_gm.cfg: line 6: bad patch option FluidR3_GM.sf2

read_config_file Timidity result rc = -1
SDL : APP: INFO: __Sound_SetError("MIDI: Could not initialise"); [NOT INITIALIZED!]
Supported sound decoders:
 - Play modules through ModPlug : 669,AMF,AMS,DBM,DMF,DSM,FAR,GDM,IT,MDL,MED,MOD,MT2,MTM,OKT,PTM,PSM,S3M,STM,ULT,UMX,XM,
 - MPEG-1 Audio Layer I-III : MP3,MP2,MP1,
 - Microsoft WAVE audio format : WAV,
 - Audio Interchange File Format : AIFF,AIF,
 - Sun/NeXT audio file format : AU,
 - Ogg Vorbis audio : OGG,
 - Creative Labs Voice format : VOC,
 - Raw audio : RAW,
 - Shorten-compressed audio data : SHN,
 - Free Lossless Audio Codec : FLAC,FLA,
Install exit handler
Initialize legacy path finder library
Game title: 'Trilby's Notes SE'
Game uid (old format): `1112392103`
Game guid: ''
Game GUI version: 105
WARNING: font 'agsfnt0.wfn' has mistakes in data format, some characters may be displayed incorrectly
WARNING: font 'agsfnt0.wfn' has mistakes in data format, some characters may be displayed incorrectly
Checking for disk space
Game native resolution: 320 x 240 (8 bit) letterbox-by-design
Graphic settings: driver: OGL, windowed: no, screen size: 0 x 0, game scale: round
Running OpenGL: 4.6
Graphics mode set: 1920 x 1080 (32-bit) fullscreen desktop
Mouse speed control: enabled, unit: 1.000000, user value: 2.000000
Touch-to-mouse motion mode: absolute
Multitasking mode set: 0
Setting up window
Multitasking mode set: 0
Initialize sprites
Engine initialization complete
Starting game
SDL : APP: INFO: MODPLUG: Unrecognized file type: mid
SDL : APP: INFO: __Sound_SetError("MODPLUG: Not a module file.");
SDL : APP: INFO: __Sound_SetError("MP3: Not an MPEG-1 layer 1-3 stream.");
SDL : APP: INFO: __Sound_SetError("WAV: Not a RIFF file.");
SDL : APP: INFO: __Sound_SetError("AIFF: Not a FORM file.");
SDL : APP: INFO: __Sound_SetError("AU: Not an .AU stream.");
SDL : APP: INFO: __Sound_SetError("VORBIS: missing capture pattern");
SDL : APP: INFO: __Sound_SetError("VOC: Wrong signature; not a VOC file.");
SDL : APP: INFO: __Sound_SetError("RAW: extension isn't explicitly "RAW".");
SDL : APP: INFO: __Sound_SetError("SHN: Not a SHN file");
SDL : APP: INFO: __Sound_SetError("FLAC: Not a FLAC stream.");
SDL : APP: INFO: __Sound_SetError("Sound format unsupported");
SDL : APP: INFO: WAV: Appears to be uncompressed audio.
SDL : APP: INFO: WAV: Accepting data stream.
SDL : APP: INFO: New sample DESIRED format: S16LSB format, 22050 rate, 1 channels.
SDL : APP: INFO: New sample ACTUAL format: S16LSB format, 22050 rate, 1 channels.
SDL : APP: INFO: On-the-fly conversion: DISABLED.
SDL : APP: INFO: WAV: Appears to be uncompressed audio.
SDL : APP: INFO: WAV: Accepting data stream.
SDL : APP: INFO: New sample DESIRED format: S16LSB format, 22050 rate, 1 channels.
SDL : APP: INFO: New sample ACTUAL format: S16LSB format, 22050 rate, 1 channels.
SDL : APP: INFO: On-the-fly conversion: DISABLED.
Quitting the game...
***** ENGINE HAS SHUTDOWN

@ericoporto
Copy link
Member

Random idea: @i30817 , can you confirm in your pat files there is only / as separator in the paths and no \ (windows separator)?

@ivan-mogilko
Copy link
Contributor

ivan-mogilko commented Mar 9, 2023

I honestly think it's SDL2 'refactoring' timidity may have broken compatibility with the older and more arcane file format / and or indirections in the fileformat.

Well, we are using completely different sound loading library now, SDL_Sound (it's not directly a part of SDL2, but a separate lib). IMHO the problems of format parsing, and problems of not finding files may be considered SDL_Sound lib issues, and/or issues of the version of Timidity source that they are using. They may be reported as a bug or feature suggestions in their repository:
https://github.com/icculus/sdl_sound
We already opened one ticket there in regards to this.
Maybe some of us could look into this too later and make a pr to them, when we get more spare time.
For instance, I think being able to direct to a custom cfg file location is a must. Of course I don't know anything about the pat formats, so cannot imagine if it's difficult to add missing support to timidity.

The alternative would be to support MIDI loading ourselves, by embedding either that, or old allegro's code directly in the engine, and converted as necessary, and then having to maintain it altogether.

@i30817
Copy link
Author

i30817 commented Mar 9, 2023

Yeah, there are no \.

I did a small experiment with the soundfont that worked, and i'm preeeeety sure that at least the source command is broken, if not sure about the rest i mentioned in my last post.

Because i have a game tree like this:

.
├── game.ags
├── t2
│   ├── ...rest of soundfont files
│   ├── timidity.cfg
└── timidity.cfg

And the outer timidity is just 'souce t2/timidity.cfg'

Trying to load the outer:
TIMIDITY_CFG=/home/i3/Downloads/larry_test.ags/timidity.cfg /home/i3/Downloads/ags

says it loads the inner later:


TIMIDITY_CFG= /home/i3/Downloads/larry_test.ags/timidity.cfg

init config file: /home/i3/Downloads/larry_test.ags/timidity.cfg

init_with_config Timidity result rc = 0
SDL : APP: INFO: Trying to open /home/i3/Downloads/larry_test.ags/timidity.cfg
SDL : APP: INFO: Trying to open t2/timidity.cfg

read_config_file Timidity result rc = 0

but later says:

SDL : APP: INFO: Trying to open /home/i3/Downloads/larry_test.ags/synpiano
SDL : APP: INFO: Could not open synpiano

notice the path forgetting about the subdirectory, like if the outer cfg was the right base path, not the inner one.

While loading the inner timidity.cfg loads it correctly and music plays

So, at least that is wrong. Oh well.

@i30817
Copy link
Author

i30817 commented Mar 9, 2023

I do think there is more wrong because i tried to load the 'source' files that the main timidity.cfg installed by soundfonts asks for with

TIMIDITY_CFG=/etc/timidity/fluidr3_gs.cfg /home/i3/Downloads/ags

and

TIMIDITY_CFG=/etc/timidity/fluidr3_gm.cfg /home/i3/Downloads/ags

and

TIMIDITY_CFG=/etc/timidity/timgm6mb.cfg /home/i3/Downloads/ags

and none of them worked. But now that i think about it, the same thing can be a problem because the first command of those files is:

dir /usr/share/sounds/sf2

another redirection, slightly different in that it's not a cfg file, but the same kind of operation to present the files in the file as relative to a path...

Although , the error actually mentioned in these cases for the ags that was provided in this thread is the strangely consistent:

SDL : APP: INFO: /etc/timidity/timgm6mb.cfg: line 6: bad patch option TimGM6mb.sf2

strange because it's always line 6 in all 3 sound fonts and line 6 doesn't appear special.

edit: no i lie, for gs it's line 5.

@ivan-mogilko
Copy link
Contributor

ivan-mogilko commented Mar 9, 2023

I'm afraid there's alot of information in this thread already, but not much that we can do with this.
From what I am capable to understand at this point, there may be 2 distinct problems:

  1. Not being able to find cfg in wanted locations. For example, engine cannot look for timidity.cfg in the game dir implicitly, without having TIMIDITY_CFG set.
  2. Timidity itself (integrated in SDL_Sound) fails to parse some of the cfg and/or patch syntax.

All of these issues currently relate to SDL_Sound/Timidity library. AGS engine itself does not participate in any of this.

I think we may open a ticket in their repo for at least the problem 1 (being able to tell where to look for timidity.cfg). In fact, we might even try to make a PR for them ourselves.

Regarding other, personally I don't have enough knowledge about the syntax or expected behavior, so I cannot do the same.
So perhaps someone who understands this better could make respective bug/feature tickets in SDL_Sound repo, and let its author(s) and contributor(s) handle these.

Alternatives would be to either

  • Plan using another, more suitable, library for loading MIDI;
  • Plan on implementing our own MIDI support in the engine, with all the necessary feature support. I have no idea if any of our contributors would be willing to have a take on that.

@ericoporto
Copy link
Member

ericoporto commented Mar 9, 2023

I don't like the idea of telling where to look vs using SDL_rwops, because using SDL_rwops means we can actually run everything through our asset manager, so we get assets in Android, we get logging, we get the priority of where to look for things.

Telling where to look will just be inconsistent. And you already can do by leveraging SDL_setenv before SDL2_Sound is initialized. I think you also need to revert SDL_setenv when it quits, because SDL_setenv I think sets for the environment.

One thing to PR there is some better logging because it's terrible as is. Also if it's possible to use the SDL hint system instead of environment variables and have it have priority over everything and be possible to just NOT initialize it.

But it won't work consistently and you can't tell when it fails properly/why it fails properly.

@ivan-mogilko
Copy link
Contributor

And you already can do by leveraging SDL_setenv before SDL2_Sound is initialized

Hm, this sounds like this may be used as a hotfix for desktop at least.

@ericoporto
Copy link
Member

The only problem with setenv that I don't know if it's a problem or if it's a problem in some platforms is how the env is persisted after the application exits or if it's persisted at all.

@ivan-mogilko
Copy link
Contributor

ivan-mogilko commented Mar 9, 2023

Ah, no, I remembered why this may be a bad idea: because in that case the user's env variable won't be used. We cannot ask to search in local dir, and then search in whatever user had set before running the game.
This could be done only if there were a separate setting provided in SDL_Sound API; either a function or a SDL-style hint.

@i30817
Copy link
Author

i30817 commented Mar 11, 2023

Frankly, as it is now, it's unusable anyway, unless i want to make a mess/annoy myself.

To have sound here i'd either to have to remember to set the env var every time, or place the directory contents of the one soundfont that worked on the etc/timidity dir (horrible idea), or place the contents of the soundfont + timidity.cfg on the game directory root.

If i was a completely clueless user, i'd have no clue about this, so you just know almost everyone has it broken.

I'd actually prefer using the env variable as a temporary hotfix, to prevent the 'mess', if the 'hotfix' canonized a alternate relative 'timidity dir' to place in the env variable that is under the current game directory (or current directory rather, which I guess is not the same thing all the time - edit, actually in linux it kind of is, because the ags executable is not in the game directory so the only way to find the data is to start ags in the game directory).

Very annoying, especially after allegro finally working.

I suspect that SDL_audio didn't exactly test or expect this to be used yet.

@i30817
Copy link
Author

i30817 commented Mar 11, 2023

Meanwhile, here is my workaround:

For the soundfont that works, i took the timidity file that came with it, and changed the instruments inside it to add 'soundfont/' before the start of each instrument. This is enough to load the music and keep the instruments in a subdir, with timidity.cfg on the top level of the game dir.
timidity.cfg.txt

I'm not sure if this trick will work in windows because of the directory separator. I know that windows can use / as directory separator in some cases, and in some cases it can't, but i don't have windows to test.

To deduplicate the soundfonts, since hardlinks to directories are forbidden, it's better to hardlink the files. Inside the 'real' soundfont directory, cp * -l /variousdestinations can do it.

@ivan-mogilko
Copy link
Contributor

ivan-mogilko commented Mar 11, 2023

The situation currently is this: I would like to release 3.6.0 very soon, because it's been in development for too long, is working in general, and has some new features very wanted by the game developers (such as unicode support, more game porting options, and graphics performance improvements), even though few specific features work worse or require workarounds to make them work. The MIDI is not the only problem with audio in this version after porting to SDL2 (there are few others; notably #1695 and #1687).

When making a release I'll of course add warnings about known issues and regressions.

After 3.6.0 is out, I will likely have to focus on fixing these regressions, and look into all this more closely, as there's few things I'll have to learn myself. These fixes will maybe released as small patches or some 3.6.* update.

In regards to the MIDI, this ticket looks more like a problem investigation log. We'd need to form a task description, where we'd have a clear and elaborate explanation of what is expected to work. That is: where do you want the engine to find the timidity.cfg and soundfonts, how to setup that location; what do you expect from configuration that does not work currently, and so on.
If you could write that down, even if here in comments, I would very much appreciate that.

When we have this, we may look into what the SDL_Sound does now, and see how feasible it is to add this support there (or, if it will be too complicated to do with the SDL_Sound, consider using a different approach, as noted above).

@ivan-mogilko ivan-mogilko changed the title No midi sound 3.6.0: Problems with MIDI audio and Timidity Mar 11, 2023
@ericoporto
Copy link
Member

I took a read of SDL_Sound and the timidity part already uses SDL_rwops internally, the problem is this method here, timi_openfile

https://github.com/icculus/SDL_sound/blob/9bdc56c2791ca8a98bd7838d6f17346c1e848a94/src/timidity/common.c#L36

It's used to create the SDL_rwops that will be passed around when either reading the config or the instruments and all. If there was a way to replace it with a different function, than we could use to read from our game assets or anywhere we want. Of course, an API to also pass the path directly would be required - or we would need to abuse a bit on the environment variable.

@rathann
Copy link
Contributor

rathann commented Mar 31, 2023

FWIW, I was able to make MIDI playback in Leasure Suit Larry 2 (under ags 3.6.0.46) work with both the dgguspat soundfont mentioned in #1941 (comment) and with the FluidR3_GM.sf2 after extracting the individual patch files with the unsf tool and pointing to the generated cfg file with TIMIDITY_CFG env variable. It seems to me that SDL_sound's timidity fork simply doesn't support the "joined" file format of soundfonts as mentioned in #1941 (comment) . I'd say the title should be modified to point to SDL_sound, not timidity, which is actually not involved here.

@ivan-mogilko ivan-mogilko modified the milestones: 3.6.0, 3.6.0 maintenance Apr 1, 2023
@ivan-mogilko ivan-mogilko changed the title 3.6.0: Problems with MIDI audio and Timidity 3.6.0: Problems with MIDI audio (SDL_Sound / Timidity issue) Apr 1, 2023
@ivan-mogilko
Copy link
Contributor

ivan-mogilko commented Apr 20, 2023

@i30817 , I am trying to gather the list of things needed to be fixed/changed in 3.6.x in regards to MIDI. Could you please tell, how should a soundfont data be searched by the engine in your opinion? E.g. should it check in the game's dir, or use a config setting, and so on (or is current search suitable)?

@i30817
Copy link
Author

i30817 commented Apr 20, 2023

As a gamer, i usually want to 'just play the game'. As a collector of ags games, i want 'platform and location independence' so i can copy paste games into other systems or run them in a detachable drive in another OS without anything breaking. I choose the second just because i had time, but regular people would probably choose to 'install a soundfont in the default soundfont path' if the game didn't come with the soundfont in the game dir.

This new version on SDL seems like a early beta. You 'have' to have a timidity.cfg, it 'has' to be very simple and use no redirection at all (which means you have to edit it or deal with hundreds of instrument files on the game dir if you choose the approach of the soundfont in the game dir), and from that it 'may' (not sure it will work) not be portable, because of the use of the '/' path separator inside timidity.cfg.

As a user i have no problems with the way it's checked now, first the timidity default dir, then the game dir (not executable dir, as they can/usually are different in linux). It's just more complicated than downloading a file from the internet, or installing debian timidity soundfonts, which means regular users will just have broken sound, because SDL2 is not supporting the regular system soundfonts and the one that works still needs edits on the config file.

Ie: the problems aren't in the paths; they're in SDL2 'beta' MIDI/timidity support. I'd prefer if it worked with the system soundfonts and with a compressed soundfont in the system dir, or the ags dir, then the game dir, if not, like Allegro did. But it doesn't.

Oh yes, you can probably add another tier of path between 'system' and 'game directory' with a 'ags cfg/data' dir check, for those people that don't want to put the soundfonts in all games that require them (i only do that for moving around systems with the games), but can't/won't change the system. I don't think it's actually necessary though if the usual system soundfonts you can install actually work.

@ivan-mogilko
Copy link
Contributor

ivan-mogilko commented Apr 20, 2023

I am trying to understand the desired behavior so that I could know which direction to go to. This may be broken into two parts: 1) quick fixes that would make existing implementation easier to work with; 2) more serious changes (like suggesting to patch a library, use another library, reimplementing midi support in the engine). My intent is also to write a proper task issue with clearly stated goals.

Therefore what I'd like to know is:

  • what data should the engine be looking to load for midi to work, and
  • where it should be looking for it.

My problem is that I never fully researched how the MIDI feature is supposed to work. I know there are sound fonts that tell how to play instruments, but I know little about their format, and how they are normally installed on a system. This is why many things said in this thread are difficult to understand for me.

Is there some documentation I can read on this?

I might also investigate how Allegro did this exactly, if that may be used as an example.

You 'have' to have a timidity.cfg, it 'has' to be very simple and use no redirection at all
I don't think it's actually necessary though if the usual system soundfonts you can install actually work.

Do I understand correctly, that the desired behavior you are speaking of (let's say hypothetically) is to make engine not require timidity.cfg and load sound fonts directlyfrom the standard system location where you normally install them?

NOTE: it's SDL_Sound library that loads midi, not SDL2.

@ericoporto
Copy link
Member

Reading the SDL_Sound codebase there are a bunch of FIX-ME (example). I don't think fixing all of them are feasible.

I think the better approach for now is to have a sound path that works and simply tell people to "use this".

@i30817
Copy link
Author

i30817 commented Apr 21, 2023

As i said, i don't think you can do anything about SDL_sound unless you're willing to PR there. Personally, i think linking a soundfont that works in the readme, and can be placed on game dirs or a shared dir, preferably one in a zip (or tar.gz, or something), and that works as a single file (so it's not too messy) would be good and 'enough' for casual users, but i'm not sure if it's possible to make sdl_sound work with that instead of bare instrument files (the lesser alternative is a folder with the instruments and a timidity.cfg that is altered to refer to the instruments inside the folder like i did above, assuming that works in both windows and unix).

If you want something actionable, a PR to sdl_sound to be able to load this type of single file soundfont (maybe with a timidity.cfg inside so two files aren't required), then when using the fork/updated sdl_sound put a link in the readme to soundfont that 'works' for users is more than enough.

If you want even more work, fixing the missing commands, particularly 'map' and 'source', so more of the traditional soundfonts works (from freepaths, timgm6mb-soundfont, fluid-soundfont-gm and fluid-soundfont-gs, these are the ubuntu package names) would also fix the complaints from most users because then sdl_sound would 'work if you install a soundfont'. BTW these sounfonts are also compressed/joined into a single file, i don't know the format.

The file utility in ubuntu calls the soundfont files (they're at /usr/share/sounds/sf2)
/usr/share/sounds/sf2/TimGM6mb.sf2: RIFF (little-endian) data, SoundFont/Bank so who knows if they are a custom format or whatever.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
context: audio system: linux type: bug unexpected/erroneous behavior in the existing functionality
Projects
None yet
Development

No branches or pull requests

4 participants