aboutsummaryrefslogtreecommitdiff
path: root/engines/agos
diff options
context:
space:
mode:
Diffstat (limited to 'engines/agos')
-rw-r--r--engines/agos/drivers/accolade/adlib.cpp29
-rw-r--r--engines/agos/midi.cpp9
-rw-r--r--engines/agos/midi.h3
3 files changed, 30 insertions, 11 deletions
diff --git a/engines/agos/drivers/accolade/adlib.cpp b/engines/agos/drivers/accolade/adlib.cpp
index 3a95d8f1c1..fce7c9b5d2 100644
--- a/engines/agos/drivers/accolade/adlib.cpp
+++ b/engines/agos/drivers/accolade/adlib.cpp
@@ -153,9 +153,10 @@ private:
byte currentA0hReg;
byte currentB0hReg;
int16 volumeAdjust;
+ byte velocity;
ChannelEntry() : currentInstrumentPtr(NULL), currentNote(0),
- currentA0hReg(0), currentB0hReg(0), volumeAdjust(0) { }
+ currentA0hReg(0), currentB0hReg(0), volumeAdjust(0), velocity(0) { }
};
byte _percussionReg;
@@ -257,8 +258,17 @@ void MidiDriver_Accolade_AdLib::close() {
}
void MidiDriver_Accolade_AdLib::setVolume(byte volume) {
- _masterVolume = volume;
- //renewNotes(-1, true);
+ // Set the master volume in range from -128 to 127
+ _masterVolume = CLIP<int>(-128 + volume, -128, 127);
+ for (int i = 0; i < AGOS_ADLIB_VOICES_COUNT; i++) {
+ // Adjust channel volume with the master volume and re-set registers
+ byte adjustedVelocity = _channels[i].velocity * ((float) (128 + _masterVolume) / 128);
+ noteOnSetVolume(i, 1, adjustedVelocity);
+ if (i <= AGOS_ADLIB_VOICES_PERCUSSION_START) {
+ // Set second operator for FM voices + first percussion
+ noteOnSetVolume(i, 2, adjustedVelocity);
+ }
+ }
}
void MidiDriver_Accolade_AdLib::onTimer() {
@@ -376,12 +386,11 @@ void MidiDriver_Accolade_AdLib::noteOn(byte FMvoiceChannel, byte note, byte velo
int16 channelVolumeAdjust = _channels[FMvoiceChannel].volumeAdjust;
channelVolumeAdjust += adjustedVelocity;
channelVolumeAdjust = CLIP<int16>(channelVolumeAdjust, 0, 0x7F);
-
- // TODO: adjust to global volume
- // original drivers had a global volume variable, which was 0 for full volume, -64 for half volume
- // and -128 for mute
-
- adjustedVelocity = channelVolumeAdjust;
+
+ // adjust velocity with the master volume
+ byte volumeAdjust = adjustedVelocity * ((float) (128 + _masterVolume) / 128);
+
+ adjustedVelocity = volumeAdjust;
if (!_musicDrvMode) {
// INSTR.DAT
@@ -441,6 +450,8 @@ void MidiDriver_Accolade_AdLib::noteOn(byte FMvoiceChannel, byte note, byte velo
adjustedVelocity = adjustedVelocity >> 1; // divide by 2
}
+ // Save velocity in the case volume will need to be changed
+ _channels[FMvoiceChannel].velocity = adjustedVelocity;
// Set volume of voice channel
noteOnSetVolume(FMvoiceChannel, 1, adjustedVelocity);
if (FMvoiceChannel <= AGOS_ADLIB_VOICES_PERCUSSION_START) {
diff --git a/engines/agos/midi.cpp b/engines/agos/midi.cpp
index 5e28654c41..b20f183489 100644
--- a/engines/agos/midi.cpp
+++ b/engines/agos/midi.cpp
@@ -28,6 +28,8 @@
#include "agos/agos.h"
#include "agos/midi.h"
+#include "agos/drivers/accolade/adlib.cpp"
+
#include "agos/drivers/accolade/mididriver.h"
#include "agos/drivers/simon1/adlib.h"
// Miles Audio for Simon 2
@@ -89,7 +91,7 @@ int MidiPlayer::open(int gameType, bool isDemo) {
assert(!_driver);
Common::String accoladeDriverFilename;
- MusicType musicType = MT_INVALID;
+ musicType = MT_INVALID;
switch (gameType) {
case GType_ELVIRA1:
@@ -159,6 +161,7 @@ int MidiPlayer::open(int gameType, bool isDemo) {
switch (musicType) {
case MT_ADLIB:
_driver = MidiDriver_Accolade_AdLib_create(accoladeDriverFilename);
+
break;
case MT_MT32:
_driver = MidiDriver_Accolade_MT32_create(accoladeDriverFilename);
@@ -473,6 +476,10 @@ void MidiPlayer::pause(bool b) {
_paused = b;
Common::StackLock lock(_mutex);
+ // if using the driver Accolade_AdLib call setVolume() to turn off\on the volume on all channels
+ if (musicType == MT_ADLIB && _musicMode == kMusicModeAccolade) {
+ static_cast <MidiDriver_Accolade_AdLib*> (_driver)->setVolume(_paused ? 0 : 128);
+ }
for (int i = 0; i < 16; ++i) {
if (_music.channel[i])
_music.channel[i]->volume(_paused ? 0 : (_music.volume[i] * _musicVolume / 255));
diff --git a/engines/agos/midi.h b/engines/agos/midi.h
index fb987fddcf..070413e2f8 100644
--- a/engines/agos/midi.h
+++ b/engines/agos/midi.h
@@ -123,7 +123,8 @@ public:
private:
kMusicMode _musicMode;
-
+ MusicType musicType;
+
private:
Common::SeekableReadStream *simon2SetupExtractFile(const Common::String &requestedFileName);
};