Commit Graph

646 Commits

Author SHA1 Message Date
Eugene Sandulenko
858954eec1 AUDIO: Properly warn user and act gracefully when soundfont is not specified.
Fixes #7127
2020-08-29 17:55:33 +02:00
Eugene Sandulenko
30d67ced36 AUDIO: Added flag to skip rewinding in LoopingAudioStream 2020-08-29 02:17:18 +02:00
Eugene Sandulenko
d49a9870b7 AUDIO: Silence MSVC warning
Their code analysis does not catch the fact that we cover all possible
cases in the switch() statement, hence it produces the warning.
2020-08-27 15:02:59 +02:00
Cameron Cawley
b76652120b AUDIO: Separate the XA ADPCM decoder from the PSX video decoder 2020-08-24 14:21:00 +02:00
Eugene Sandulenko
ed82ccb95b BACKENDS: More mutexes 2020-08-20 00:53:23 +02:00
Eric Fry
bd4939a2a4 AUDIO: FluidSynth Don't accept soundfont data if using version 1.x 2020-08-19 23:51:04 +10:00
Eugene Sandulenko
44e21a499d AUDIO: Added override keywords 2020-08-19 12:34:58 +02:00
Eric Fry
d0aea31958 AUDIO: Fixed Soundfont Coverity issues 2020-08-15 14:17:42 +10:00
Eugene Sandulenko
3c5f17dca8 AUDIO: Plug memory leak 2020-08-10 10:54:34 +02:00
Cameron Cawley
b7e3a807e8
AUDIO: Fix compilation on DS and OpenPandora 2020-08-09 16:19:16 +01:00
Eugene Sandulenko
d9bcf03903 AUDIO: Fix warnings 2020-08-08 10:38:25 +02:00
Eric Fry
ea7faf3d20 DRAGONS: soundfont2 fix windows compile. 2020-08-08 15:16:36 +10:00
Eric Fry
cc1de3f102 AUDIO: Removed standard headers from soundfont2 code. Updated license comment. 2020-08-07 10:10:12 +02:00
Eric Fry
487e4ec27a AUDIO: soundfont2 Fix endian issues when creating sf2 file data 2020-08-07 10:10:12 +02:00
Eric Fry
428cadbe6a AUDIO: Soundfont: Added scummvm license headers. Renamed class variables. 2020-08-07 10:10:12 +02:00
Eric Fry
2b500c1124 AUDIO: Soundfont. replaced _t types. Replaces sprintf usage. 2020-08-07 10:10:12 +02:00
Eric Fry
f2e4cc35a6 AUDIO: SoundFont2 creation support 2020-08-07 10:10:12 +02:00
Cameron Cawley
65164e00d4 AUDIO: Fix unused functions with older FluidSynth versions 2020-08-01 20:32:09 +01:00
athrxx
b379b52938 AUDIO: preparations for SegaCD sound driver 2020-07-30 22:19:21 +02:00
athrxx
5e276286ae AUDIO/GUI: add SegaCD sound settings 2020-07-30 22:19:21 +02:00
athrxx
edc0c5dc91 AUDIO: (FM-TOWNS) - fix pcm rate 2020-07-30 22:19:12 +02:00
Eugene Sandulenko
c5e532f1ad AUDIO: Fix warning 2020-07-25 13:20:15 +02:00
NMIError
11c74aaef8 MIDI: Updated MidiParser documentation 2020-07-25 00:35:47 +02:00
NMIError
da64fdc3d1 MIDI: Fix MIDI parser tracker overflow
The MIDI parser tracks the number of ticks and microseconds since the start of
playback of the current track. If a track loops infinitely, the tracker
eventually overflows (after about 71 minutes). The parser would then go haywire,
sending out the MIDI events at full speed and not terminating hanging notes,
resulting in loads of polyphony overrun errors. This does not affect looping
using jumpToTick or autoLoop, because that resets the tracker.

This change fixes this for the XMIDI parser. processEvent implementations can
now set a bool flag on the event, indicating that the event has caused a loop.
The MIDI parser will then reset the ticks and microseconds on the tracker to 0,
maintaining the deltas between the previous event values and current values.
The absolute number of ticks and microseconds since track start do not seem to
be needed anywhere; only the difference with the previous event is relevant.

This should fix bugs #6275 and #4354.
2020-07-25 00:35:47 +02:00
NMIError
3ad8c85af2 MIDI: Prevent duplicate MIDI messages
The MIDI parser would send All Notes Off events on all MIDI channels as a
safety measure when stopping playback in various situations without first
checking if a track was actually playing. Depending on the specifics of the
code driving the MIDI parser, this could generate many duplicate All Notes Off,
Sustain off and/or Pitch Bend center messages. This is a problem for slow MIDI
hardware like the MT-32, which needs some time to process all these messages.
As a result, the timing at the beginning of the next track could be wrong.

I've introduced checks in stopPlaying, setTrack, unloadMusic and the MIDI
parser destructor so that allNotesOff is called once when a track is playing,
and not a second time when playback has already stopped. Similarly, unloadMusic
does not execute when no music is loaded to prevent duplicate Pitch Bend
messages.
2020-07-25 00:35:47 +02:00
NMIError
315bbc7b5b MIDI: Use driver-specific impl. for stopping all notes
When the MIDI parser wanted to stop all notes on a MIDI device, it would send
an All Notes Off message and, optionally, a Sustain off message on all 16 MIDI
channels. This is inefficient for devices like the MT-32, which uses only 9
channels. The MT-32 hardware is also quite slow, so it is more responsive if it
has to process less messages.

I've added a generic stopAllNotes message to the MIDI driver using the old
method, which can be overriden by more specific implementations in subclasses.
The Miles MIDI driver implementation sends All Notes Off only on the channels
used by the MT-32. There are probably also more efficient implementations
possible for f.e. AdLib.
2020-07-25 00:35:47 +02:00
NMIError
848d8315a6 MIDI/GROOVIE: Refactor XMIDI timbre chunk loading
XMIDI timbre chunk processing was implemented using a callback. This
reimplements this using an interface for the necessary driver method, which is
a somewhat cleaner solution.
2020-07-25 00:35:47 +02:00
NMIError
b38f1f00ac MIDI/GROOVIE: Fix MT-32 XMIDI timbre init delays
XMIDI data for the MT-32 can contain a timbre chunk which contains the custom
timbre numbers used for a track. Before starting playback of the track, the
timbres must be loaded into the MT-32 using SysEx messages. Each SysEx message
needs a delay before sending the next message to give the MT-32 enough time to
process it.

The delays between the messages were generated using the OSystem::delayMillis
function. This throws off the timing of the MidiParser, which causes MIDI
messages to "pile up", in this case at the start of the track. This change adds
a queue to the Miles MIDI driver, which can store the SysEx messages that must
be executed. The MidiParser suspends playback until the driver has sent all
messages in the queue.

This fixes the start of tracks in The 7th Guest, which had incorrect timing.

Because of the new SysEx queue, MT-32 initialization of The 7th Guest takes a
bit longer than it did before. The game plays an animation of a fixed length
and aborts the initialization if it is not done by the end of the animation.
This problem was already fixed for the GM initialization, so I've applied the
same fix for the MT-32.
2020-07-25 00:35:47 +02:00
NMIError
50772c1fbc MIDI: Fix XMIDI custom timbre loading
XMIDI files have an optional header defining custom timbres used for each
track. Before playback these timbres have to be sent to the MIDI device. The
old implementation of this functionality had two problems:

- The custom timbres were only sent during loading of the XMIDI data, for the
first track. If another track was played, the custom timbres for that track
would not be loaded.
- The custom timbres were sent after starting playback of the track. This
caused the sending of the timbres to sometimes overlap with the start of the
playback of the track, causing wrong instruments and bad timing.

If fixed these issues by moving the loading of the timbres to a new event
handler which is triggered during the setTrack function, before playback is
started.

This fixes problems with some MT-32 tracks in The 7th Guest, f.e. the second
track that plays on the main menu after starting the game.
2020-07-25 00:35:47 +02:00
NMIError
2f4937bd6d MIDI: Fix XMIDI SysEx Final Data controller
XMIDI defines controllers which allow the MIDI data to send controller changes
that build up SysEx messages. The last SysEx data byte is specified using the
Final Data controller, which should append the final byte to the SysEx message
and send it to the MIDI device. The old implementation did not append the last
byte. Additionally, when increasing the memory address for the SysEx, it did
not take into account that the MIDI bytes are 7 bit.

