Commit Graph
597 Commits
Author SHA1 Message Date
Filippos Karapetis 16fab2d480 SCI32: Ignore invalid kernel call when toggling the music in Hoyle 5 2018-08-21 03:36:07 +03:00
Eugene Sandulenko 22b674777f SCI: Added overried specifiers 2018-03-28 12:35:22 +02:00
Willem Jan Palenstijn 3a933138ce SCI: Avoid buffer overflow in amigamac sound driver
By default, frac_t is interpreted as signed. The resulting range isn't
large enough to store offsets, so we interpret it as unsigned here
instead. Fixes a crash in QfG1/Mac where instrument->loop_size is 49457.
2017-12-03 12:49:11 +01:00
Colin Snover e6228f3ff6 SCI32: Fix integer overflow calculating audio duration
Due to the need to calculate the audio duration with millisecond
precision from the file size, it is possible to overflow a 32-bit
integer in games with long background audio loops, like RAMA,
during the calculation of the duration.

It is also not necessary to give some framerate here, so eliminate
the unnecessary explicit Timestamp construction with the second
argument.
2017-11-11 20:18:17 -06:00
Colin Snover d53e778739 SCI32: Rewrap comments to 80 columns in SOL decoder 2017-10-06 22:56:26 -05:00
Colin Snover 42180527c4 SCI32: Fix music volume not being restored after speech in Torin
This was a regression introduced by
d556dcc57b.
2017-10-06 22:11:02 -05:00
Colin Snover 93c8044f69 SCI32: Clean up Audio32
* Rewrap comments to 80 columns
* Remove resolved TODOs
* Use containers and smart pointers where appropriate
2017-10-06 22:10:52 -05:00
Ruud Klaver 6843870af2 SCI: Set default MT-32 reverb before each sound
Set the default reverb configuration present in either the MT-32
patch data or MT32.DRV of SCI0 games before playing each sound, as
a previously played sound may have changed it.

Also, do not perform a general reverb init, since the start of a
sound will do that now.

Closes gh-1023.
2017-10-04 23:47:21 -05:00
Ruud Klaver cedd9d3c40 SCI: Play MIDI version of SCI0 sound resource if user prefers it
If the user has "Prefer digital sound effects" disabled for a SCI0
game, do not play the digital sample version of a sound resource, if
such data is present. When the resource has only digital sample data
and no MIDI information, play the sample instead.

Closes gh-1022.
2017-10-04 23:29:38 -05:00
Colin Snover 7feccaaa98 SCI32: Implement SCI3-variant volume handling
Trying to find differences in Lighthouse's audio sample playback,
I discovered that SCI3 had its own variant of handling volumes and
sending this volume information back to game scripts. It is not
known if this fixes any sound bug.
2017-09-27 20:27:33 -05:00
Colin Snover 21337e4cf6 SCI32: Implement per-channel audio panning
Used by RAMA, in various places, starting with the refrigerator
at base camp after the cable car at the beginning of the game.
2017-09-24 22:56:57 -05:00
Martin Kiewitz d9dfca2fcb SCI: SQ4: Now using additional and enhanced Win3.11 samples
Which were originally only played, when using the Windows interpreter.
Afaik the DOS interpreter was incapable of playing more than 1
sample at a time, which was probably the reason why Sierra only
added these for the Windows interpreter.

For example a sample is now played, when points are awarded.

Those samples are currently used all the time and will also
enhance the game, when platform DOS is chosen.
In case someone wishes to opt-out of this, we could add a game
specific option.

We do something like this for Space Quest 3 already,
that's why I don't see a reason to add a game option right now.
2017-09-25 00:44:04 +02:00
Colin Snover 836f1bdf44 SCI32: Add audio dump debugger command 2017-09-19 19:54:29 -05:00
Colin Snover 9ac219648e SCI: Omit SysEx delays when sending to MT-32 emulator
Real MIDI devices, and MT-32 in particular, need delays between
SysEx messages to ensure sufficient time to receive and process
the incoming data buffer. Sending too much data too quickly to
these devices can cause them to crash with a buffer overflow.

The MT-32 emulator, on the other hand, has no problem receiving
SysEx data instantly, so skipping the delays means that games that
send lots of data to the MT-32 will start up much faster.
2017-09-12 20:08:02 -05:00
Colin Snover 200c8c442b SCI: Remove dead code 2017-09-10 22:17:17 -05:00
Colin Snover e0aa906804 SCI32: Fix bad audio looping
Fixes Trac#10182.
2017-09-10 02:08:22 -05:00
Colin Snover e137d01967 SCI32: Fix Phant2 movie-vs-game playback volumes
This update should give the game the default mix it receives in
Windows. If necessary, the half-volume audio bug in the DOS
interpreter can be added as an additional hack for this game, since
there are still some sub-par audio mixes that might need additional
correction (like Curtis talking to Blob when taking her out of the
cage in his apartment at the start of the game) which were also
bad in the Windows version of the game.

Fixes Trac#10165.
2017-09-09 23:29:57 -05:00
Colin Snover 74738489ec SCI32: Fix SFX volume being misapplied to music & speech in some games
This was happening in games with game scripts that control the
master volume themselves by applying the master volume to each
channel sent to the kernel, instead of relying on the kernel to
manage the master volume for them.
2017-08-26 18:09:46 -05:00
Colin Snover caa8293fce SCI32: Make sure audio is not paused from the future
This can occur when a save game from the past is loaded and the
audio system was paused prior to loading the save game. This was
fixed eventually in SSCI somewhere around GK2, since it pauses
all audio before restoring a game and then resumes it after the
save game is loaded (after all of the audio channels have been
added from the save game). Since this would seem to be a problem
for earlier games as well, this change is applied universally
instead of being conditionally applied only to the games with
interpreters containing this change.

This patch contains some additional sanity checks that emit
warnings if individual channels end up being started from the
future. There was never such checking in SSCI, and it does not
seem likely to ever happen, but it is unclear right now if this is
an actual problem or not.
2017-07-30 19:22:35 -05:00
Colin Snover 2005ed79d6 SCI32: Emit a warning when an audio resource cannot be found
Refs Trac#9976.
2017-07-23 16:01:19 -05:00
Colin Snover dcb6c32215 SCI32: Destroy audio streams in Audio32 using DisposeAfterUse flag
Since Resource::makeStream returns a MemoryReadStream which will
not attempt to free the resource memory, it is fine to always
dispose those streams and get rid of the separate resourceStream
property, which was a holdover from some past WIP resource design
which no longer exists.
2017-07-17 23:56:21 -05:00
Colin Snover 64d090dcb8 SCI32: Fix stream leaks in Audio32/SOLStream
makeSOLStream was leaking the SeekableSubReadStream object it
creates itself if it was not called with DisposeAfterUse::YES. That
substream is an implementation detail which should not rely on
the caller to be destroyed.
2017-07-17 23:56:21 -05:00
Colin Snover 2528ecf26e SCI32: Fix playback of looped audio
This fixes at least Lighthouse audio 808 in room 270, and audio
801 in room 810.
2017-07-17 22:42:18 -05:00
Colin Snover 07d6ffd989 SCI32: Force General MIDI for games that support nothing else
* MGDX has only GM music;
* KQ7 1.x's AdLib data is incomplete, so is not usable even though
  it is partially there

Fixes Trac#9789.
2017-07-07 13:28:54 -05:00
Colin Snover 90cd56e4b6 SCI32: Fix missing music in MGDX
GM patch data is the same across all SCI32 games.
2017-07-07 13:25:02 -05:00
Colin Snover f3c452c31e SCI32: Forward OLDDPCM8 parameter instead of using an if-else
Thanks @OmerMor for pointing out this improvement.
2017-06-18 21:42:59 -05:00
Colin Snover 87895b97f7 SCI: Fix looping of sounds that are not initialized yet
This fixes at least the character selection screen in QFG4CD,
where the sound for the torches is supposed to loop, but wasn't
because kDoSoundSetLoop would bail out before setting the loop
property on the soundObj.
2017-06-18 21:42:58 -05:00
Colin Snover d556dcc57b SCI: Switch SCI2 games to use Audio32
Upon investigation of Sound code across SCI32 games, it was
determined that there are actually (at least) 3 different
revisions, not just a single SCI2.1 version. This patch only
changes the parts of Sound code that are relevant to the correct
use of Audio32.

Fixes Trac#9736, Trac#9756, Trac#9767, Trac#9791.
2017-06-18 21:42:58 -05:00
Colin Snover 733eaeb499 SCI32: Minor tweaks to improve code clarity & consistency 2017-06-18 21:42:58 -05:00
Colin Snover dc9522eae0 SCI32: Fix Audio32 mix volumes
The previous code for attenuating audio channels was not accurate,
so samples were quieter than they were supposed to be when mixed
together. Robots were also being mixed without attenuation, which
was incorrect.
2017-06-18 21:41:48 -05:00
Colin Snover 12afcaec49 SCI32: Support old-format 8-bit DPCM coding for SCI2 2017-06-17 13:09:27 -05:00
Colin Snover e69507cc28 SCI32: Implement engine-accurate DPCM overflow behaviour
DPCM decompression algorithms in SSCI operate directly on 8- and
16-bit registers, so any sample that ends up being out-of-range
during decompression gets wrapped by the CPU, not clipped.

This does not fix any known problem with AUD files, but there are
some VMDs (e.g. GK2 5280.VMD) which are known to contain OOR
samples. Making this code more accurate should prevent trouble
with any other similar files.
2017-06-17 13:09:27 -05:00
Colin Snover 40566820a7 SCI: Return the original master sound volume when mute is on 2017-06-09 23:30:10 -05:00
Colin Snover 85e35943fe SCI32: Implement kLock & kDoAudio(1) for SCI32
1. Unlocking all resources of a type using a resource ID of -1 is
   gone in SCI32;
2. Audio locks need to be serialized starting in GK2 for the game's
   modified kDoAudio(1) call;
3. Audio locks in SCI3 must work more like SSCI, since at least
   Lighthouse's `BackMusic::fade` method will attempt to unlock
   audio that was never locked by a script. In SSCI (and now in
   ScummVM too) this is a no-op; previously in ScummVM, it would
   remove Audio32's own lock on the audio resource, resulting in a
   use-after-free;
4. kDoAudio(1) starting in GK2 returns the number of active
   *not-in-memory* channels being played, not the total number of
   active channels.

Fixes Trac#9675.
2017-06-09 23:00:14 -05:00
Colin Snover 095226a614 SCI: Lock Audio resource types when digital SFX is enabled
This seems to have been added in SCI1.1 and continued through
SCI32; older games with digital SFX (like KQ5CD) did not convert
the resource type in kLock.

This is not known to fix any problem, but was a noted difference
in the implementation between ScummVM and SSCI.
2017-06-09 22:48:15 -05:00
Colin Snover a2ead7c4a4 SCI32: Fix include path 2017-06-09 22:48:14 -05:00
Colin Snover 67b72cc5a8 SCI: Remove unused Robot code from SCI16 audio code 2017-05-10 10:55:00 -05:00
Colin Snover 8bdfb78895 SCI32: Add debugger command to list digital audio samples 2017-04-23 13:07:25 -05:00
Colin Snover eb9965274d SCI32: Fix race conditions in Audio32 2017-04-23 13:07:25 -05:00
Colin Snover a867fb70dd SCI32: Fix audio playback with monitored channel in SCI3
SCI3 changes the way that monitored channel works. In SCI2/2.1,
when a channel is monitored, it is the only audible channel. In
SCI3, monitored channels mix normally.

This is very noticeable in LSL7, where music disappears totally
during speech if the monitored channel is the only channel played
back.
2017-04-23 13:07:25 -05:00
Colin Snover 10a4e5d591 SCI32: Fix missing break statement 2017-04-23 13:07:25 -05:00
Colin Snover 3303a88139 SCI: Improve audio volume & settings sync code
This patch includes enhancements to the ScummVM integration with
SCI engine, with particular focus on SCI32 support.

1. Fixes audio volumes syncing erroneously to ScummVM in games
   that modify the audio volume without user action (e.g. SCI1.1
   talkies that reduce music volume during speech playback). Now,
   volumes will only be synchronised when the user interacts with
   the game's audio settings. This mechanism works by looking for
   a known volume control object in the stack, and only syncing
   when the control object is present. (Ports and planes were
   researched and found unreliable.)

