-
Notifications
You must be signed in to change notification settings - Fork 160
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
Comments
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. |
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. |
To clarify, difference with Scummvm may be irrelevant here*, because they may be using their own midi loader and audio backend. |
@i30817 , there is something wrong in your build, I don't see the following in your log:
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
I think this is not used anymore, midi goes through OpenAL interface now (mojoAL is the one we use). |
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. |
Oh nice, they actually released it. https://github.com/icculus/SDL_sound/releases/tag/v2.0.1 Guess i don't need git. |
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. |
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? |
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 |
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.
|
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. |
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. |
Can you give the output of 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. |
I also use raw |
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. |
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) |
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 |
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 Going to sleep and not think about this. |
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:
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. |
This line: 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) |
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. |
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: According to the SDL_sound sources it looks in:
|
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. |
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. |
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 I did Here is the test game I used: 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 |
|
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. If you compare the soundfont that worked here:
and the format of fluidsynth fluid3_gm.cfg (which can be indirected by timidity.cfg by uncommenting its corresponding 'source' line and commenting the others) :
well... one is separate files, the other is a joined file (possibly a zip, or something else), one is using some metacommand %font and other things... i suspect this is the problem. could also be that other soundfonts are being 'indirect' with the 'dir' and 'source' command. I already saw that nonexisted 'source' commands broke the recognition of 'support' for timidity on one of the cfgs (specifically when i had to comment 'sourcegravis.cfg' 'source gsdrums.cfg' and 'source gssfx.cfg' to get one to attempt to run (but still fail). |
Random idea: @i30817 , can you confirm in your pat files there is only |
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: 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. |
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: . And the outer timidity is just 'souce t2/timidity.cfg' Trying to load the outer: says it loads the inner later:
but later says:
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. |
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:
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. |
I'm afraid there's alot of information in this thread already, but not much that we can do with this.
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. Alternatives would be to either
|
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. |
Hm, this sounds like this may be used as a hotfix for desktop at least. |
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. |
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. |
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. |
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. 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, |
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. 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). |
I took a read of SDL_Sound and the timidity part already uses SDL_rwops internally, the problem is this method here, timi_openfile 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. |
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 |
@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)? |
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. |
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:
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.
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. |
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". |
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) |
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:
and so does the soundfount itself:
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:
and the acsetup.cfg config file in the game dir is:
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):
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
The text was updated successfully, but these errors were encountered: