Commit Graph
118 Commits
Author SHA1 Message Date
Scott Percival 12cf67948d DIRECTOR: Allow multiple concurrent sound fades
Fixes collecting the orange heart in The Seven Colors.
2024-03-31 16:58:31 +02:00
Scott Percival 637caad1c3 DIRECTOR: Fix setting "the volume of sound"
Previously, volume changes would only be picked up by the next sound
started in the channel (if at all).

Fixes the hint music clashing in the fortune teller floor of the
department store and Club Exclaim in The Seven Colors.
2024-03-31 16:58:31 +02:00
Scott Percival 95ca062e6d DIRECTOR: Always disable puppet sounds on movie change
Previously the puppetSound flag condition would only be disabled if the
sound was playing at the time of the movie switch.

Fixes music when entering the cat room straight from the start room
in The Seven Colors.
2024-03-31 16:58:31 +02:00
Scott Percival 5df3b7b8cd DIRECTOR: Playing a sound after a fade should restore the volume
Fixes stacked volume changes between scenes in The Seven Colors; e.g.
going straight from the start room to the cat room.
2024-03-31 16:58:31 +02:00
threefins 0e6c4f3773 DIRECTOR: Correct for invalid loop bounds in D4
In some D4 version 400 (file version 0x45B) files, sound resource loop bounds are
invalid but their cast member flags are set to loop. Examples are
"Barbie and her Magical Dreamhouse" and "Necrobius" (Windows demo).
Invalid is any situation where the following does not hold:
`loop_start < loop_end <= size`

In the original environment, these resources are handled by disabling
the looping flag and resetting the loop bounds on the sound resources to
0 -> sample size.

This commit checks for invalid loop bounds and applies roughly the same
fix. This fixes the invalid sound looping behaviours present in the
aforementioned titles.
2024-02-27 17:16:15 +01:00
Scott Percival 67562eaded DIRECTOR: Prevent repeats in DirectorSound::playExternalSound
This should give the same behaviour as DirectorSound::playCastMember.

Fixes sounds playing twice if the animation takes too long in Spaceship
Warlock (e.g. the hovertaxi landing in the demo).
2024-02-09 21:17:57 +08:00
sluicebox ae2dad1112 DIRECTOR: Fix memory leaks. PVS-Studio V773 2023-12-05 09:24:31 -08:00
Eugene Sandulenko 8bccc12786 DIRECTOR: Reduce header dependency 2023-08-02 21:05:06 +02:00
elasota 9e92db3718 DIRECTOR: Fix signed/unsigned mismatch 2023-07-08 22:02:00 +03:00
Scott Percival 70ffd87c62 DIRECTOR: Add guardrails to loadSampleSounds 2023-07-08 22:01:00 +03:00
Scott Percival 2690a238ce DIRECTOR: Add extensions if required when loading audio files
Fixes several sound effects in Hamsterland: The Time Machine.
2023-07-08 22:01:00 +03:00
Scott Percival 17e1853347 DIRECTOR: Refactor path detection
Previously, paths were verified by pathMakeRelative().
This method had several drawbacks; the code was increasingly ad-hoc
and recursive, and the function would return a Common::String that
was not guaranteed to be distinct. 90% of the time the path would need
to be converted to Common::Path so that file streams could use it.

This code has been replaced with findPath(), a function which takes a
path string as recieved from Director (e.g. a Lingo script, a filename
stored in a CastInfo record) and returns a Common::Path object for the
file on the local system. The inner workings have been split into subfunctions,
which should make it easier to add workarounds and fuzz at the correct
layer.
2023-07-08 22:01:00 +03:00
Eugene Sandulenko 9aa0958736 DIRECTOR: Properly keep track of open resource files and their precedence
We used to close resources when we were closing movies, but with making
Archives owned by Director class, we now have list of all _seen_ resources.

This change implements a proper, ordered list of resources which are
overriding the ones loaded earlier.

Fixes cursors in the7colors which were read from previously loaded Shared Casts.
--start-movie=04CLUB:FloorColidor:IntoFloo
2023-06-30 00:32:57 +02:00
Eugene Sandulenko 95d8cf840c DIRECTOR: _allOpenResFiles -> _allSeenResFiles 2023-06-29 23:22:54 +02:00
Eugene Sandulenko a62b7985b5 DIRECTOR: Modernized some loops 2023-06-29 17:35:06 +02:00
Eugene Sandulenko 69a372672e DIRECTOR: Properly set volume on starting sound. Store sound volume defaults. 2023-06-06 19:43:32 +02:00
Eugene Sandulenko aacb0cac11 Revert "DIRECTOR: Report inactive channel volume as 0"
This reverts commit 72d890b751.

This brought a regression of turning sound in many games.

It breaks again the7colors when exiting the car:

  --start-movie=03CAR:xn--Car.IO-ma28a:CarOutSideView03
2023-06-05 20:05:34 +02:00
Eugene Sandulenko ed56d9c317 DIRECTOR: Sync channel volume during fades 2023-06-01 22:08:36 +02:00
Eugene Sandulenko 72d890b751 DIRECTOR: Report inactive channel volume as 0 2023-06-01 21:58:21 +02:00
Scott Percival e0c7bec488 DIRECTOR: Fade sounds if the channel handle exists
isChannelActive() excludes looping sounds, which are allowed to
be faded in or out.

Fixes the intro music fading in The Cute machine.
2023-05-10 22:32:21 +02:00
Scott Percival 401a17d35a DIRECTOR: Add dynamic sound channel allocation
By D5, titles are allowed to play back sounds on an arbitrary channel
and the mixer deals with it. This apparently works to an extent on Mac
for D4 and below, whereas Windows D4 has a hard limit of 4 channels.

As the clear intent is to play something, we should do that for all
versions, unless a counterexample shows up.

Used by Smarty.
2023-05-10 22:32:21 +02:00
Scott Percival 5c82519e35 DIRECTOR: Add D5 support for sound cast members 2023-05-10 09:48:50 +02:00
Scott Percival f703ee6ecf DIRECTOR: Split CastMember classes into files 2023-04-29 14:20:05 +02:00
Misty De Meo 3d65d22964 DIRECTOR: Sound: handle _loopEnd==_loopStart 2023-04-02 12:41:54 -07:00
Scott Percival 0a6f33ca97 DIRECTOR: Ignore SND loop bounds if end is before start
Fixes visiting Mount Olympus in Wrath of the Gods.
2023-03-06 21:26:28 +01:00
Misty De Meo 0fd0301266 DIRECTOR: D3 keeps looping sounds 2023-02-12 00:53:05 +01:00
Misty De Meo b7b34117da DIRECTOR: sound loops can begin on 0
The logic to determine if a sound is loopable or not didn't consder that
a sound could loop from the beginning. A short song in The Seven Colors
begins at sample 0 and ends at 6456, which was considered non-looping
before this.
2023-02-12 00:53:05 +01:00
Eugene Sandulenko e657e060e0 DIRECTOR: Fix potential race condition
If sound is ended during execution, we may refer to the freed memory
2022-12-09 01:26:32 +01:00
Eugene Sandulenko 7e69d548d7 DIRECTOR: Consider looped sounds not playing after first iteration
Fixed exit door in the7colors, where the frame had a looping
birds chirping sound together with the following Lingo:

  if the soundbusy of 2 then go to the frame

And that led to an infinite loop and inability to pass through the
opened door.

The original apparently is returning 0 in-between the sound loops
since it manually restarts the sound after its completion. We, in
contrast, are optimizing that and using LoopedAudioStream
since f48dbb43b6
2022-12-08 23:14:54 +01:00
Eugene Sandulenko 3703fee378 DIRECTOR: Do not reset looping handle early
playStream() is called right after setting loopPtr, which was leading
to immediate reset of loopPtr. Thus, we were not able to control
the looping sounds
2022-12-08 23:14:54 +01:00
Vladimir Serbinenko 0670d1a16a DIRECTOR: Switch to openFileOrDataFork 2022-12-04 20:16:21 +01:00
eientei 6fd98e2e34 DIRECTOR: Workaround in hasLoopBounds where start can be != 0 and end = 0 2022-12-01 01:18:11 +01:00
Roland van Laar 8b310f1271 DIRECTOR: Fix memory leak in sound
Delete the stream gotten from _macresman->getDataFork.

