swfans / swars

Syndicate Wars port, alternative binary for the classic Bullfrog game
Other
81 stars 13 forks source link

Tension music does not play #22

Closed geist22 closed 1 year ago

geist22 commented 2 years ago

As far as I know, this is a known issue with the port and has always been the case, since the vexillium version.

mefistotelis commented 1 year ago

This needs investigating - MIDI playback is not functional in the port. Maybe there's a working MIDI playback in Magic Carpet HD? Then similar solution could be used for SW Port.

This would be easier if we had sound library separated from the rest: https://github.com/mefistotelis/swars/issues/20

mefistotelis commented 1 year ago

The playback from Magic Carpet is based on SDL_mixer; SW Port uses OpenAL. But it looks like playing XMI files using OpenAL is an issue which was also solved already. One interesting discussion is here: https://github.com/Interrupt/systemshock/issues/14

mefistotelis commented 1 year ago

Examples for converting XMI to MIDI and playing via SDL_Mixer:

https://github.com/turican0/remc2/blob/development/remc2/engine/AIL_stub.cpp#L6141 https://github.com/TinyRetroWarehouse/SR/blob/59d0b5311498b7254dd0d61871cf3edf402a7aa9/games/Warcraft/SR-War/Warcraft-music-midiplugin2.c#L205 https://github.com/TinyRetroWarehouse/SR/blob/master/games/Albion/SR-Main/Albion-music-midiplugin.c#L889

Example of synthesizing XMI via AdlMIDI and playing via SDL_Mixer: https://github.com/Interrupt/systemshock/compare/master...adlmidi-xmi

Example of synthesizing XMI via WildMIDI and using OpenAL: https://github.com/afritz1/OpenTESArena/blob/458a284844883496d64e163708a5197e71c733ee/OpenTESArena/src/Media/AudioManager.cpp#L123

Here is a project with support of a lot different ways of synthesizing, either on OS driver or by software; if by software, it uses SDL to play: https://github.com/exult/exult/blob/master/audio/midi_drivers/XMidiFile.h

mefistotelis commented 1 year ago

The plan:

  1. Rewrite all AIL API functions related to playing MIDIs
  2. Prepare OpenAL part of the playback (sound sources, buffers, etc), play a generated tone or sample as a test
  3. Add MIDI software synth library to build system (WildMIDI or AdlMIDI)
  4. Implement directing MIDI data buffers to SW synth lib, and sending output to OpenAL
  5. Fix volume, tempo and general state control for the MIDI sequences

Current status: (1) is done.

mefistotelis commented 1 year ago

Status update: (2) is done.

mefistotelis commented 1 year ago

(3) is done. Though WildMIDI requires external music samples to work, which adds another point:

4b. Include selected PAT instruments in SW conf

mefistotelis commented 1 year ago

Done with 4 and 4b.

The track doesn't loop though, so stops after one play.

mefistotelis commented 1 year ago

The track now loops, volume changes properly.

The original code provided some variation to the danger music by enabling various effects, changing tempo and pitch based on some playback parameters. But these were barely audible anyway, so not going to implement that as part of this issue.

Also more / better matching instruments could be added, but that doesn't require programming, just messing with midipats.cfg.

So, all done.