2. Fixes audio syncing in SCI32 games that do not set game
   volumes through kDoSoundMasterVolume/kDoAudioVolume, like GK1,
   GK2, Phant1, and Torin.

3. Fixes speech/subtitles syncing in SCI32 games that do not use
   global 90, like LSL6hires.

4. Fixes in-game volume controls in SCI32 games reflecting
   outdated audio volumes when a change is made during the game
   from the ScummVM launcher.

5. Fixes SCI32 games that would restore volumes from save games
   or reset volumes on startup, which caused game volumes to be
   out-of-sync with ScummVM when started.

6. ScummVM integration code for audio sync has been abstracted
   into a new GuestAdditions class. This keeps the ScummVM-
   specific code all in one place, with only small hooks into the
   engine code. ScummVM integrated save/load code should probably
   also go here in the future.

Fixes Trac#9700.
2017-04-21 19:00:27 -05:00
Colin Snover 4946f149b4 SCI: Improve MidiParser_SCI robustness against bad sound resources
1. KQ4 sound 104 has an extra 0xFC (MIDI Stop command/kEndOfTrack)
   at the end of the resource, which causes an out-of-bounds read
   because the filtering loop continues after the first 0xFC and
   unconditionally attempts to read 2 bytes (expecting there to
   always be a delta value + a command, whereas in this file there
   is only another kEndOfTrack command). This is corrected by
   exiting the filtering loop when a kEndOfTrack is encountered
   and there is not enough data remaining in the resource to
   continue reading.

2. KQ5 sound 699 is truncated, which causes the parser to attempt
   to read past the end of the resource. This is addressed by
   adding bounds checks that exit the mix loop early if there is
   no more data available to read. This allows truncated sounds
   to be played as far as possible (previously, trying to read
   truncated resources would result in a fatal error).

3. midiMixChannels allocates an arbitrary amount of raw memory
   for the mixed MIDI sequence, without performing any bounds
   checking when writing to this memory, potentially leading to
   a crash or silent corruption of adjacent memory. This is
   mitigated by using SciSpan instead of a raw pointer for the
   mixed data.

Fixes Trac#9727.
2017-04-16 12:23:35 -05:00
Thierry Crozat 1e38ca45cd SCI: Fix speech in QfG IV on big endian platforms 2017-04-14 00:01:54 +01:00
Colin Snover 5723f2f5fe SCI32: Hack around MIDI parser causing stuck harp animation in KQ7
The eventual proper fix for this is to change the current MIDI
parser to work the same as in SSCI, but for now this workaround
allows the game to continue.

Fixes Trac#9696.
2017-03-30 20:49:36 -05:00
Colin Snover 3de6f290e7 SCI: Change default master MIDI volume to 15
GK1 handles MIDI volume by changing the volumes of individual
sound objects, rather than by using the MIDI master volume. As a
result, the master volume needs to default to the maximum output
level in order for GK1 to play music at the correct volume.

This change does not affect earlier games, since SCI16 managed
MIDI volume via the master volume, and for these games the master
volume from ScummVM is synced at startup.
2017-03-30 19:46:27 -05:00
Colin Snover 4d062fc7a0 SCI32: Do not default to General MIDI for SCI2.1 games
The only SCI32 game that uses MIDI and does not support AdLib is
MGDX, and it its MIDI playback is currently broken regardless of
the synth setting.
2017-03-30 19:46:27 -05:00
Colin Snover 0826501ef6 SCI32: Fix audio, wave, VMD, Duck, CLUT, TGA, ZZZ, Etc patches
Specifically, audio patches are used in at least PQ:SWAT
(40103.AUD), Lighthouse (9103.AUD), and the GK2 demo (300.AUD).
2017-03-30 19:46:27 -05:00
Colin Snover 766d46153a SCI32: Implement known-used portions of kPlayDuck 2017-03-30 19:46:27 -05:00
Colin Snover a233696212 SCI: Update formatting strings to match updated Span API 2017-03-30 14:23:41 -05:00