Made the stream copying more explicit by aligning the variables names
with the function logic.
2022-11-30 10:54:49 +01:00
Hubert Maier 1eef5da741 DIRECTOR: Correct spelling mistake
comming -> coming
2022-10-27 15:56:09 +02:00
Misty De Meo 028bc85dc4 DIRECTOR: copy sound streams in AudioFileDecoder
It's possible for audio playback to still be underway at the time the
AudioFileDecoder is destroyed. For Mac games, destroying the _macresman
will also destroy the stream, feeing the pointer while it may be read from
in another thread. Copying the audio instead of just fetching the stream
from the MacResMan ensures that new stream will outlive the MacResMan if
necessary.

Fixes https://bugs.scummvm.org/ticket/13881.
2022-10-23 21:09:30 -07:00
Roland van Laar a2dc39d444 DIRECTOR: Fix unchecked return value
Only try to open the datafork when `open` succeeded.

Fixes COVERITY: 1465739
2022-10-07 17:14:10 +02:00
Roland van Laar 0091a20fe9 DIRECTOR: limit files closed by closeResFile
Lingo function `closeResFile` is only responsible for closing resource
file opened by `openResFile`. Register in `openResFile` which files
where opened and close only those files in `closeResFile`.

- Rename `_openResFiles` to `_allOpenResFiles` and
- Add new `_openResFiles` hashmap to track which files were opened in
  `openResFile`.
2022-09-23 22:55:50 +02:00
Scott Percival cb0455e34d DIRECTOR: Fix audio loop use-after-free 2022-09-12 15:52:18 +02:00
Scott Percival 7fc407bc4b DIRECTOR: Plug more memory leaks 2022-09-12 15:52:18 +02:00
Scott Percival f48dbb43b6 DIRECTOR: Use LoopableAudioStream for score audio loops
For looping sounds, the original code polled the score and created a new
AudioStream every time the previous iteration finished playing. The
downside of this approach is the sound needs to be fully resampled and
buffered after each playback, which can be heard as a gap between loops.

To fix this, loops now use a LoopableAudioStream. The reason why the
previous code did not was to allow for a specific edge case.
In Director, when a looping audio channel is set to cast member 0, the
loop is allowed to finish the current iteration before the audio stops.
Originally there wasn't a way of doing that, but now the
LoopableAudioStream classes can stop playing after a number of
iterations. As such, we keep a copy of the LoopableAudioStream handle
and call for the loop to stop when the cast member gets set to 0.

Improves looped audio playback in Eastern Mind.

Fixes the guitar solo between the transition from BLAST.DXR to INTRO.DXR
in Meet MediaBand.

Fixes the audio transition between n.am and s.am in Meet MediaBand.
2022-08-28 10:31:00 +00:00
Scott Percival 7c9badd57c DIRECTOR: Add debug level for sound events 2022-07-23 23:49:35 +02:00
Eugene Sandulenko abea37c9bb ALL: Update ScummVM project license to GPLv3+ 2021-12-26 18:48:43 +01:00
Misty De Meo 9d2492b4f8 DIRECTOR: stop sound before playing stream 2021-12-13 07:14:45 +01:00
Misty De Meo 1e9ecf405e DIRECTOR: allocate more than 2 audio channels 2021-11-19 22:58:59 -05:00
Misty De Meo 753c1c2fd9 DIRECTOR: handle macbinary audio streams 2021-11-07 20:39:51 +01:00
Scott Percival 53da0c8170 DIRECTOR: Fix file handle leak in getAudioStream 2021-11-07 11:57:29 +08:00
Scott Percival 7c145266b6 DIRECTOR: Case-scrub paths used by AudioFileDecoder::getAudioStream
Fixes the music on the Intro Menu screen of Total Distortion.
2021-09-19 10:45:53 +08:00
Logan B 21afa1457a DIRECTOR: Add AIFC detection 2021-09-17 20:34:16 +03:00
Roland van Laar 9dc24508d0 DIRECTOR: Handle sndCommand 0x8050
0x8050 seems to be handled the same as 0x8051.
Was added to allow for 'Double Click' demo movie.
2021-08-13 23:32:38 +02:00
djsrv 0a92826957 DIRECTOR: Fix whitespace 2021-08-12 13:18:27 -04:00