thobbsinteractive / magic-carpet-2-hd

Recode Binary code of game Magic Carpet2 to C/C++ language(remake MC2 for any platform)
GNU General Public License v3.0
27 stars 4 forks source link

sound on linux #237

Closed rodan closed 1 year ago

rodan commented 1 year ago

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?

rodan commented 1 year ago

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?

rodan commented 1 year ago

I have rewritten most of the openal implementation as a proof-of-concept in my openal branch.

what's new:

what would be nice to implement:

thobbsinteractive commented 1 year ago

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 (https://github.com/thobbsinteractive/magic-carpet-2-hd/issues/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 (https://github.com/thobbsinteractive/magic-carpet-2-hd/issues/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.

rodan commented 1 year ago

good morning Tim,

There is no stereo or 3D that the GOG version seems to have., The tile Environmental sounds do not play (https://github.com/thobbsinteractive/magic-carpet-2-hd/issues/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 (https://github.com/thobbsinteractive/magic-carpet-2-hd/issues/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

thobbsinteractive commented 1 year ago

Hey Peter,

You could create a PR, then I could see what you intend to remove, even if I do not merge it immediately. My fix for the environments was to enforce a minimum volume level in the playback. I did not merge that fix as it felt wrong. If OpenAl works better we should perhaps move to it? I can test it out if you create a PR.

On Wed, 26 Apr 2023, 13:47 Petre Rodan, @.***> wrote:

good morning Tim,

There is no stereo or 3D that the GOG version seems to have., The tile Environmental sounds do not play (#54 https://github.com/thobbsinteractive/magic-carpet-2-hd/issues/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 https://github.com/thobbsinteractive/magic-carpet-2-hd/issues/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

— Reply to this email directly, view it on GitHub https://github.com/thobbsinteractive/magic-carpet-2-hd/issues/237#issuecomment-1523282951, or unsubscribe https://github.com/notifications/unsubscribe-auth/AETQQFF4LBKGMWZYLVECZY3XDEDN5ANCNFSM6AAAAAAXHXALC4 . You are receiving this because you commented.Message ID: @.***>

rodan commented 1 year ago

no need to rush OpenAL in, it's not been tested enough and I really need to fix a few things before:

would be nice to have:

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

thobbsinteractive commented 1 year ago

You got it

On Wed, 26 Apr 2023, 14:37 Petre Rodan, @.***> wrote:

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

— Reply to this email directly, view it on GitHub https://github.com/thobbsinteractive/magic-carpet-2-hd/issues/237#issuecomment-1523349878, or unsubscribe https://github.com/notifications/unsubscribe-auth/AETQQFFEBMXQEODNNUQV7FDXDEJKJANCNFSM6AAAAAAXHXALC4 . You are receiving this because you commented.Message ID: @.***>

rodan commented 1 year ago

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.

thobbsinteractive commented 1 year ago

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: https://github.com/thobbsinteractive/magic-carpet-2-hd/issues/182

rodan commented 1 year ago

the check_install.sh script fixes all known case-sensitivity problems, including #182