swars icon indicating copy to clipboard operation
swars copied to clipboard

Tension music does not play

Open geist22 opened this issue 2 years ago • 2 comments

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

geist22 avatar Jun 13 '22 16:06 geist22

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 avatar Sep 11 '22 09:09 mefistotelis

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 avatar Sep 16 '22 00:09 mefistotelis

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 avatar Jul 11 '23 01:07 mefistotelis

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 avatar Jul 13 '23 17:07 mefistotelis

Status update: (2) is done.

mefistotelis avatar Jul 16 '23 20:07 mefistotelis

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

4b. Include selected PAT instruments in SW conf

mefistotelis avatar Jul 17 '23 10:07 mefistotelis

Done with 4 and 4b.

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

mefistotelis avatar Jul 18 '23 00:07 mefistotelis

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.

mefistotelis avatar Jul 18 '23 12:07 mefistotelis