maestun / alis

Silmarils game engine re-implementation
MIT License
18 stars 5 forks source link

Music and audio picth/speed is too high #11

Closed vanfanel closed 1 month ago

vanfanel commented 1 month ago

Hi there,

Just discovered this engine by searching for "Ishar opensource": I didn't expect any meaningful results, but wow! This is crazy, and a personal dream of mine you fulfilled: having my favorite saga of C-RPGs natively working on GNU/Linux via opensource. Incredible!

Maybe it's early days, but I saw that, at least using the DOS Ishar 1 data, music is too fast and has too high pitch also.

Also, a fullscreen mode option would be fantastic: I'm currently adding the SDL_WINDOW_FULLSCREENDESKTOP to SDL_CreateWindow() call, but a --fullscreen parameter would be very usefull: even if adding the flag on the code, the game appears pillarboxed by white areas that should be black.

Please keep up the work on this, I am really happy that this exists! :)

skruug commented 1 month ago

Hi, thanks for testing. :-)

The music playback code for Ishar uses an older version of the player, which was written at least on the Atari ST, using self-modifying code, and it was hell to figure out. So it's quite likely that Its still buggy. The speed and pitch can be adjusted in 'audio/music_v1.c' in the function 'mv1_gomusic()'. You can try to fix it, or you can wait, I'll fix it eventually. :-)

Another audio issue is missing implementation of OPL2 music in the DOS version of Ishar 2.

BTW I think there is a non-zero probability that different platforms played music with slight variations according to the capabilities of their hardware.

I will fix the remaining issues with pillarboxing and missing configuration in time, but they are not a priority. I'm kind of hoping that integration into ScummVM will solve the those problems for me. :-)

At the moment I am working on making all the games from 'Manhattan Dealers' to 'Robinson's Requiem' playable.

vanfanel commented 1 month ago

Pillarboxing is correct and expected, because these are 4:3 games on modern 16:9 displays: the only problem is that the pillars are white instead of black. I will try to experiment with the music playback, but I doubt I can fix it myself :(

vanfanel commented 1 month ago

@maestun I have found out that if I change this: https://github.com/maestun/alis/blob/44cc8affbab034554b5840566d25a42644e9a52e/src/sys/sdl2/sys_sdl2.c#L94 to be instead: SDL_SetRenderDrawColor(_renderer, 0, 0, 0, 0); ...the pillars are black as expected :) So an easy fix!

Cosmicore commented 1 month ago

Hi, @skruug !

At the moment I am working on making all the games from 'Manhattan Dealers' to 'Robinson's Requiem' playable.

What do you do specifically? Maybe there is some sort of pipeline with tasks? I've been working on the task of loading packed dat files into Robinson's Requiem this week, coded unmixword() function, etc. Doesn't that conflict with your tasks? I'd rather not do what you've already done but did not commit!

skruug commented 1 month ago

Nice, I'll fix it and commit it ASAP. BTW that audio fix should be easy as well, try to change 'float ratio = (48 * 200.0) / _audio_spec->freq;' Constant 48 should most likely be 44.1. Variable 'ratio' is used to modify some precalculated table lifted from Atari ST music player.

vanfanel commented 1 month ago

Nice, I'll fix it and commit it ASAP. BTW that audio fix should be easy as well, try to change 'float ratio = (48 * 200.0) / _audio_spec->freq;' Constant 48 should most likely be 44.1. Variable 'ratio' is used to modify some precalculated table lifted from Atari ST music player.

I tried that modification and it makes no difference. I also tried modifying the constant in mv1a.mumax = 1.0 * 48 / ratio; with no different results.

skruug commented 1 month ago

Hi, @Cosmicore!

we should try to coordinate. :-) At the moment I'm working on opcodes aim, avtstmov, atstmap and related code.

skruug commented 1 month ago

@vanfanel My bad, DOS version of Ishar 1 is using newer player. Have a look in music_v2 in function mv2_calculfrq()

vanfanel commented 1 month ago

@vanfanel My bad, DOS version of Ishar 1 is using newer player. Have a look in music_v2 in function mv2_calculfrq()

Ah, yes! In that file, changing this: float ratio = 50000.0f / _audio_spec->freq; into this: float ratio = 22050.0f / _audio_spec->freq; ...makes the music play correctly on both the DOS and AMIGA versions.

Still, intro SFX are too fast and high-pitched (in-game sounds seem correct, strangely).

I couldn't find other similar values there in that files to try to experiment with the FX solution.

skruug commented 1 month ago

@vanfanel what value is returned in your _audio_spec->freq ?

vanfanel commented 1 month ago

@vanfanel what value is returned in your _audio_spec->freq ?

It returns 44100 here, this is what I found via GDB:

Thread 1 "alis" hit Breakpoint 1, sys_init (pl=0x55555561f5c8 <platforms+8040>) at src/sys/sdl2/sys_sdl2.c:119
119         if (SDL_OpenAudio(desired_spec, _audio_spec) < 0 )
(gdb) n
[New Thread 0x7fffe34006c0 (LWP 8334)]
[New Thread 0x7fffe2a006c0 (LWP 8335)]
125         free(desired_spec);
(gdb) p _audio_spec 
$1 = (SDL_AudioSpec *) 0x55555876fb20
(gdb) p *_audio_spec 
$2 = {freq = 44100, format = 32784, channels = 2 '\002', silence = 0 '\000', samples = 882, padding = 0, size = 3528, 
  callback = 0x5555555799bb <sys_audio_callback>, userdata = 0x0}

I'm using plain ALSA on GNU/Linux (no PulseAudio, no Pipewire.. just plain direct ALSA).

Cosmicore commented 1 month ago

At the moment I'm working on opcodes aim, avtstmov, atstmap and related code.

Oh great, they're just in R's script! Then I'm good to go with the pw60/pb60 dat-files.

we should try to coordinate. :-)

Maybe some sort of Discord channel can be created for communication? Of course, sometimes there are questions. Anyway, I get what you're doing and will know you're doing it until there's a commit.

skruug commented 1 month ago

Interesting, it returns 44100 on my machines as well but playback speed is correct. :-( As a temporary fix, you can try to do similar change in sys_audio_callback() look for case eChannelTypeSample and var ratio.

vanfanel commented 1 month ago

sys_audio_callback

Yes, I see it here:

https://github.com/maestun/alis/blob/350ac89ce2a154991bf5a203ee12d091373d6d07/src/sys/sdl2/sys_sdl2.c#L618

However, I see ratio is derived from _audio_spec->freq which is 44100 for you and me.

skruug commented 1 month ago

@Cosmicore New ALIS discord chanel: https://discord.gg/ATdZw45U

skruug commented 1 month ago

@vanfanel I guess SDL returns incorect value, either on my or your system.

vanfanel commented 1 month ago

@skruug If I go to case eChannelTypeSample and change this: ratio = (float)(ch->freq) / (float)(_audio_spec->freq); to this: ratio = (float)(ch->freq) / (float)(_audio_spec->freq) / 2; ...then I get the right pitch for the SFX too.

Strange... and I lack the ability to explain it :P

skruug commented 1 month ago

Issue was caused by SDL setting audio differently than requested. IE. 2 channel stereo instead of single mono channel. Fixed in latest version using SDL builtin conversion.

vanfanel commented 1 month ago

Issue was caused by SDL setting audio differently than requested. IE. 2 channel stereo instead of single mono channel. Fixed in latest version using SDL builtin conversion.

I can confirm it's sounding perfectly now on my system (real, direct ALSA on GNU/Linux).