This commit fixes these issues. This restores a missing data byte in a SySex in
the MIDI initialization of The 7th Guest.
2020-07-25 00:35:47 +02:00
Michał Janiszewski
eed727474f AUDIO: Fix linking with vcpkg-provided FLAC 2020-07-15 15:30:55 +02:00
Eugene Sandulenko
1b501be3b7 AUDIO: Align overridden methods 2020-07-07 12:18:20 +02:00
NMIError
57cb344396
MIDI: Fix _gsBank init and bad if statement (#2341) 2020-06-21 16:07:20 +02:00
NMIError
0af83d3faa
KYRA/MIDI: Fix minor MT-32/GM issues (#2333)
* KYRA: Added GM initialization for Lands of Lore

The original interpreter of Lands of Lore uses two executables, which
both do initialization of MIDI devices. The main executable runs a
sysex file for GM devices; the intro executable does not.

ScummVM only does MIDI initialization once and it performs this like
the intro executable. I've added the GM initialization of the main
executable. Note that the initialization file consists mostly of
sysexes which alter the display of the SC-55, so it's not particulary
useful. Not many games did this though, so I thought it would be a
fun feature to include.

I also noticed that the check which distinguishes between the two
demo versions of LoL did not work properly; the useAltShapeHeader
flag was true for both versions. I've changed it to check for the
existence of a PAK file which was only included with one of the two
demos.

* MIDI: Delay parser after handling SysEx events

This changes the way delays between SysEx events in MIDI data are handled from
delaying the backend to delaying the MidiParser.

SysEx events require a delay between events to ensure correct processing by the
MIDI device. This is usually implemented by calling OSystem::delayMillis.
Some games use some form of MIDI sequence filled with SysEx messages to
initialize the MIDI device. This is handled by the MidiParser. Using the
delayMillis method causes the following MIDI events to be "bunched up" and be
executed in a shorter timespan than intended.

I've altered this by making the MidiParser stop parsing when a SysEx event is
encountered and not enough time has passed since the last SysEx. After enough
time has passed, the next SysEx is sent and parsing resumes. To facilitate
this, I've introduced an alternate sysExNoDelay fuction on the MidiDiver. This
does not execute the delay itself, but instead returns the required delay time,
so the parser can handle this instead.

I've currently only implemented this method for the Miles MT-32/GM driver. For
other driver implementations, this will call the regular sysEx method and
return a 0 delay time, so there will be no change in behavior.

This restores a sound effect at the end of the Legend of Kyrandia MT-32 MIDI
initialization. Before, the Note On and Note Off events would be transmitted
instantly after each other, causing the notes not to play.

* MIDI: Add instrument bank fallback

Some games rely on a feature of the Roland SC-55 v1.xx that corrects invalid
instrument banks. This feature was removed in later versions of the device and
not implemented in most other GM devices, causing some MIDI data (sound effects
mostly) to play incorrectly.

Specifically, this applies to Lands of Lore. For example, in the intro, the
sound effect of the ring sparkling uses an incorrect instrument bank. Depending
on how the MIDI device handles this, the sound will play correctly, with the
wrong instrument, or not at all.

This commit emulates the SC-55 functionality that corrects the invalid bank
numbers. I've implemented this (partially) on the MidiDriver, so that it can be
re-used for other games (Xeen 4 and 5 also have this issue with some sound
effects).

* KYRA: Start MIDI playback after selecting track

The MIDI parser would automatically start playback after loading MIDI data, but
KYRA engine games use MIDI files with multiple tracks. Because of this it was
necessary to immediately stop playback after loading MIDI data, and then select
the track that should be played for correct playback. The parser now has a
feature to disable automatically starting playback, so I've implemented this
for KYRA.

* KYRA: Improve stopping MIDI playback

In two places All Notes Off events were sent on all channels to stop MIDI
playback of the background music. However, this will also cut off any MIDI
sound effects which are playing. Where needed I've replaced this with simply
stopping playback of the background music; the parser will turn off any active
notes.
I've also made sure playback is stopped before freeing the music data
memory to prevent any issues.
I've added sending All Notes Off events when the game quits, just in case any
hanging notes are not ended by the parsers (should not really be a problem
though).

* MIDI/KYRA: Add pausing playback to MIDI parser

* KYRA: Fix invalid track selection

If a game would attempt to play an invalid track, the parser would start
playing the previously selected track. Fixed this so the parser will not start
playing.
2020-06-20 23:27:30 +02:00
D G Turner
e086dbfcd5 AUDIO: Fix Signed vs. Unsigned Comparison Compiler Warning in Fluidsynth 2020-06-16 22:03:04 +01:00
D G Turner
286c5d6f1e AUDIO: Fix Compiler Warnings in MIDI / XMIDI Parser
The _activeTrack variable is of type byte which is defined in
common/scummsys.h as unsigned char so this variable can never
be negative and thus the checks removed here were causing compiler
warnings.
2020-06-13 18:31:32 +01:00
NMIError
6f575e580c MIDI: Fix XMIDI hanging notes
XMIDI uses Note On events with a length which specifies when a corresponding
Note Off event should be generated. Some XMIDI data contains notes with length
0, which are played very briefly by AIL. However, the ScummVM MidiParser will
treat Note On events with length 0 as "active notes", meaning it will wait for
a Note Off event before turning off the note. The Note Off will never come and
the note will hang.

This is particularly noticable in Ultima 8 (first section of the track that
plays at the beginning of the game, at the shore) and The 7th Guest (the track
that plays while solving the cake puzzle).

I've fixed this by changing the length from 0 to 1. This will cause the notes
to be active for the minimum length.
2020-06-13 23:33:31 +09:00
Eugene Sandulenko
3446edb01a AUDIO: Added override keywords 2020-06-12 21:53:49 +02:00
NMIError
0f297559cd ULTIMA8/MIDI: Rename doNotAutoStartPlayback
Renamed doNotAutoStartPlayback to disableAutoStartPlayback for more consistency
in property naming.
2020-06-12 13:46:27 -05:00
NMIError
a24e3b2a4f MIDI: Add constant for number of tracks 2020-06-12 13:46:27 -05:00
NMIError
f497753b21 MIDI: Add support for XMIDI sequence branch indexes
This adds support for the "sequence branch index" feature of the XMIDI format.
These "branches" (positions in the MIDI bytestream) are defined in the track
header. I've added two generic methods to the MidiParser interface to set the
current parsing position to one of these positions, or to check for the
existence of a position with a certain number (this is needed for Ultima 8).

Additionally, I've added an option to the MIDI parser to prevent the parser
from starting playback immediately after parsing, so that a starting position
(or a track) can be selected first. Playback can then be started with the new
startPlaying method.
2020-06-12 13:46:27 -05:00
Lothar Serra Mari
b0b0e573fb MT32: Add missing default switch cases
See 4d911012e2 for reference.
2020-06-07 00:55:45 +02:00
Lothar Serra Mari
d831c5984e MT32: Fix MSVC warning
see 369ba0c4b7 for reference.
2020-06-07 00:55:45 +02:00
Lothar Serra Mari
cc5299961e MT32: Update to libmt32emu 2.4.0 2020-06-07 00:55:45 +02:00
Eric Fry
66f880812a AUDIO: Fixed formatting for sf loader functions.
Don't include sf loader support if compiling with fluidsynth 1.x
2020-06-05 20:57:54 +10:00
Eric Fry
d18f9734a1 AUDIO: Add ability for engine to supply its own soundfont data.
Add MDT_PREFER_FLUID to allow engines to indicate they prefer the fluidsynth driver.
2020-06-05 20:57:54 +10:00
NMIError
62387f8d38
MIDI/KYRA: Miles channel locking and GM support (#2273)
* MIDI/KYRA: Add channel locking and GM to XMIDI

This improves support for XMIDI channel locking and moves it from the KYRA
engine to the generic Miles MIDI driver. To support this, a source parameter
is added to the XMIDI parser and Miles driver so the driver can distinguish
several XMIDI parser instances sending MIDI events. I've also added GM support
to the generic Miles MIDI driver.

The previous implementation of channel locking did not always track and restore
controller values properly when unlocking a channel. Specifically, at the start
of Legend of Kyrandia, when Brandon talks to the tree, the tree "creaking"
sound effect uses some channels from the background music. The volume of the
music channels was not correctly restored, resulting in some instruments being
much louder then others.
Another issue was that volume was not always properly set when locking a
channel. In the Legend of Kyrandia intro, when Brandon is lifted up to the
house, some sound effects were missing because MIDI channel volume was 0.
This new implementation fixes these issues.

* MIDI: Suppress Miles controller warnings

Several Miles controller MIDI messages generate warnings in the XMIDI parser,
even though they are handled by the Miles drivers. I've removed these.

* MIDI: Fix Codacy issues
2020-05-29 17:50:14 +02:00
Matthew Duggan
a98617a843 AUDIO: Correct small errors in AMF loader
Crusader menu music now plays correctly, woo.
2020-05-03 22:52:45 +09:00
Matthew Duggan
a64462a60f AUDIO: Add support for loading Crusader AMF files 2020-05-02 20:09:23 +02:00
Matthew Duggan
79f151c6aa AUDIO: Import small fix from latest micromod/ibxm
Specifically, 9ff030a (Fix set panning command.)
2020-05-02 17:07:54 +09:00