sound on linux
rodan opened this issue · 10 comments
I just realized that the windows binary of the game has working sound.
is the audio expected to work under linux with the default config and the default compilation options (which include SDL_Mixer)?
the game registers with pulse-audio, interacts with alsa (based on strace), has 100% volume setting but it's completely silent.
tried compiling game with openal enabled with no improvement.
later found that in init_sound():594
run() which does the sound initialization is commented out. enabling that and providing a valid path to a midi file properly plays that midi file just fine, so at least the sequencer seems to be working. all game still silent.
I failed to find any function inside port_sdl_sound.cpp (except init_sound() ) that is actually executed by the game itself as if mc2 was configured to run with no sound card.
any ideas?
the check in Sound.cpp:642 was failing.
I checked and every single file and directory on the CD is lowercase in the iso file got from GOG:
bchunk game.gog game.ins chunk
mkdir /tmp/mc2_iso
mount -o loop chunk01.iso /tmp/mc2_iso
tree /tmp/mc2_iso/
/tmp/mc2_iso/
├── data
│ ├── bl16c0-0.dat
│ ├── bl16f0-0.dat
│ ├── bl16n0-0.dat
│ ├── bl32c0-0.dat
[..]
├── readme.txt
├── setsound.exe
└── sound
├── adlib.mdi
├── adlibg.mdi
├── adrv688.dig
├── aildrvr.lst
├── bullfrog.sbk
├── esfm.mdi
├── jammer.dig
├── mpu401.mdi
├── mt32mpu.mdi
├── music.dat
[..]
observe the lowercase in every single file name/directory^
so the game is looking for "SOUND", fails and marks all the sound system unusable.
file names are case sensitive in linux.
renaming the directory to SOUND allows pcm sound to come out
however there is a de-sync between the fire action and the sound output, I'd say the sound is delayed ~0.5s. is that normal?
also disabling the alternative ogg files appears to play the wrong midi sequences during the boulder menu. normal?
I have rewritten most of the openal implementation as a proof-of-concept in my openal branch.
what's new:
- cleaned up the code a bit
- new port_openal.cpp file that caches chunks and only binds the buffers once (during first use). any new request for the same chunk only sets up the source.
- a whitelist controls which chunks can be played concurrently (for example fast firing will play each pew sound even if the last one did not finish playing). any play request for chunks that are already playing and are not on the whitelist are dropped.
- no noticeable delay when playing cached sounds
- this implementation plays up to OPENAL_C_SZ number of chunks at the same time
- zero openal-related errors during use
- I'm thinking of making openal a required dependency just as sdl_mixer
what would be nice to implement:
- use player position and location of action to precisely pinpoint the sound source location (needs MONO chunks and good re-code knowledge)
- use the software EAX implementation (nice reverb) in cave levels
- replace 'fake_id' in the code with a better identifier (maybe with the sample's offset in sound.dat?)
We have many issues with sound with Windows too (I believe some are already logged as issues already).
There is no stereo or 3D that the GOG version seems to have., The tile Environmental sounds do not play (#54) and finally the reason I ship the ORG music by default is that the midi music is turned down at the start of a level, but not back up again (#8). Basically the games entire sound in Windows is turned down instead of just the midi track.
So sound is a mess and I appreciate you taking a look at it Rodan. You seem to be speaking from Experience.
good morning Tim,
There is no stereo or 3D that the GOG version seems to have., The tile Environmental sounds do not play (#54)
I'm happy to report that the environmental sounds work perfectly with my openal implementation. I can hear the crickets in the spawn point in the first map, also the sea is can be perfectly heard once I move over a body of water. you can check the code out in my 'openal' branch. Indeed I can't hear any of these with only SDL_mixer support.
I could do a pull request, but I did remove over 5000 files of deadweight from the repo in order to clean things up. you might kinda dislike that. plus there is more work that needs to be done in this openal corner.
and finally the reason I ship the ORG music by default is that the midi music is turned down at the start of a level, but not back up again (#8).
oh, for me midi works throughout the game, but many instruments are missing, I will have to look into that as well, probably I need to change the soundfont or something similar.
So sound is a mess and I appreciate you taking a look at it Rodan. You seem to be speaking from Experience.
please call me peter :)
while I am usually being paid to write C software, this is the first time I work directly on a game. and I work on this one because it's my second favorite DOS game from the 90s.
this past project of mine was also targeted directly at magic carpet2 : https://github.com/rodan/lemidi it allows the use of those 2 joysticks of mine in a pentium2 retro PC that ain't got no direct USB support.
best regards,
peter
no need to rush OpenAL in, it's not been tested enough and I really need to fix a few things before:
- a reliable and unique chunk id seems to be a pita to obtain (currently I'm using the chunk size as identifier, which ain't great)
- apparently all sound chunks are played at a volume level of 127, I need to see if some samples are set at a lower level after the chunk was sent to the driver - maybe this is where I will hit your environmental chunk bug, who knows.
- there is a feedback mechanism in which the recode wants to know if a sample has finished playing (SOUND_sample_status()). I absolutely need to implement that as well for openal.
would be nice to have:
- now that I know what sound chunk is played I can add force-feedback for some of the big damage spells (cave-in, tremor, volcano ...)
- environmental effects in cave levels (some chunks will need to be received as MONO by openal in order for this to work)
- update exact player location and source location instead of everything at (0,0,1) for a more immersive experience (also MONO chunks are needed for this)
if I do a PR now for openal it will drag everything with it, including my joystick patch.
so let's work on my joystick PR first since it is much more release-worthy in my opinion and I will re-base and provide a cleaner openal patch after that was merged in some form.
best regards,
peter
as predicted I ended hitting your environment bug as well. the recode is setting the chunk volume BEFORE the chunk is sent to the driver to be played, which was unexpected for me. I made this backward logic work and sure enough starting at the second play of the environment sound the volume is set to 0 - even if the sound keeps being pushed to be played every few seconds.
but since OpenAL's job will be to automatically decrease the volume of sources based on distance to the listener we don't need the recode's input in this task, so those set_sample_volume functions will be disabled.
the check in Sound.cpp:642 was failing. I checked and every single file and directory on the CD is lowercase in the iso file got from GOG:
bchunk game.gog game.ins chunk mkdir /tmp/mc2_iso mount -o loop chunk01.iso /tmp/mc2_iso tree /tmp/mc2_iso/ /tmp/mc2_iso/ ├── data │ ├── bl16c0-0.dat │ ├── bl16f0-0.dat │ ├── bl16n0-0.dat │ ├── bl32c0-0.dat [..] ├── readme.txt ├── setsound.exe └── sound ├── adlib.mdi ├── adlibg.mdi ├── adrv688.dig ├── aildrvr.lst ├── bullfrog.sbk ├── esfm.mdi ├── jammer.dig ├── mpu401.mdi ├── mt32mpu.mdi ├── music.dat [..]observe the lowercase in every single file name/directory^
so the game is looking for "SOUND", fails and marks all the sound system unusable. file names are case sensitive in linux.
renaming the directory to SOUND allows pcm sound to come out however there is a de-sync between the fire action and the sound output, I'd say the sound is delayed ~0.5s. is that normal? also disabling the alternative ogg files appears to play the wrong midi sequences during the boulder menu. normal?
We actually have a bug logged about this. I do not have a linux distribution running so have not fixed it yet: #182