Sound and movie playback¶
Both were stubs until 15 November 2026: ZPS2Video reported end-of-file
immediately (cutscenes were skipped) and ZDllSoundSDL answered the synth
commands without producing audio. The port now decodes the game's own PS2
assets on the host.
Movies¶
The disc stores cutscenes as MOVIES/PAL/*.PSS (or NTSC): MPEG-2 program
streams whose video is in stream 0xE0 and whose audio is PCM in private
stream 0xBD. port/engine/rendervideo/_sdl/videosdl.cpp:
- resolves the level's movie name (
Movies/M00_Star) toMovies/PAL/M00_Star.pss, falling back to NTSC; - loads the whole stream through
g_pSysFileand demuxes it with FFmpeg (memoryAVIOContext), decoding MPEG-2 to RGBA. The scaler is made for each decoded frame's own size and pixel format (it used to take the codec context's format, which a frame need not share, and a scaler made for another layout reads past the planes it is given); - parses the audio itself: each private packet carries a four-byte
0xFFA00000header, the first one adds theSShd/SSbdchunk header with the sample rate, channel count and 0x200-byte stereo interleave, and the rest is 48 kHz stereo S16 PCM.SSbd's length field is the size of the whole sample stream, so only its eight-byte header is skipped: treating the value as a chunk length leaves the header in the PCM and shifts every interleave block, which plays as music with a static layer. The channels are stored as 512-byte blocks per channel (left, right, left, ...) and are reordered into sample interleaving. The whole stream is queued when the player opens, so a cutscene cannot underrun between game frames, and the device is resumed by the firstShowNextFrame, on the same tick the picture clock starts. The video stream is opened before the audio: a movie that cannot be shown (no FFmpeg, no decodable stream) is skipped without its sound. When the sound buffer cannot grow, the movie plays silent (a failed grow used to keep the old size with no buffer, and the queue then read from null), and after the reorder the size counts whole frames only; - paces frames by the stream's own presentation timestamps (PAL streams are 25 fps while the game flips at 60), so the movie lasts its real length;
- hands each frame to the renderer with
GpuMovieFrame;GpuEndFrameuploads it andCompositeblits it to the swapchain instead of the scene, with the same 4:3 pillarbox the game frame uses.
ZVideoPlayer::FrameUpdate calls ShowNextFrame every game frame and stops on
EndOfFile; m_bEOF is set only after the last frame's presentation time has
passed, so the level resumes after the cutscene.
make port-setup (and make port-windows-setup) builds a pinned FFmpeg
(port/port.json) from source as static libraries with only the parts the
player calls (FFMPEG_OPTIONS in tools/port/setup_port.py), and CMake finds it
before any FFmpeg installed on the system. The PSS streams carry no stream map,
so the program-stream demuxer identifies the video by probing it with the raw
mpegvideo demuxer, which therefore has to be built too. -D OB_WITH_FFMPEG=OFF
(tools/port/build_port.py) builds the old skip-everything stub, which logs that
the video was skipped.
PC movies¶
The PC (Steam) release has the same cutscenes as Bink files at 800 x 600
(the intro at 768 x 576) where the PS2 streams are 512 x 448. When the PC
version is played (the launcher's Version choice, pc_install in
obm.config.json; SettingsPcInstall), ZPS2Video::Init looks for the PC file first and plays the
PSS only when there is none or it cannot be decoded:
- the movie's name is the PSS path's file name without
.pss(Movies/PAL/M00_Star.pssgivesM00_Star); - it is looked up as
<name>.bikin<install>/Movies, then in<install>/Movies/M00_M02P(where the PC keeps M00_intr, M01_Inte, M01_Star and M02_Esca/Inte/Star), ignoring case. A name longer than eight characters is also tried cut to eight, because every PC file name is 8.3 (M00_Star.bik,Intro_bi.bik,gfxlogo.bik); - the picture goes through the same FFmpeg decoder and
GpuMovieFramepath as the PSS, at the file's own size;Compositepillarboxes it to 4:3 like the game frame; - the sound is decoded by a second demuxer on the same file (FFmpeg's Bink
audio decoders give planar float), interleaved to float and kept one second
ahead of the device on every
ShowNextFrame, instead of being queued whole as the PSS sound is. The device starts with the picture clock, as for the PSS, and getsAudio_Volume_Movie; - the log says
movie <pss>: PC movie <bik>, orno PC movie for "<name>"when an install is set but has no match.
Subtitles keep the PS2 timing, so a PC cut that differs in length from the PS2 stream would put them off.
Sound¶
The game writes synthesizer commands into a frame buffer and loads a per-scene
wave bank (.WAV) with a header table (.WHD). port/engine/audio/soundengine/_sdl/soundsdl.cpp
replaces the IOP synthesizer with a software mixer:
InstallWaves/InstallWaveHeadersload both files throughg_pSysFile;- the WHD is a table of 0x40-byte records. The packed
.SNDgraph stores the record's byte offset (SStartSoundBase::m_lHeaderOffset). A record gives the format, sample rate, compressed size, channels, data offset and sample count; - scene data is PS2 SPU ADPCM: 16-byte blocks with a shift/filter byte, a flag byte, then 28 4-bit samples (low nibble first). Each WHD offset points to the start of the entry in the WAV. Its compressed size includes a 16-byte silent lead block before the samples;
- bit 7 of WHD byte 0x0a selects a byte range of
PS2_Eng.str. The port reads that range on demand, the first 512 KB in the frame the sound starts and the rest 512 KB per game frame while it plays, so a long music track does not stall a frame; 16-bit entries are interleaved S16 PCM and 8-bit entries are G.711 mu-law. A voice entry starts with a 0x1000-byteLIPchunk (lip-sync data; its size field is the total for the line), and more 0x1000-byte LIP blocks follow at a fixed period counted from that chunk: every 13th or 17th block in the 8-bit lines, every 33rd in the 16-bit mono ones, every 173rd in the long stereo track. They are untagged, mostly zero bytes, and their table bytes played as audio are the glitch between sentences. The reader learns the period from the first block that is mostly zeros (and, in 16-bit data, holds a sample of magnitude 0x1000 or more; real near-silence stays below 40) and then drops only blocks at that period. Music and effect entries have noLIPchunk and are never filtered: 25 of M00's 16-bit tracks have blocks of silence followed by loud music that would pass the zero test. The record's size counts sample bytes only, so each dropped block extends the read by one block; reading just the record's size cut up to 1.3 s off the end of the longer lines. A simulation of the rule over every voice entry of M00, M01 and M06 recovers each record's full sample count with every dropped block on its period. Playing those mu-law bytes as linear PCM turns their silence (an alternating0xFF/0x7F) into a full-scale 8 kHz buzz, which is the static layer heard under dialogue; the banked 8-bit voice in M01 also uses this codec; - decoded waves are cached by header offset, at most 32 entries and 192 MB of PCM; only waves no voice is playing are evicted. Active voices are mixed into a 48 kHz stereo S16 SDL stream;
- Positional sources use the PS2 cone and distance calculations. The stereo angle uses the real listener position and orientation. Each occluding room exit reduces the source level by one third of the squared closure in synth volume units. Non-positional streams retain their native channel balance.
- An active voice keeps its playback cursor through parameter updates. A new one-shot requires the start flag. Loops can reacquire a voice when they come back into range. Start offsets are in 1/256 seconds at the source sample rate. When a stream starts, the mixer sends the pending and started replies together so the engine balances its two-second loading allowance. Banked effects play on their normal timers.
- A remove releases the voice's reference immediately and fades the sound over 128 output frames. A paused voice releases immediately. Each movie holds the gameplay mix from its first frame until completion or destruction.
The mixer runs on the game thread and queues up to 60 ms of audio. It sums voices in 32-bit accumulators at the requested volume, then saturates once when writing stereo S16. This removes the port's previous fixed 6 dB cut and lets overlapping samples of opposite signs cancel before clipping.
PC streams¶
When the launcher names a PC (Steam) install (pc_install) and pc_audio is
on (the default), speech, music and streamed ambience come from the install's
pc_eng.str instead of PS2_ENG.STR. The PS2 lines are 16 kHz mu-law and the
music 32 kHz; the PC has the same lines and tracks at up to 44.1 kHz.
port/engine/audio/soundengine/_sdl/pcstreamsdl.cpp:
- both files are IOI
IOISNDSTREAMversion 9 containers: a 0x28-byte header (magic, version, index offset, entry count, data start, 0, platform, 1) and 0x48-byte index entries (data offset, size, format record, name, a LIP flag at +0x38 and a LIP spacing at +0x3c). A format record is codec, total samples, channels, rate, bits and codec words. Names are source paths such asDialog/M08/Oneliners/.../M08_NR_01GW.wav; InstallStreamWavesreads the PS2 index throughg_pSysFileand the PC index from the host file, once per run. A WHD record's offset finds the PS2 entries that start there, the name of the one with the record's channels and rate finds the PC entry. Composite records share an offset with several names: a stereo track and its mono alternative, or a line and its radio version (...AssassinLeader.wavand...AssassinLeaderR.wav); the format check picks the track, and the line with lip-sync data wins over its radio copy. 3,384 of the 3,387 PS2 line and track entries have a PC entry; the threeCharacter/Expressions/Stripper/Stripper_0N.wavdo not;- the PC codecs are 2 (PCM16), 3 (Microsoft IMA ADPCM, mono, 0x400-byte blocks
of 2041 samples, decoded in the unit) and 4 (one complete Ogg Vorbis stream
per entry, decoded with FFmpeg through a custom
AVIOContextthat reads the entry's byte range ofpc_eng.str). Builds without FFmpeg leave the Vorbis entries (106, ambience and some music) to the PS2 data. Codec 17 entries (two-line pairs) are never chosen: only.wavnames are looked up; - the LIP blocks follow the index rule, not the PS2 reader's heuristic: with flag 4, block 0 of the entry is a 0x1000-byte LIP block and another follows after every spacing / 4 audio blocks; the size counts audio bytes only;
- a PC wave keeps the PS2 record's header offset and stream flag (so voice
routing and the start/stream replies are unchanged) and the PC rate and
channel count. It is decoded on the game thread, 96,000 frames (about two
seconds) in the frame it starts and as much per game frame after that,
2 to 7 ms of work per frame while an entry is being read. The lines' durations
agree with the PS2 records (2.84 s for
M06_DGCWG_01Guard, 160.6 s forM06_Salsa_Bomba), so timers and subtitles keep their timing; - PC streams raise the decoded-wave cache to 448 MB and accept up to 256 MB
per wave (
M02_Wonderousis 79.5 MB decoded), past the 64 MB record check of the PS2 path; - any miss or failure (no install, no entry, unreadable entry, no FFmpeg for
Vorbis) plays the PS2 data as before. The log says
pc audio: <file>, N entries; ...once andpc audio: N of M streams of <scene>.whd from pc_eng.strfor every scene (1,101 of 1,101 in M06, 1,303 of 1,303 in M00).
PC sound effects¶
With pc_sound_effects (and pc_install), the scene banks' short sounds
(footsteps, impacts, doors, weapons, the menu sounds) also come from the PC
install: a banked PS2 wave whose PC counterpart is known is decoded from the
PC scene's .WAV (IMA ADPCM or PCM, up to 44.1 kHz) instead of the disc's
SPU ADPCM (at most 22.05 kHz). The PS2 bank keeps no names, so
pcdata/pcsoundmap.cpp pairs the two scenes' Wave tables by order, group
byte and duration, and pceffectssdl.cpp checks the pairs made by position
by their loudness envelope and gives the engine the PC length of the weapon
shots the PS2 cut short. 10,944 of the 11,273 banked PS2 records of the 68
scenes get a PC wave. pc-assets.md has the
measurements, the pairing and how it was verified. The log says
pc effects: N of M banked waves of <scene>.whd from <PC .WAV> (...) for
every scene, and with OPENBLOOD_SOUND_LOG=1
sound: wave <offset> from the PC bank: <name> (...) for each wave.
PC scene data¶
When the port runs from a PC installation, the scenes' own .SND, .WHD and .WAV are the PC's, and so is the stream file, pc_Eng.str. The engine reads the PC .SND unchanged. The mixer decodes banked PC waves (IMA ADPCM, format tag 0x11, or PCM) and plays every streamed record from the pc_eng.str entry at the record's offset. The installed stream file's header and each record's format tag pick the decoder. docs/internals/formats/snd.md, "PC version", has the layouts and the measurements. The log says pc audio: <file> is the PC stream container (...) once, and pc audio: N of M streamed waves of <scene>.WHD playable from the PC stream file for every scene.
Room reverb¶
The PS2 game has no reverb: SYNTHCD.IRX leaves the SPU2 effect volume at
zero. The PC gives every room an EAX 3 listener environment. With reverb=room
the mixer runs an algorithmic reverb with those settings
(reverbsdl.cpp, roomeffectsdl.cpp):
- the settings are the RoomEffect objects (type 7) of the PC scene's
.SND, read from the PC scene zip while the scene loads (Scenes/M06/M06_main.ZIP; an eight-character PS2 name such asM00_ALBImatches the PC'sM00_albino). The 22 words from object +0x18 are environment, size, diffusion, room, room HF, room LF, decay time, HF and LF decay ratios, reflections, reflections delay, reverb, reverb delay, echo time and depth, modulation time and depth, air absorption, HF and LF reference, room rolloff and flags. Each object's resource name is the string just before it (audio:roomeffects/m00/m00_loc_ins_centrebuilding/m00_poker_room_01#roomeffect); the last part is the PS2 ZROOM's name; - the table has about one entry per room with an audio environment (a ZROOM
with a RoomRef; on the PS2 every RoomRef points to one stub object, so it
cannot tell the rooms apart), in descending
m_lSoundGraphIdorder. Rooms that share an effect point to one object, named after the first of them. In M01 25 entries hold 12 named objects for 25 rooms, and each of the 12 named rooms sits on its name's first entry in that order. The named rooms are anchors, and the rooms between two anchors take the entries between them when there are as many of each; a gap whose counts differ is left to the default. Rooms with an audio environment but no PC settings get a default room (7.5 m, 0.8 s, about the PC's median indoor values); outdoor sections and the root are dry. The rooms are found by walking the exits from the root and from the listener's room into a table of 1,024; the listener's room used to be added without a bound check when the root's walk had filled it. The log givesreverb: N rooms: K with PC room effects (A by name, B by table order; ...)per scene. Rooms with an environment that get PC settings: M00 24 of 24, M01 25/25 (12 by name, 13 by order), M02 55/55, M03 53/53, M04 62/62, M05 40/40, M06 74/74, M08 57/61, M09 63/63, M10 128/129, M11 41/41, M12 32/49, hideout 3/3; M13 has no RoomEffects on the PC; - every frame the listener's room sets the target. Within 200 units of an
open exit the room beyond is blended in with
ZSoundGraph::GetEnvMorph's curve (half each in the exit), and every parameter glides to its target over about 150 ms. The levels and delay times ramp sample by sample, and the delays move by at most 0.2 samples per sample: stepping them once per 32-frame block tore the wet signal (a sine through a room switch showed steps four times its own slope; now within about 10 % of it); - only positional sources (
Base,LocationSoundsbuffers) feed the wet bus, with their panned, distance-attenuated gains; music, the direct streams and the 2D sounds stay dry. The wet bus is low-passed by Room HF, tapped for eight early reflections (spread by the room size, after the reflections delay) and, after the reverb delay and four allpass diffusers, feeds an eight-line Hadamard feedback delay network (23 to 50 ms lines) whose lines lose 60 dB per decay time, with a one-pole low-pass per line for the HF decay ratio at the HF reference. Room, Reflections and Reverb set the levels; echo, modulation (zero depth in the PC data), the LF settings, air absorption and room rolloff are not modelled. The result is added to the 32-bit mix before the clamp; - the reverb is reset by scene loads,
MuteAllWavesand movies, and goes idle (no wet bus, no processing) once a dry room's tail has faded. Withreverb=offit never runs and the mix is the PS2 one.
The European disc's SYNTHCD.IRX checks the WHD stream flag at 0x2a78,
tests start and loop flags for missing voices at 0x2ba0, and handles removal
at 0x2d80. Its occlusion calculation starts at 0x89c8 and its direct stereo
stream gain at 0x8cec. These offsets are relative to the module's text.
When the engine renders its sound frame twice in one game frame (scene
transitions), ZDllSoundSDL::BuildFrame builds the second one without source
commands but still sends its removes and ends it with the end marker.
Debugging¶
OPENBLOOD_SOUND_DUMP=<path>writes the mixed game audio (reverb included) as raw S16LE 48 kHz stereo for ten seconds, orOPENBLOOD_SOUND_DUMP_SECONDS=<seconds>, once per run;OPENBLOOD_SOUND_DUMP_DELAY=<seconds>starts the dump later (useful to skip the intro movie). It used to reopen, and so truncate, the file after each period, leaving only the last partial one.OPENBLOOD_SOUND_LOG=1logs every wave the mixer decodes (offset, source bank or stream, flags, rate, bits, channels, size, first bytes), every voice it starts (ref, wave, step, volume, pan), each PC stream it uses (wave <offset> from pc_eng.str: <name> (codec, rate, channels, frames)) and any PC decode step over 2 ms, every room's reverb source (reverb: room <name> (graph <id>, inside): PC | PC, by table order | default | dry) and each room the listener enters.OPENBLOOD_WAVE_DUMP_DIR=<dir>writes each decoded wave as a WAV, which is how the mu-law and interleave bugs were found.OPENBLOOD_MOVIE_DUMP=<path>writes a cutscene's decoded PCM as a WAV.- Any movie logs
movie <path>: <bytes>,movie audio: <rate> Hz, <channels> channelsonce when it opens. - A missing FFmpeg build logs
movie ...: built without FFmpeg, video skipped.
Known limits¶
-
Host playback uses stereo panning and linear sample interpolation. The SPU2 surround phase matrix, hardware interpolation and DSP effects can still sound different on a console. Peak level and loudness have been measured from the host mix only.
-
PS2 WHD records tagged Ogg Vorbis (
formatTag 0x1000) are not decoded; the PS2 disc's streams are PCM and mu-law. The PC's Vorbis and IMA ADPCM entries are decoded bypcstreamsdl.cpp(Vorbis needs FFmpeg). - The PS2 path still finds its LIP blocks by the heuristic above; the index rule the PC path uses would also fit the PS2 entries, but the PS2 path is kept as it was.
- The reverb is an approximation of EAX 3, not Creative's algorithm; the per-source distance rolloff of the reverb send and the air absorption are not modelled.
- Banked effects come from the PC only with
pc_sound_effects, and only where the pairing finds and accepts a PC wave (pc-assets.md). - Movie audio is played by the movie player, not by the game's sound DLL. The
player applies
Audio_Volume_Moviewhen it opens, the option the original constructor reads forSetFmvVolume;ZDllSoundSDL::SetFmvVolumeonly keeps the engine's copy of the value.
During FMV playback the subtitle camera draws into the game picture, while the presenter displays the movie texture. Subtitles drawn only to the game picture are therefore absent from the displayed movie.