Initial commit

This commit is contained in:
2026-02-02 04:50:13 +01:00
commit 5b11698731
22592 changed files with 7677434 additions and 0 deletions

View File

@@ -0,0 +1,915 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/file.h"
#include "common/system.h"
#include "common/textconsole.h"
#include "audio/fmopl.h"
#include "audio/mididrv.h"
#include "dgds/sound/resource/sci_resource.h"
#include "dgds/sound/drivers/mididriver.h"
#include "dgds/sound/scispan.h"
#include "dgds/dgds.h"
namespace Dgds {
#ifdef __DC__
#define STEREO false
#else
#define STEREO true
#endif
class MidiDriver_AdLib : public MidiDriver {
public:
enum {
kVoices = 9,
kRhythmKeys = 62
};
MidiDriver_AdLib() : _isSCI0(false), _playSwitch(true), _masterVolume(15),
_numVoiceMax(kVoices), _rhythmKeyMap(), _opl(nullptr), _adlibTimerParam(nullptr), _adlibTimerProc(nullptr), _stereo(false), _isOpen(false) { }
~MidiDriver_AdLib() override { }
// MidiDriver
int open() override { return -1; } // Dummy implementation (use openAdLib)
int openAdLib();
void close() override;
void send(uint32 b) override;
MidiChannel *allocateChannel() override { return nullptr; }
MidiChannel *getPercussionChannel() override { return nullptr; }
bool isOpen() const override { return _isOpen; }
uint32 getBaseTempo() override { return 1000000 / OPL::OPL::kDefaultCallbackFrequency; }
// MidiDriver
void setTimerCallback(void *timerParam, Common::TimerManager::TimerProc timerProc) override;
void onTimer();
void setVolume(byte volume);
void playSwitch(bool play);
bool loadResource(const SciSpan<const byte> &data);
uint32 property(int prop, uint32 param) override;
bool useRhythmChannel() const { return _rhythmKeyMap; }
private:
enum ChannelID {
kLeftChannel = 1,
kRightChannel = 2
};
struct AdLibOperator {
bool amplitudeMod;
bool vibrato;
bool envelopeType;
bool kbScaleRate;
byte frequencyMult; // (0-15)
byte kbScaleLevel; // (0-3)
byte totalLevel; // (0-63, 0=max, 63=min)
byte attackRate; // (0-15)
byte decayRate; // (0-15)
byte sustainLevel; // (0-15)
byte releaseRate; // (0-15)
byte waveForm; // (0-3)
};
struct AdLibModulator {
byte feedback; // (0-7)
bool algorithm;
};
struct AdLibPatch {
AdLibOperator op[2];
AdLibModulator mod;
};
struct Channel {
uint8 patch; // Patch setting
uint8 volume; // Channel volume (0-63)
uint8 pan; // Pan setting (0-127, 64 is center)
uint8 holdPedal; // Hold pedal setting (0 to 63 is off, 127 to 64 is on)
uint8 extraVoices; // The number of additional voices this channel optimally needs
uint16 pitchWheel; // Pitch wheel setting (0-16383, 8192 is center)
uint8 lastVoice; // Last voice used for this MIDI channel
bool enableVelocity; // Enable velocity control (SCI0)
uint8 voices; // Number of voices currently used by this channel
uint8 mappedVoices; // Number of voices currently mapped to this channel
Channel() : patch(0), volume(63), pan(64), holdPedal(0), extraVoices(0),
pitchWheel(8192), lastVoice(0), enableVelocity(false), voices(0),
mappedVoices(0) { }
};
struct AdLibVoice {
int8 channel; // MIDI channel that is currently using this voice, or -1
int8 mappedChannel; // MIDI channel that this voice is mapped to, or -1
int8 note; // Currently playing MIDI note or -1
int patch; // Currently playing patch or -1
uint8 velocity; // Note velocity
bool isSustained; // Flag indicating a note that is being sustained by the hold pedal
uint16 age; // Age of the current note
AdLibVoice() : channel(-1), mappedChannel(-1), note(-1), patch(-1), velocity(0), isSustained(false), age(0) { }
};
bool _stereo;
bool _isSCI0;
OPL::OPL *_opl;
bool _isOpen;
bool _playSwitch;
int _masterVolume;
const uint8 _numVoiceMax;
Channel _channels[MIDI_CHANNELS];
AdLibVoice _voices[kVoices];
Common::SpanOwner<SciSpan<const byte> > _rhythmKeyMap;
Common::Array<AdLibPatch> _patches;
Common::List<int> _voiceQueue;
Common::TimerManager::TimerProc _adlibTimerProc;
void *_adlibTimerParam;
void loadInstrument(const SciSpan<const byte> &ins);
void voiceOn(int voice, int note, int velocity);
void voiceOff(int voice);
void setPatch(int voice, int patch);
void setNote(int voice, int note, bool key);
void setVelocity(int voice);
void setOperator(int oper, AdLibOperator &op);
void setRegister(int reg, int value, int channels = kLeftChannel | kRightChannel);
void renewNotes(int channel, bool key);
void noteOn(int channel, int note, int velocity);
void noteOff(int channel, int note);
int findVoice(int channel);
int findVoiceLateSci11(int channel);
void voiceMapping(int channel, int voices);
void assignVoices(int channel, int voices);
void releaseVoices(int channel, int voices);
void donateVoices();
void queueMoveToBack(int voice);
void setVelocityReg(int regOffset, int velocity, int kbScaleLevel, int pan);
int calcVelocity(int voice, int op);
};
class MidiPlayer_AdLib : public MidiPlayer {
public:
MidiPlayer_AdLib() : MidiPlayer() { _driver = new MidiDriver_AdLib(); }
~MidiPlayer_AdLib() override {
delete _driver;
_driver = nullptr;
}
int open() override;
void close() override;
byte getPlayId() const override;
int getPolyphony() const override { return MidiDriver_AdLib::kVoices; }
bool hasRhythmChannel() const override { return false; }
void setVolume(byte volume) override { static_cast<MidiDriver_AdLib *>(_driver)->setVolume(volume); }
void playSwitch(bool play) override { static_cast<MidiDriver_AdLib *>(_driver)->playSwitch(play); }
int getLastChannel() const override { return (static_cast<const MidiDriver_AdLib *>(_driver)->useRhythmChannel() ? 8 : 15); }
};
static const byte registerOffset[MidiDriver_AdLib::kVoices] = {
0x00, 0x01, 0x02, 0x08, 0x09, 0x0A, 0x10, 0x11, 0x12
};
static const byte velocityMap1[64] = {
0x00, 0x0c, 0x0d, 0x0e, 0x0f, 0x11, 0x12, 0x13,
0x14, 0x16, 0x17, 0x18, 0x1a, 0x1b, 0x1c, 0x1d,
0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26,
0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2d, 0x2d, 0x2e,
0x2f, 0x30, 0x31, 0x32, 0x32, 0x33, 0x34, 0x34,
0x35, 0x36, 0x36, 0x37, 0x38, 0x38, 0x39, 0x3a,
0x3b, 0x3b, 0x3b, 0x3c, 0x3c, 0x3c, 0x3d, 0x3d,
0x3d, 0x3e, 0x3e, 0x3e, 0x3e, 0x3f, 0x3f, 0x3f
};
static const byte velocityMap2[64] = {
0x00, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a,
0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x21,
0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29,
0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x2f, 0x30,
0x31, 0x32, 0x32, 0x33, 0x34, 0x34, 0x35, 0x36,
0x36, 0x37, 0x38, 0x38, 0x39, 0x39, 0x3a, 0x3a,
0x3b, 0x3b, 0x3b, 0x3c, 0x3c, 0x3c, 0x3d, 0x3d,
0x3d, 0x3e, 0x3e, 0x3e, 0x3e, 0x3f, 0x3f, 0x3f
};
// One octave with three pitch wheel positions after each note
static const int adlibFreq[48] = {
0x157, 0x15c, 0x161, 0x166, 0x16b, 0x171, 0x176, 0x17b,
0x181, 0x186, 0x18c, 0x192, 0x198, 0x19e, 0x1a4, 0x1aa,
0x1b0, 0x1b6, 0x1bd, 0x1c3, 0x1ca, 0x1d0, 0x1d7, 0x1de,
0x1e5, 0x1ec, 0x1f3, 0x1fa, 0x202, 0x209, 0x211, 0x218,
0x220, 0x228, 0x230, 0x238, 0x241, 0x249, 0x252, 0x25a,
0x263, 0x26c, 0x275, 0x27e, 0x287, 0x290, 0x29a, 0x2a4
};
int MidiDriver_AdLib::openAdLib() {
_stereo = STEREO;
debug(3, "ADLIB: Starting driver in %s mode", (_isSCI0 ? "SCI0" : "SCI1"));
// Fill in the voice queue
for (int i = 0; i < kVoices; ++i)
_voiceQueue.push_back(i);
_opl = OPL::Config::create(_stereo ? OPL::Config::kDualOpl2 : OPL::Config::kOpl2);
// Try falling back to mono, thus plain OPL2 emulator, when no Dual OPL2 is available.
if (!_opl && _stereo) {
_stereo = false;
_opl = OPL::Config::create(OPL::Config::kOpl2);
}
if (!_opl)
return -1;
if (!_opl->init()) {
delete _opl;
_opl = nullptr;
return -1;
}
setRegister(0xBD, 0);
setRegister(0x08, 0);
setRegister(0x01, 0x20);
_isOpen = true;
_opl->start(new Common::Functor0Mem<void, MidiDriver_AdLib>(this, &MidiDriver_AdLib::onTimer));
return 0;
}
void MidiDriver_AdLib::close() {
delete _opl;
_rhythmKeyMap.clear();
}
void MidiDriver_AdLib::setVolume(byte volume) {
_masterVolume = volume;
renewNotes(-1, true);
}
// MIDI messages can be found at https://web.archive.org/web/20120128110425/http://www.midi.org/techspecs/midimessages.php
void MidiDriver_AdLib::send(uint32 b) {
byte command = b & 0xf0;
byte channel = b & 0xf;
byte op1 = (b >> 8) & 0xff;
byte op2 = (b >> 16) & 0xff;
//debug(1, "midi send %02x %x %02x %02x", command, channel, op1, op2);
switch (command) {
case 0x80:
noteOff(channel, op1);
break;
case 0x90:
noteOn(channel, op1, op2);
break;
case 0xb0:
switch (op1) {
case 0x07:
_channels[channel].volume = op2 >> 1;
renewNotes(channel, true);
break;
case 0x0a:
_channels[channel].pan = op2;
renewNotes(channel, true);
break;
case 0x40:
_channels[channel].holdPedal = op2;
if (op2 == 0) {
for (int i = 0; i < kVoices; i++) {
if ((_voices[i].channel == channel) && _voices[i].isSustained)
voiceOff(i);
}
}
break;
case 0x4b:
#ifndef ADLIB_DISABLE_VOICE_MAPPING
voiceMapping(channel, op2);
#endif
break;
case 0x4e:
_channels[channel].enableVelocity = op2;
break;
case SCI_MIDI_CHANNEL_NOTES_OFF:
for (int i = 0; i < kVoices; i++)
if ((_voices[i].channel == channel) && (_voices[i].note != -1))
voiceOff(i);
break;
default:
//warning("ADLIB: ignoring MIDI command %02x %02x %02x", command | channel, op1, op2);
break;
}
break;
case 0xc0:
_channels[channel].patch = op1;
break;
// The original AdLib driver from sierra ignores aftertouch completely, so should we
case 0xa0: // Polyphonic key pressure (aftertouch)
case 0xd0: // Channel pressure (aftertouch)
break;
case 0xe0:
_channels[channel].pitchWheel = (op1 & 0x7f) | ((op2 & 0x7f) << 7);
renewNotes(channel, true);
break;
default:
warning("ADLIB: Unknown event %02x", command);
}
}
void MidiDriver_AdLib::setTimerCallback(void *timerParam, Common::TimerManager::TimerProc timerProc) {
_adlibTimerProc = timerProc;
_adlibTimerParam = timerParam;
}
void MidiDriver_AdLib::onTimer() {
if (_adlibTimerProc)
(*_adlibTimerProc)(_adlibTimerParam);
// Increase the age of the notes
for (int i = 0; i < kVoices; i++) {
if (_voices[i].note != -1)
_voices[i].age++;
}
}
void MidiDriver_AdLib::loadInstrument(const SciSpan<const byte> &ins) {
AdLibPatch patch;
// Set data for the operators
for (int i = 0; i < 2; i++) {
const byte *op = ins.getUnsafeDataAt(i * 13, 13);
patch.op[i].kbScaleLevel = op[0] & 0x3;
patch.op[i].frequencyMult = op[1] & 0xf;
patch.op[i].attackRate = op[3] & 0xf;
patch.op[i].sustainLevel = op[4] & 0xf;
patch.op[i].envelopeType = op[5];
patch.op[i].decayRate = op[6] & 0xf;
patch.op[i].releaseRate = op[7] & 0xf;
patch.op[i].totalLevel = op[8] & 0x3f;
patch.op[i].amplitudeMod = op[9];
patch.op[i].vibrato = op[10];
patch.op[i].kbScaleRate = op[11];
}
patch.op[0].waveForm = ins[26] & 0x3;
patch.op[1].waveForm = ins[27] & 0x3;
// Set data for the modulator
patch.mod.feedback = ins[2] & 0x7;
patch.mod.algorithm = !ins[12]; // Flag is inverted
_patches.push_back(patch);
}
void MidiDriver_AdLib::voiceMapping(int channel, int voices) {
int curVoices = 0;
for (int i = 0; i < _numVoiceMax; i++)
if (_voices[i].mappedChannel == channel)
curVoices++;
curVoices += _channels[channel].extraVoices;
if (curVoices < voices) {
debug(3, "ADLIB: assigning %i additional voices to channel %i", voices - curVoices, channel);
assignVoices(channel, voices - curVoices);
} else if (curVoices > voices) {
debug(3, "ADLIB: releasing %i voices from channel %i", curVoices - voices, channel);
releaseVoices(channel, curVoices - voices);
donateVoices();
}
}
void MidiDriver_AdLib::assignVoices(int channel, int voices) {
assert(voices > 0);
for (int i = 0; i < _numVoiceMax; i++)
if (_voices[i].mappedChannel == -1) {
if (_voices[i].note != -1) // Late SCI1.1, stop note on unmapped channel
voiceOff(i);
_voices[i].mappedChannel = channel;
++_channels[channel].mappedVoices;
if (--voices == 0)
return;
}
// This is already too advanced for SCI0...
if (!_isSCI0)
_channels[channel].extraVoices += voices;
}
void MidiDriver_AdLib::releaseVoices(int channel, int voices) {
if (_channels[channel].extraVoices >= voices) {
_channels[channel].extraVoices -= voices;
return;
}
voices -= _channels[channel].extraVoices;
_channels[channel].extraVoices = 0;
for (int i = 0; i < _numVoiceMax; i++) {
if ((_voices[i].mappedChannel == channel) && (_voices[i].note == -1)) {
_voices[i].mappedChannel = -1;
--_channels[channel].mappedVoices;
if (--voices == 0)
return;
}
}
for (int i = 0; i < _numVoiceMax; i++) {
if (_voices[i].mappedChannel == channel) {
voiceOff(i);
_voices[i].mappedChannel = -1;
--_channels[channel].mappedVoices;
if (--voices == 0)
return;
}
}
}
void MidiDriver_AdLib::donateVoices() {
if (_isSCI0)
return;
int freeVoices = 0;
for (int i = 0; i < kVoices; i++)
if (_voices[i].mappedChannel == -1)
freeVoices++;
if (freeVoices == 0)
return;
for (int i = 0; i < MIDI_CHANNELS; i++) {
if (_channels[i].extraVoices >= freeVoices) {
assignVoices(i, freeVoices);
_channels[i].extraVoices -= freeVoices;
return;
} else if (_channels[i].extraVoices > 0) {
assignVoices(i, _channels[i].extraVoices);
freeVoices -= _channels[i].extraVoices;
_channels[i].extraVoices = 0;
}
}
}
void MidiDriver_AdLib::renewNotes(int channel, bool key) {
for (int i = 0; i < kVoices; i++) {
// Update all notes playing this channel
if ((channel == -1) || (_voices[i].channel == channel)) {
if (_voices[i].note != -1)
setNote(i, _voices[i].note, key);
}
}
}
void MidiDriver_AdLib::noteOn(int channel, int note, int velocity) {
if (velocity == 0)
return noteOff(channel, note);
velocity >>= 1;
// Check for playable notes
if ((note < 12) || (note > 107))
return;
for (int i = 0; i < kVoices; i++) {
if ((_voices[i].channel == channel) && (_voices[i].note == note)) {
voiceOff(i);
voiceOn(i, note, velocity);
return;
}
}
int voice = _rhythmKeyMap ? findVoiceLateSci11(channel) : findVoice(channel);
if (voice == -1) {
debug(3, "ADLIB: failed to find free voice assigned to channel %i", channel);
return;
}
voiceOn(voice, note, velocity);
}
int MidiDriver_AdLib::findVoice(int channel) {
int voice = -1;
int oldestVoice = -1;
uint32 oldestAge = 0;
// Try to find a voice assigned to this channel that is free (round-robin)
for (int i = 0; i < kVoices; i++) {
int v = (_channels[channel].lastVoice + i + 1) % kVoices;
if (_voices[v].mappedChannel == channel) {
if (_voices[v].note == -1) {
voice = v;
_voices[voice].channel = channel;
break;
}
// We also keep track of the oldest note in case the search fails
// Notes started in the current time slice will not be selected
if (_voices[v].age >= oldestAge) {
oldestAge = _voices[v].age;
oldestVoice = v;
}
}
}
if (voice == -1) {
if (!oldestAge)
return -1;
voiceOff(oldestVoice);
voice = oldestVoice;
_voices[voice].channel = channel;
}
_channels[channel].lastVoice = voice;
return voice;
}
int MidiDriver_AdLib::findVoiceLateSci11(int channel) {
// Search for unused voice
for (const auto &voice : _voiceQueue) {
if (_voices[voice].note == -1 && _voices[voice].patch == _channels[channel].patch) {
_voices[voice].channel = channel;
return voice;
}
}
// Same as before, minus the program check
for (const auto &voice : _voiceQueue) {
if (_voices[voice].note == -1) {
_voices[voice].channel = channel;
return voice;
}
}
// Search for channel with highest excess of voices
int maxExceed = 0;
int maxExceedChan = 0;
for (uint i = 0; i < MIDI_CHANNELS; ++i) {
if (_channels[i].voices > _channels[i].mappedVoices) {
int exceed = _channels[i].voices - _channels[i].mappedVoices;
if (exceed > maxExceed) {
maxExceed = exceed;
maxExceedChan = i;
}
}
}
// Stop voice on channel with highest excess if possible, otherwise stop
// note on this channel.
int stopChan = (maxExceed > 0) ? maxExceedChan : channel;
for (const auto &voice : _voiceQueue) {
if (_voices[voice].channel == stopChan) {
voiceOff(voice);
_voices[voice].channel = channel;
return voice;
}
}
return -1;
}
void MidiDriver_AdLib::queueMoveToBack(int voice) {
_voiceQueue.remove(voice);
_voiceQueue.push_back(voice);
}
void MidiDriver_AdLib::noteOff(int channel, int note) {
for (int i = 0; i < kVoices; i++) {
if ((_voices[i].channel == channel) && (_voices[i].note == note)) {
if (_channels[channel].holdPedal)
_voices[i].isSustained = true;
else
voiceOff(i);
return;
}
}
}
void MidiDriver_AdLib::voiceOn(int voice, int note, int velocity) {
int channel = _voices[voice].channel;
int patch = _channels[channel].patch;
_voices[voice].age = 0;
++_channels[channel].voices;
queueMoveToBack(voice);
if ((channel == 9) && _rhythmKeyMap) {
patch = CLIP(note, 27, 88) + 101;
}
// Set patch if different from current patch
if (patch != _voices[voice].patch && _playSwitch)
setPatch(voice, patch);
_voices[voice].velocity = velocity;
setNote(voice, note, true);
}
void MidiDriver_AdLib::voiceOff(int voice) {
int channel = _voices[voice].channel;
_voices[voice].isSustained = false;
setNote(voice, _voices[voice].note, 0);
_voices[voice].note = -1;
_voices[voice].age = 0;
queueMoveToBack(voice);
--_channels[channel].voices;
}
void MidiDriver_AdLib::setNote(int voice, int note, bool key) {
int channel = _voices[voice].channel;
if ((channel == 9) && _rhythmKeyMap)
note = _rhythmKeyMap[CLIP(note, 27, 88) - 27];
_voices[voice].note = note;
int index = note << 2;
uint16 pitchWheel = _channels[channel].pitchWheel;
int sign;
if (pitchWheel == 0x2000) {
pitchWheel = 0;
sign = 0;
} else if (pitchWheel > 0x2000) {
pitchWheel -= 0x2000;
sign = 1;
} else {
pitchWheel = 0x2000 - pitchWheel;
sign = -1;
}
pitchWheel /= 171;
if (sign == 1)
index += pitchWheel;
else
index -= pitchWheel;
if (index > 0x1fc) // Limit to max MIDI note (<< 2)
index = 0x1fc;
if (index < 0) // Not in SSCI
index = 0;
int freq = adlibFreq[index % 48];
setRegister(0xA0 + voice, freq & 0xff);
int oct = index / 48;
if (oct > 0)
--oct;
if (oct > 7) // Not in SSCI
oct = 7;
setRegister(0xB0 + voice, (key << 5) | (oct << 2) | (freq >> 8));
setVelocity(voice);
}
void MidiDriver_AdLib::setVelocity(int voice) {
AdLibPatch &patch = _patches[_voices[voice].patch];
int pan = _channels[_voices[voice].channel].pan;
setVelocityReg(registerOffset[voice] + 3, calcVelocity(voice, 1), patch.op[1].kbScaleLevel, pan);
// In AM mode we need to set the level for both operators
if (_patches[_voices[voice].patch].mod.algorithm == 1)
setVelocityReg(registerOffset[voice], calcVelocity(voice, 0), patch.op[0].kbScaleLevel, pan);
}
int MidiDriver_AdLib::calcVelocity(int voice, int op) {
if (_isSCI0) {
int velocity = _masterVolume;
if (velocity > 0)
velocity += 3;
if (velocity > 15)
velocity = 15;
int insVelocity;
if (_channels[_voices[voice].channel].enableVelocity)
insVelocity = _voices[voice].velocity;
else
insVelocity = 63 - _patches[_voices[voice].patch].op[op].totalLevel;
// Note: Later SCI0 has a static table that is close to this formula, but not exactly the same.
// Early SCI0 does (velocity * (insVelocity / 15))
return velocity * insVelocity / 15;
} else {
AdLibOperator &oper = _patches[_voices[voice].patch].op[op];
int velocity = _channels[_voices[voice].channel].volume + 1;
velocity = velocity * (velocityMap1[_voices[voice].velocity] + 1) / 64;
velocity = velocity * (_masterVolume + 1) / 16;
if (--velocity < 0)
velocity = 0;
return velocityMap2[velocity] * (63 - oper.totalLevel) / 63;
}
}
void MidiDriver_AdLib::setVelocityReg(int regOffset, int velocity, int kbScaleLevel, int pan) {
if (!_playSwitch)
velocity = 0;
if (_stereo) {
int velLeft = velocity;
int velRight = velocity;
if (pan > 0x40)
velLeft = velLeft * (0x7f - pan) / 0x3f;
else if (pan < 0x40)
velRight = velRight * pan / 0x40;
setRegister(0x40 + regOffset, (kbScaleLevel << 6) | (63 - velLeft), kLeftChannel);
setRegister(0x40 + regOffset, (kbScaleLevel << 6) | (63 - velRight), kRightChannel);
} else {
setRegister(0x40 + regOffset, (kbScaleLevel << 6) | (63 - velocity));
}
}
void MidiDriver_AdLib::setPatch(int voice, int patch) {
if ((patch < 0) || ((uint)patch >= _patches.size())) {
warning("ADLIB: Invalid patch %i requested", patch);
// Substitute instrument 0
patch = 0;
}
_voices[voice].patch = patch;
AdLibModulator &mod = _patches[patch].mod;
// Set the common settings for both operators
setOperator(registerOffset[voice], _patches[patch].op[0]);
setOperator(registerOffset[voice] + 3, _patches[patch].op[1]);
// Set the additional settings for the modulator
byte algorithm = mod.algorithm ? 1 : 0;
setRegister(0xC0 + voice, (mod.feedback << 1) | algorithm);
}
void MidiDriver_AdLib::setOperator(int reg, AdLibOperator &op) {
setRegister(0x40 + reg, (op.kbScaleLevel << 6) | op.totalLevel);
setRegister(0x60 + reg, (op.attackRate << 4) | op.decayRate);
setRegister(0x80 + reg, (op.sustainLevel << 4) | op.releaseRate);
setRegister(0x20 + reg, (op.amplitudeMod << 7) | (op.vibrato << 6)
| (op.envelopeType << 5) | (op.kbScaleRate << 4) | op.frequencyMult);
setRegister(0xE0 + reg, op.waveForm);
}
void MidiDriver_AdLib::setRegister(int reg, int value, int channels) {
if (channels & kLeftChannel) {
_opl->write(0x220, reg);
_opl->write(0x221, value);
}
if (_stereo) {
if (channels & kRightChannel) {
_opl->write(0x222, reg);
_opl->write(0x223, value);
}
}
}
void MidiDriver_AdLib::playSwitch(bool play) {
_playSwitch = play;
renewNotes(-1, play);
}
bool MidiDriver_AdLib::loadResource(const SciSpan<const byte> &data) {
const uint32 size = data.size();
if (size != 1344 && size != 2690 && size != 5382) {
warning("ADLIB: Unsupported patch format (%u bytes)", size);
return false;
}
for (int i = 0; i < 48; i++)
loadInstrument(data.subspan(28 * i));
if (size == 1344) {
byte dummy[28] = {0};
// Only 48 instruments, add dummies
for (int i = 0; i < 48; i++)
loadInstrument(SciSpan<const byte>(dummy, sizeof(dummy)));
} else if (size == 2690) {
for (int i = 48; i < 96; i++)
loadInstrument(data.subspan(2 + (28 * i)));
} else {
// SCI1.1 and later
for (int i = 48; i < 190; i++) {
loadInstrument(data.subspan(28 * i));
}
_rhythmKeyMap->allocateFromSpan(data.subspan(5320, kRhythmKeys));
}
return true;
}
uint32 MidiDriver_AdLib::property(int prop, uint32 param) {
switch(prop) {
case MIDI_PROP_MASTER_VOLUME:
if (param != 0xffff)
_masterVolume = param;
return _masterVolume;
default:
break;
}
return 0;
}
int MidiPlayer_AdLib::open() {
// Load up the patch.003 file, parse out the instruments
SciResource *res = getMidiPatchData(3);
bool ok = false;
if (res) {
ok = static_cast<MidiDriver_AdLib *>(_driver)->loadResource(*res);
delete res;
// WORKAROUND: The Willy Beamish interactive demo has empty Adlib patch
// data. Ignore the failure there.
const DgdsEngine *engine = DgdsEngine::getInstance();
if (!ok && engine->getGameId() == GID_WILLY && engine->isDemo()) {
warning("No ADLIB sound available for Willy Beamish demo");
ok = true;
}
} else {
// Early SCI0 games have the sound bank embedded in the AdLib driver
Common::File f;
if (f.open("ADL.DRV")) {
int size = f.size();
const uint patchSize = 1344;
// Note: Funseeker's Guide also has another version of adl.drv, 8803 bytes.
// This isn't supported, but it's not really used anywhere, as that demo
// doesn't have sound anyway.
if (size == 5684 || size == 5720 || size == 5727) {
ok = f.seek(0x45a);
if (ok) {
Common::SpanOwner<SciSpan<const byte> > patchData;
patchData->allocateFromStream(f, patchSize);
ok = static_cast<MidiDriver_AdLib *>(_driver)->loadResource(*patchData);
}
}
}
}
if (!ok) {
warning("ADLIB: Failed to load patch.003");
return -1;
}
return static_cast<MidiDriver_AdLib *>(_driver)->openAdLib();
}
void MidiPlayer_AdLib::close() {
if (_driver) {
_driver->close();
}
}
byte MidiPlayer_AdLib::getPlayId() const {
return 0x00;
}
MidiPlayer *MidiPlayer_AdLib_create() {
return new MidiPlayer_AdLib();
}
} // End of namespace Dgds

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,667 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "sci/sci.h"
#include "common/file.h"
#include "common/system.h"
#include "common/textconsole.h"
#include "audio/softsynth/fmtowns_pc98/towns_audio.h"
#include "sci/sound/resource/sci_resource.h"
#include "sci/sound/drivers/mididriver.h"
namespace Dgds {
class MidiDriver_FMTowns;
class TownsChannel {
public:
TownsChannel(MidiDriver_FMTowns *driver, uint8 id);
~TownsChannel() {}
void noteOff();
void noteOn(uint8 note, uint8 velo);
void pitchBend(int16 val);
void updateVolume();
void updateDuration();
uint8 _assign;
uint8 _note;
uint8 _sustain;
uint16 _duration;
private:
uint8 _id;
uint8 _velo;
uint8 _program;
MidiDriver_FMTowns *_drv;
};
class TownsMidiPart {
friend class MidiDriver_FMTowns;
public:
TownsMidiPart(MidiDriver_FMTowns *driver, uint8 id);
~TownsMidiPart() {}
void noteOff(uint8 note);
void noteOn(uint8 note, uint8 velo);
void controlChangeVolume(uint8 vol);
void controlChangeSustain(uint8 sus);
void controlChangePolyphony(uint8 numChan);
void controlChangeAllNotesOff();
void programChange(uint8 prg);
void pitchBend(int16 val);
void addChannels(int num);
void dropChannels(int num);
uint8 currentProgram() const;
private:
int allocateChannel();
uint8 _id;
uint8 _program;
uint8 _volume;
uint8 _sustain;
uint8 _chanMissing;
int16 _pitchBend;
uint8 _outChan;
MidiDriver_FMTowns *_drv;
};
class MidiDriver_FMTowns : public MidiDriver, public TownsAudioInterfacePluginDriver {
friend class TownsChannel;
friend class TownsMidiPart;
public:
MidiDriver_FMTowns(Audio::Mixer *mixer, SciVersion version);
~MidiDriver_FMTowns() override;
int open() override;
void loadInstruments(const SciSpan<const uint8> &data);
bool isOpen() const override { return _isOpen; }
void close() override;
void send(uint32 b) override;
uint32 property(int prop, uint32 param) override;
void setTimerCallback(void *timer_param, Common::TimerManager::TimerProc timer_proc) override;
void setSoundOn(bool toggle);
uint32 getBaseTempo() override;
MidiChannel *allocateChannel() override { return nullptr; }
MidiChannel *getPercussionChannel() override { return nullptr; }
void timerCallback(int timerId) override;
private:
int getChannelVolume(uint8 midiPart);
void addMissingChannels();
void updateParser();
void updateChannels();
Common::TimerManager::TimerProc _timerProc;
void *_timerProcPara;
TownsMidiPart **_parts;
TownsChannel **_out;
uint8 _masterVolume;
bool _soundOn;
bool _isOpen;
bool _ready;
const uint16 _baseTempo;
SciVersion _version;
TownsAudioInterface *_intf;
};
class MidiPlayer_FMTowns : public MidiPlayer {
public:
MidiPlayer_FMTowns(SciVersion version);
~MidiPlayer_FMTowns() override;
int open(ResourceManager *resMan) override;
bool hasRhythmChannel() const override;
byte getPlayId() const override;
int getPolyphony() const override;
void playSwitch(bool play) override;
private:
MidiDriver_FMTowns *_townsDriver;
};
TownsChannel::TownsChannel(MidiDriver_FMTowns *driver, uint8 id) : _drv(driver), _id(id), _assign(0xff), _note(0xff), _velo(0), _sustain(0), _duration(0), _program(0xff) {
}
void TownsChannel::noteOn(uint8 note, uint8 velo) {
_duration = 0;
if (_drv->_version != SCI_VERSION_1_EARLY) {
if (_program != _drv->_parts[_assign]->currentProgram() && _drv->_soundOn) {
_program = _drv->_parts[_assign]->currentProgram();
_drv->_intf->callback(4, _id, _program);
}
}
_note = note;
_velo = velo;
_drv->_intf->callback(1, _id, _note, _velo);
}
void TownsChannel::noteOff() {
if (_sustain)
return;
_drv->_intf->callback(2, _id);
_note = 0xff;
_duration = 0;
}
void TownsChannel::pitchBend(int16 val) {
_drv->_intf->callback(7, _id, val);
}
void TownsChannel::updateVolume() {
if (_assign > 15 && _drv->_version != SCI_VERSION_1_EARLY)
return;
_drv->_intf->callback(8, _id, _drv->getChannelVolume((_drv->_version == SCI_VERSION_1_EARLY) ? 0 : _assign));
}
void TownsChannel::updateDuration() {
if (_note != 0xff)
_duration++;
}
TownsMidiPart::TownsMidiPart(MidiDriver_FMTowns *driver, uint8 id) : _drv(driver), _id(id), _program(0), _volume(0x3f), _sustain(0), _chanMissing(0), _pitchBend(0x2000), _outChan(0) {
}
void TownsMidiPart::noteOff(uint8 note) {
for (int i = 0; i < 6; i++) {
if ((_drv->_out[i]->_assign != _id && _drv->_version != SCI_VERSION_1_EARLY) || _drv->_out[i]->_note != note)
continue;
if (_sustain)
_drv->_out[i]->_sustain = 1;
else
_drv->_out[i]->noteOff();
return;
}
}
void TownsMidiPart::noteOn(uint8 note, uint8 velo) {
if (note < 12 || note > 107)
return;
if (velo == 0) {
noteOff(note);
return;
}
if (_drv->_version != SCI_VERSION_1_EARLY)
velo >>= 1;
for (int i = 0; i < 6; i++) {
if ((_drv->_out[i]->_assign != _id && _drv->_version != SCI_VERSION_1_EARLY) || _drv->_out[i]->_note != note)
continue;
_drv->_out[i]->_sustain = 0;
_drv->_out[i]->noteOff();
_drv->_out[i]->noteOn(note, velo);
return;
}
int chan = allocateChannel();
if (chan != -1)
_drv->_out[chan]->noteOn(note, velo);
}
void TownsMidiPart::controlChangeVolume(uint8 vol) {
if (_drv->_version == SCI_VERSION_1_EARLY)
return;
_volume = vol >> 1;
for (int i = 0; i < 6; i++) {
if (_drv->_out[i]->_assign == _id)
_drv->_out[i]->updateVolume();
}
}
void TownsMidiPart::controlChangeSustain(uint8 sus) {
if (_drv->_version == SCI_VERSION_1_EARLY)
return;
_sustain = sus;
if (_sustain)
return;
for (int i = 0; i < 6; i++) {
if (_drv->_out[i]->_assign == _id && _drv->_out[i]->_sustain) {
_drv->_out[i]->_sustain = 0;
_drv->_out[i]->noteOff();
}
}
}
void TownsMidiPart::controlChangePolyphony(uint8 numChan) {
if (_drv->_version == SCI_VERSION_1_EARLY)
return;
uint8 numAssigned = 0;
for (int i = 0; i < 6; i++) {
if (_drv->_out[i]->_assign == _id)
numAssigned++;
}
numAssigned += _chanMissing;
if (numAssigned < numChan) {
addChannels(numChan - numAssigned);
} else if (numAssigned > numChan) {
dropChannels(numAssigned - numChan);
_drv->addMissingChannels();
}
}
void TownsMidiPart::controlChangeAllNotesOff() {
for (int i = 0; i < 6; i++) {
if ((_drv->_out[i]->_assign == _id || _drv->_version == SCI_VERSION_1_EARLY) && _drv->_out[i]->_note != 0xff)
_drv->_out[i]->noteOff();
}
}
void TownsMidiPart::programChange(uint8 prg) {
_program = prg;
}
void TownsMidiPart::pitchBend(int16 val) {
_pitchBend = val;
val -= 0x2000;
for (int i = 0; i < 6; i++) {
// Strangely, the early version driver applies the setting to channel 0 only.
if (_drv->_out[i]->_assign == _id || (_drv->_version == SCI_VERSION_1_EARLY && i == 0))
_drv->_out[i]->pitchBend(val);
}
}
void TownsMidiPart::addChannels(int num) {
for (int i = 0; i < 6; i++) {
if (_drv->_out[i]->_assign != 0xff)
continue;
_drv->_out[i]->_assign = _id;
_drv->_out[i]->updateVolume();
if (_drv->_out[i]->_note != 0xff)
_drv->_out[i]->noteOff();
if (!--num)
break;
}
_chanMissing += num;
programChange(_program);
pitchBend(_pitchBend);
controlChangeVolume(_volume << 1);
}
void TownsMidiPart::dropChannels(int num) {
if (_chanMissing == num) {
_chanMissing = 0;
return;
} else if (_chanMissing > num) {
_chanMissing -= num;
return;
}
num -= _chanMissing;
_chanMissing = 0;
for (int i = 0; i < 6; i++) {
if (_drv->_out[i]->_assign != _id || _drv->_out[i]->_note != 0xff)
continue;
_drv->_out[i]->_assign = 0xff;
if (!--num)
return;
}
for (int i = 0; i < 6; i++) {
if (_drv->_out[i]->_assign != _id)
continue;
_drv->_out[i]->_sustain = 0;
_drv->_out[i]->noteOff();
_drv->_out[i]->_assign = 0xff;
if (!--num)
return;
}
}
uint8 TownsMidiPart::currentProgram() const {
return _program;
}
int TownsMidiPart::allocateChannel() {
int chan = _outChan;
int ovrChan = 0;
int ld = 0;
bool found = false;
for (bool loop = true; loop; ) {
if (++chan == 6)
chan = 0;
if (chan == _outChan)
loop = false;
if (_id == _drv->_out[chan]->_assign || _drv->_version == SCI_VERSION_1_EARLY) {
if (_drv->_out[chan]->_note == 0xff) {
found = true;
break;
}
if (_drv->_out[chan]->_duration >= ld) {
ld = _drv->_out[chan]->_duration;
ovrChan = chan;
}
}
}
if (!found) {
if (!ld)
return -1;
chan = ovrChan;
_drv->_out[chan]->_sustain = 0;
_drv->_out[chan]->noteOff();
}
_outChan = chan;
return chan;
}
MidiDriver_FMTowns::MidiDriver_FMTowns(Audio::Mixer *mixer, SciVersion version) : _version(version), _timerProc(nullptr), _timerProcPara(nullptr), _baseTempo(10080), _ready(false), _isOpen(false), _masterVolume(0x0f), _soundOn(true) {
_intf = new TownsAudioInterface(mixer, this, true);
_out = new TownsChannel*[6];
for (int i = 0; i < 6; i++)
_out[i] = new TownsChannel(this, i);
_parts = new TownsMidiPart*[16];
for (int i = 0; i < 16; i++)
_parts[i] = new TownsMidiPart(this, i);
}
MidiDriver_FMTowns::~MidiDriver_FMTowns() {
delete _intf;
if (_parts) {
for (int i = 0; i < 16; i++) {
delete _parts[i];
_parts[i] = nullptr;
}
delete[] _parts;
_parts = nullptr;
}
if (_out) {
for (int i = 0; i < 6; i++) {
delete _out[i];
_out[i] = nullptr;
}
delete[] _out;
_out = nullptr;
}
}
int MidiDriver_FMTowns::open() {
if (_isOpen)
return MERR_ALREADY_OPEN;
if (!_ready) {
if (!_intf->init())
return MERR_CANNOT_CONNECT;
_intf->callback(0);
_intf->callback(21, 255, 1);
_intf->callback(21, 0, 1);
_intf->callback(22, 255, 221);
_intf->callback(33, 8);
_intf->setSoundEffectChanMask(~0x3f);
_ready = true;
}
_isOpen = true;
return 0;
}
void MidiDriver_FMTowns::loadInstruments(const SciSpan<const uint8> &data) {
enum {
fmDataSize = 48
};
if (data.size()) {
SciSpan<const uint8> instrumentData = data.subspan(6);
for (int i = 0; i < 128; i++, instrumentData += fmDataSize) {
_intf->callback(5, 0, i, instrumentData.getUnsafeDataAt(0, fmDataSize));
}
}
_intf->callback(70, 3);
property(MIDI_PROP_MASTER_VOLUME, _masterVolume);
}
void MidiDriver_FMTowns::close() {
_isOpen = false;
}
void MidiDriver_FMTowns::send(uint32 b) {
if (!_isOpen)
return;
byte para2 = (b >> 16) & 0xFF;
byte para1 = (b >> 8) & 0xFF;
byte cmd = b & 0xF0;
TownsMidiPart *chan = _parts[b & 0x0F];
switch (cmd) {
case 0x80:
chan->noteOff(para1);
break;
case 0x90:
chan->noteOn(para1, para2);
break;
case 0xb0:
switch (para1) {
case 7:
chan->controlChangeVolume(para2);
break;
case 64:
chan->controlChangeSustain(para2);
break;
case SCI_MIDI_SET_POLYPHONY:
chan->controlChangePolyphony(para2);
break;
case SCI_MIDI_CHANNEL_NOTES_OFF:
chan->controlChangeAllNotesOff();
break;
default:
break;
}
break;
case 0xc0:
chan->programChange(para1);
break;
case 0xe0:
chan->pitchBend(para1 | (para2 << 7));
break;
default:
break;
}
}
uint32 MidiDriver_FMTowns::property(int prop, uint32 param) {
switch(prop) {
case MIDI_PROP_MASTER_VOLUME:
if (param != 0xffff) {
_masterVolume = param;
for (int i = 0; i < 6; i++)
_out[i]->updateVolume();
}
return _masterVolume;
default:
break;
}
return 0;
}
void MidiDriver_FMTowns::setTimerCallback(void *timer_param, Common::TimerManager::TimerProc timer_proc) {
_timerProc = timer_proc;
_timerProcPara = timer_param;
}
void MidiDriver_FMTowns::setSoundOn(bool toggle) {
_soundOn = toggle;
}
uint32 MidiDriver_FMTowns::getBaseTempo() {
return _baseTempo;
}
void MidiDriver_FMTowns::timerCallback(int timerId) {
if (!_isOpen)
return;
switch (timerId) {
case 1:
updateParser();
updateChannels();
break;
default:
break;
}
}
int MidiDriver_FMTowns::getChannelVolume(uint8 midiPart) {
static const uint8 volumeTable[] = { 0x00, 0x0D, 0x1B, 0x28, 0x36, 0x43, 0x51, 0x5F, 0x63, 0x67, 0x6B, 0x6F, 0x73, 0x77, 0x7B, 0x7F };
int tableIndex = (_version == SCI_VERSION_1_EARLY) ? _masterVolume : (_parts[midiPart]->_volume * (_masterVolume + 1)) >> 6;
assert(tableIndex < 16);
return volumeTable[tableIndex];
}
void MidiDriver_FMTowns::addMissingChannels() {
uint8 avlChan = 0;
for (int i = 0; i < 6; i++) {
if (_out[i]->_assign == 0xff)
avlChan++;
}
if (!avlChan)
return;
for (int i = 0; i < 16; i++) {
if (!_parts[i]->_chanMissing)
continue;
if (_parts[i]->_chanMissing < avlChan) {
avlChan -= _parts[i]->_chanMissing;
uint8 m = _parts[i]->_chanMissing;
_parts[i]->_chanMissing = 0;
_parts[i]->addChannels(m);
} else {
_parts[i]->_chanMissing -= avlChan;
_parts[i]->addChannels(avlChan);
return;
}
}
}
void MidiDriver_FMTowns::updateParser() {
if (_timerProc)
_timerProc(_timerProcPara);
}
void MidiDriver_FMTowns::updateChannels() {
for (int i = 0; i < 6; i++)
_out[i]->updateDuration();
}
MidiPlayer_FMTowns::MidiPlayer_FMTowns(SciVersion version) : MidiPlayer(version) {
_driver = _townsDriver = new MidiDriver_FMTowns(g_system->getMixer(), version);
}
MidiPlayer_FMTowns::~MidiPlayer_FMTowns() {
delete _driver;
}
int MidiPlayer_FMTowns::open(ResourceManager *resMan) {
int result = MidiDriver::MERR_DEVICE_NOT_AVAILABLE;
if (_townsDriver) {
result = _townsDriver->open();
if (!result && _version == SCI_VERSION_1_LATE) {
Resource *res = resMan->findResource(ResourceId(kResourceTypePatch, 8), false);
if (res != nullptr) {
_townsDriver->loadInstruments(*res);
} else {
warning("MidiPlayer_FMTowns: Failed to open patch 8");
result = MidiDriver::MERR_DEVICE_NOT_AVAILABLE;
}
}
}
return result;
}
bool MidiPlayer_FMTowns::hasRhythmChannel() const {
return false;
}
byte MidiPlayer_FMTowns::getPlayId() const {
return (_version == SCI_VERSION_1_EARLY) ? 0x00 : 0x16;
}
int MidiPlayer_FMTowns::getPolyphony() const {
// WORKAROUND:
// I set the return value to 16 for SCI_VERSION_1_EARLY here, which fixes music playback in Mixed Up Mothergoose.
// This has been broken since the introduction of SciMusic::remapChannels() and the corresponding code.
// The original code of Mixed Up Mothergoose code doesn't have the remapping and doesn't seem to check the polyphony
// setting ever. So the value of 1 was probably incorrect.
return (_version == SCI_VERSION_1_EARLY) ? 16 : 6;
}
void MidiPlayer_FMTowns::playSwitch(bool play) {
if (_townsDriver)
_townsDriver->setSoundOn(play);
}
MidiPlayer *MidiPlayer_FMTowns_create(SciVersion _soundVersion) {
return new MidiPlayer_FMTowns(_soundVersion);
}
} // End of namespace Sci

View File

@@ -0,0 +1,223 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef DGDS_SOUND_DRIVERS_GM_NAMES_H
#define DGDS_SOUND_DRIVERS_GM_NAMES_H
namespace Dgds {
// These tables are only used for debugging. Don't include them for devices
// with not enough available memory (e.g. phones), where REDUCE_MEMORY_USAGE
// is defined
#ifndef REDUCE_MEMORY_USAGE
static const char *const GmInstrumentNames[] = {
/*000*/ "Acoustic Grand Piano",
/*001*/ "Bright Acoustic Piano",
/*002*/ "Electric Grand Piano",
/*003*/ "Honky-tonk Piano",
/*004*/ "Electric Piano 1",
/*005*/ "Electric Piano 2",
/*006*/ "Harpsichord",
/*007*/ "Clavinet",
/*008*/ "Celesta",
/*009*/ "Glockenspiel",
/*010*/ "Music Box",
/*011*/ "Vibraphone",
/*012*/ "Marimba",
/*013*/ "Xylophone",
/*014*/ "Tubular Bells",
/*015*/ "Dulcimer",
/*016*/ "Drawbar Organ",
/*017*/ "Percussive Organ",
/*018*/ "Rock Organ",
/*019*/ "Church Organ",
/*020*/ "Reed Organ",
/*021*/ "Accordion",
/*022*/ "Harmonica",
/*023*/ "Tango Accordion",
/*024*/ "Acoustic Guitar (nylon)",
/*025*/ "Acoustic Guitar (steel)",
/*026*/ "Electric Guitar (jazz)",
/*027*/ "Electric Guitar (clean)",
/*028*/ "Electric Guitar (muted)",
/*029*/ "Overdriven Guitar",
/*030*/ "Distortion Guitar",
/*031*/ "Guitar Harmonics",
/*032*/ "Acoustic Bass",
/*033*/ "Electric Bass (finger)",
/*034*/ "Electric Bass (pick)",
/*035*/ "Fretless Bass",
/*036*/ "Slap Bass 1",
/*037*/ "Slap Bass 2",
/*038*/ "Synth Bass 1",
/*039*/ "Synth Bass 2",
/*040*/ "Violin",
/*041*/ "Viola",
/*042*/ "Cello",
/*043*/ "Contrabass",
/*044*/ "Tremolo Strings",
/*045*/ "Pizzicato Strings",
/*046*/ "Orchestral Harp",
/*047*/ "Timpani",
/*048*/ "String Ensemble 1",
/*049*/ "String Ensemble 2",
/*050*/ "SynthStrings 1",
/*051*/ "SynthStrings 2",
/*052*/ "Choir Aahs",
/*053*/ "Voice Oohs",
/*054*/ "Synth Voice",
/*055*/ "Orchestra Hit",
/*056*/ "Trumpet",
/*057*/ "Trombone",
/*058*/ "Tuba",
/*059*/ "Muted Trumpet",
/*060*/ "French Horn",
/*061*/ "Brass Section",
/*062*/ "SynthBrass 1",
/*063*/ "SynthBrass 2",
/*064*/ "Soprano Sax",
/*065*/ "Alto Sax",
/*066*/ "Tenor Sax",
/*067*/ "Baritone Sax",
/*068*/ "Oboe",
/*069*/ "English Horn",
/*070*/ "Bassoon",
/*071*/ "Clarinet",
/*072*/ "Piccolo",
/*073*/ "Flute",
/*074*/ "Recorder",
/*075*/ "Pan Flute",
/*076*/ "Blown Bottle",
/*077*/ "Shakuhachi",
/*078*/ "Whistle",
/*079*/ "Ocarina",
/*080*/ "Lead 1 (square)",
/*081*/ "Lead 2 (sawtooth)",
/*082*/ "Lead 3 (calliope)",
/*083*/ "Lead 4 (chiff)",
/*084*/ "Lead 5 (charang)",
/*085*/ "Lead 6 (voice)",
/*086*/ "Lead 7 (fifths)",
/*087*/ "Lead 8 (bass+lead)",
/*088*/ "Pad 1 (new age)",
/*089*/ "Pad 2 (warm)",
/*090*/ "Pad 3 (polysynth)",
/*091*/ "Pad 4 (choir)",
/*092*/ "Pad 5 (bowed)",
/*093*/ "Pad 6 (metallic)",
/*094*/ "Pad 7 (halo)",
/*095*/ "Pad 8 (sweep)",
/*096*/ "FX 1 (rain)",
/*097*/ "FX 2 (soundtrack)",
/*098*/ "FX 3 (crystal)",
/*099*/ "FX 4 (atmosphere)",
/*100*/ "FX 5 (brightness)",
/*101*/ "FX 6 (goblins)",
/*102*/ "FX 7 (echoes)",
/*103*/ "FX 8 (sci-fi)",
/*104*/ "Sitar",
/*105*/ "Banjo",
/*106*/ "Shamisen",
/*107*/ "Koto",
/*108*/ "Kalimba",
/*109*/ "Bag pipe",
/*110*/ "Fiddle",
/*111*/ "Shannai",
/*112*/ "Tinkle Bell",
/*113*/ "Agogo",
/*114*/ "Steel Drums",
/*115*/ "Woodblock",
/*116*/ "Taiko Drum",
/*117*/ "Melodic Tom",
/*118*/ "Synth Drum",
/*119*/ "Reverse Cymbal",
/*120*/ "Guitar Fret Noise",
/*121*/ "Breath Noise",
/*122*/ "Seashore",
/*123*/ "Bird Tweet",
/*124*/ "Telephone Ring",
/*125*/ "Helicopter",
/*126*/ "Applause",
/*127*/ "Gunshot"
};
// The GM Percussion map is downwards compatible to the MT32 map, which is used in SCI
static const char *const GmPercussionNames[] = {
/*00*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/*10*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/*20*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/*30*/ 0, 0, 0, 0, 0,
// The preceding percussions are not covered by the GM standard
/*35*/ "Acoustic Bass Drum",
/*36*/ "Bass Drum 1",
/*37*/ "Side Stick",
/*38*/ "Acoustic Snare",
/*39*/ "Hand Clap",
/*40*/ "Electric Snare",
/*41*/ "Low Floor Tom",
/*42*/ "Closed Hi-Hat",
/*43*/ "High Floor Tom",
/*44*/ "Pedal Hi-Hat",
/*45*/ "Low Tom",
/*46*/ "Open Hi-Hat",
/*47*/ "Low-Mid Tom",
/*48*/ "Hi-Mid Tom",
/*49*/ "Crash Cymbal 1",
/*50*/ "High Tom",
/*51*/ "Ride Cymbal 1",
/*52*/ "Chinese Cymbal",
/*53*/ "Ride Bell",
/*54*/ "Tambourine",
/*55*/ "Splash Cymbal",
/*56*/ "Cowbell",
/*57*/ "Crash Cymbal 2",
/*58*/ "Vibraslap",
/*59*/ "Ride Cymbal 2",
/*60*/ "Hi Bongo",
/*61*/ "Low Bongo",
/*62*/ "Mute Hi Conga",
/*63*/ "Open Hi Conga",
/*64*/ "Low Conga",
/*65*/ "High Timbale",
/*66*/ "Low Timbale",
/*67*/ "High Agogo",
/*68*/ "Low Agogo",
/*69*/ "Cabasa",
/*70*/ "Maracas",
/*71*/ "Short Whistle",
/*72*/ "Long Whistle",
/*73*/ "Short Guiro",
/*74*/ "Long Guiro",
/*75*/ "Claves",
/*76*/ "Hi Wood Block",
/*77*/ "Low Wood Block",
/*78*/ "Mute Cuica",
/*79*/ "Open Cuica",
/*80*/ "Mute Triangle",
/*81*/ "Open Triangle"
};
#endif // REDUCE_MEMORY_USAGE
} // End of namespace Dgds
#endif // DGDS_SOUND_DRIVERS_GM_NAMES_H

View File

@@ -0,0 +1,272 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "audio/audiostream.h"
#include "audio/mixer.h"
#include "common/frac.h"
#include "common/mutex.h"
#include "common/system.h"
#ifndef DGDS_SOUND_DRIVERS_MACMIXER_H
#define DGDS_SOUND_DRIVERS_MACMIXER_H
namespace Dgds {
// Unsigned version of frac_t
typedef uint32 ufrac_t;
static inline ufrac_t uintToUfrac(uint16 value) { return value << FRAC_BITS; }
static inline uint16 ufracToUint(ufrac_t value) { return value >> FRAC_BITS; }
template <typename T>
class Mixer_Mac : public Audio::AudioStream {
public:
enum {
kChannels = 4,
kInterruptFreq = 60
};
enum Mode {
kModeAuthentic,
kModeHq,
kModeHqStereo
};
Mixer_Mac(Mode mode);
void startMixer();
void stopMixer();
void setMixerVolume(byte volume) { _mixVolume = volume; }
void resetChannel(uint channel);
void resetChannels();
// NOTE: Last sample accessed is data[endOffset + 1] in kModeHq(Stereo)
void setChannelData(uint channel, const byte *data, uint16 startOffset, uint16 endOffset, uint16 loopLength = 0);
void setChannelStep(uint channel, ufrac_t step);
void setChannelVolume(uint channel, byte volume);
void setChannelPan(uint channel, byte pan);
// AudioStream
bool isStereo() const override { return _mode == kModeHqStereo; }
int getRate() const override { return (_mode == kModeAuthentic ? 11127 : g_system->getMixer()->getOutputRate()); }
int readBuffer(int16 *data, const int numSamples) override;
bool endOfData() const override { return false; }
Common::Mutex _mutex;
private:
template <Mode mode>
void generateSamples(int16 *buf, int len);
struct Channel {
ufrac_t pos;
ufrac_t step;
const byte *data;
uint16 endOffset;
uint16 loopLength;
byte volume;
int8 pan;
};
ufrac_t _nextTick;
ufrac_t _samplesPerTick;
bool _isPlaying;
const Mode _mode;
Channel _mixChannels[kChannels];
byte _mixVolume;
};
template <typename T>
Mixer_Mac<T>::Mixer_Mac(Mode mode) :
_nextTick(0),
_samplesPerTick(0),
_mode(mode),
_isPlaying(false),
_mixChannels(),
_mixVolume(8) {}
template <typename T>
void Mixer_Mac<T>::startMixer() {
_nextTick = _samplesPerTick = uintToUfrac(getRate() / kInterruptFreq) + uintToUfrac(getRate() % kInterruptFreq) / kInterruptFreq;
resetChannels();
_isPlaying = true;
}
template <typename T>
void Mixer_Mac<T>::stopMixer() {
resetChannels();
_isPlaying = false;
}
template <typename T>
void Mixer_Mac<T>::setChannelData(uint channel, const byte *data, uint16 startOffset, uint16 endOffset, uint16 loopLength) {
assert(channel < kChannels);
Channel &ch = _mixChannels[channel];
ch.data = data;
ch.pos = uintToUfrac(startOffset);
ch.endOffset = endOffset;
ch.loopLength = loopLength;
}
template <typename T>
void Mixer_Mac<T>::setChannelStep(uint channel, ufrac_t step) {
assert(channel < kChannels);
if (_mode == kModeAuthentic) {
_mixChannels[channel].step = step;
} else {
// We could take 11127Hz here, but it appears the original steps were
// computed for 11000Hz
// FIXME: One or two more bits of step precision might be nice here
_mixChannels[channel].step = (ufrac_t)(step * 11000ULL / getRate());
}
}
template <typename T>
void Mixer_Mac<T>::setChannelVolume(uint channel, byte volume) {
assert(channel < kChannels);
_mixChannels[channel].volume = volume;
}
template <typename T>
void Mixer_Mac<T>::setChannelPan(uint channel, byte pan) {
assert(channel < kChannels);
_mixChannels[channel].pan = pan;
}
template <typename T>
template <typename Mixer_Mac<T>::Mode mode>
void Mixer_Mac<T>::generateSamples(int16 *data, int len) {
for (int i = 0; i < len; ++i) {
int32 mixL = 0;
int32 mixR = 0;
for (int ci = 0; ci < kChannels; ++ci) {
Channel &ch = _mixChannels[ci];
if (!ch.data)
continue;
const uint16 curOffset = ufracToUint(ch.pos);
if (mode == kModeHq || mode == kModeHqStereo) {
int32 sample = (ch.data[curOffset] - 0x80) << 8;
// Since _extraSamples > 0, we can safely access this sample
const int32 sample2 = (ch.data[curOffset + 1] - 0x80) << 8;
sample += fracToInt((sample2 - sample) * (ch.pos & FRAC_LO_MASK));
sample *= ch.volume;
if (mode == kModeHqStereo) {
mixL += sample * (127 - ch.pan) / (63 * 64);
mixR += sample * ch.pan / (63 * 64);
} else {
mixL += sample / 63;
}
} else {
mixL += static_cast<T *>(this)->applyChannelVolume(ch.volume, ch.data[curOffset]) << 8;
}
ch.pos += ch.step;
if (ufracToUint(ch.pos) > ch.endOffset) {
if (ch.loopLength > 0) {
do {
ch.pos -= uintToUfrac(ch.loopLength);
} while (ufracToUint(ch.pos) > ch.endOffset);
} else {
static_cast<T *>(this)->onChannelFinished(ci);
ch.data = nullptr;
}
}
}
*data++ = (int16)CLIP<int32>(mixL, -32768, 32767) * _mixVolume / 8;
if (mode == kModeHqStereo)
*data++ = (int16)CLIP<int32>(mixR, -32768, 32767) * _mixVolume / 8;
}
}
template <typename T>
int Mixer_Mac<T>::readBuffer(int16 *data, const int numSamples) {
// Would probably be better inside generateSamples, but let's follow Audio::Paula
Common::StackLock lock(_mutex);
if (!_isPlaying) {
memset(data, 0, numSamples * 2);
return numSamples;
}
const int stereoFactor = isStereo() ? 2 : 1;
int len = numSamples / stereoFactor;
do {
int step = len;
if (step > ufracToUint(_nextTick))
step = ufracToUint(_nextTick);
switch (_mode) {
case kModeAuthentic:
generateSamples<kModeAuthentic>(data, step);
break;
case kModeHq:
generateSamples<kModeHq>(data, step);
break;
case kModeHqStereo:
generateSamples<kModeHqStereo>(data, step);
}
_nextTick -= uintToUfrac(step);
if (ufracToUint(_nextTick) == 0) {
static_cast<T *>(this)->interrupt();
_nextTick += _samplesPerTick;
}
data += step * stereoFactor;
len -= step;
} while (len);
return numSamples;
}
template <typename T>
void Mixer_Mac<T>::resetChannel(uint channel) {
assert(channel < kChannels);
Channel &ch = _mixChannels[channel];
ch.pos = 0;
ch.step = 0;
ch.data = nullptr;
ch.endOffset = 0;
ch.loopLength = 0;
ch.volume = 0;
ch.pan = 64;
}
template <typename T>
void Mixer_Mac<T>::resetChannels() {
for (uint ci = 0; ci < kChannels; ++ci)
resetChannel(ci);
}
} // End of namespace Dgds
#endif // DGDS_SOUND_DRIVERS_MACMIXER_H

View File

@@ -0,0 +1,371 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef DGDS_SOUND_DRIVERS_MAP_MT32_TO_GM_H
#define DGDS_SOUND_DRIVERS_MAP_MT32_TO_GM_H
namespace Dgds {
// Patch not mapped
#define MIDI_UNMAPPED 0xff
// Patch mapped to rhythm key
#define MIDI_MAPPED_TO_RHYTHM 0xfe
struct Mt32ToGmMap {
const char *name;
uint8 gmInstr;
uint8 gmRhythmKey;
};
/*******************************************
* Fancy instrument mappings begin here... *
*******************************************/
static const Mt32ToGmMap Mt32PresetTimbreMaps[] = {
/*000*/ {"AcouPiano1", 0, MIDI_UNMAPPED},
/*001*/ {"AcouPiano2", 1, MIDI_UNMAPPED},
/*002*/ {"AcouPiano3", 0, MIDI_UNMAPPED},
/*003*/ {"ElecPiano1", 4, MIDI_UNMAPPED},
/*004*/ {"ElecPiano2", 5, MIDI_UNMAPPED},
/*005*/ {"ElecPiano3", 4, MIDI_UNMAPPED},
/*006*/ {"ElecPiano4", 5, MIDI_UNMAPPED},
/*007*/ {"Honkytonk ", 3, MIDI_UNMAPPED},
/*008*/ {"Elec Org 1", 16, MIDI_UNMAPPED},
/*009*/ {"Elec Org 2", 17, MIDI_UNMAPPED},
/*010*/ {"Elec Org 3", 18, MIDI_UNMAPPED},
/*011*/ {"Elec Org 4", 18, MIDI_UNMAPPED},
/*012*/ {"Pipe Org 1", 19, MIDI_UNMAPPED},
/*013*/ {"Pipe Org 2", 19, MIDI_UNMAPPED},
/*014*/ {"Pipe Org 3", 20, MIDI_UNMAPPED},
/*015*/ {"Accordion ", 21, MIDI_UNMAPPED},
/*016*/ {"Harpsi 1 ", 6, MIDI_UNMAPPED},
/*017*/ {"Harpsi 2 ", 6, MIDI_UNMAPPED},
/*018*/ {"Harpsi 3 ", 6, MIDI_UNMAPPED},
/*019*/ {"Clavi 1 ", 7, MIDI_UNMAPPED},
/*020*/ {"Clavi 2 ", 7, MIDI_UNMAPPED},
/*021*/ {"Clavi 3 ", 7, MIDI_UNMAPPED},
/*022*/ {"Celesta 1 ", 8, MIDI_UNMAPPED},
/*023*/ {"Celesta 2 ", 8, MIDI_UNMAPPED},
/*024*/ {"Syn Brass1", 62, MIDI_UNMAPPED},
/*025*/ {"Syn Brass2", 63, MIDI_UNMAPPED},
/*026*/ {"Syn Brass3", 62, MIDI_UNMAPPED},
/*027*/ {"Syn Brass4", 63, MIDI_UNMAPPED},
/*028*/ {"Syn Bass 1", 38, MIDI_UNMAPPED},
/*029*/ {"Syn Bass 2", 39, MIDI_UNMAPPED},
/*030*/ {"Syn Bass 3", 38, MIDI_UNMAPPED},
/*031*/ {"Syn Bass 4", 39, MIDI_UNMAPPED},
/*032*/ {"Fantasy ", 88, MIDI_UNMAPPED},
/*033*/ {"Harmo Pan ", 89, MIDI_UNMAPPED},
/*034*/ {"Chorale ", 52, MIDI_UNMAPPED},
/*035*/ {"Glasses ", 98, MIDI_UNMAPPED},
/*036*/ {"Soundtrack", 97, MIDI_UNMAPPED},
/*037*/ {"Atmosphere", 99, MIDI_UNMAPPED},
/*038*/ {"Warm Bell ", 89, MIDI_UNMAPPED},
/*039*/ {"Funny Vox ", 85, MIDI_UNMAPPED},
/*040*/ {"Echo Bell ", 39, MIDI_UNMAPPED},
/*041*/ {"Ice Rain ", 101, MIDI_UNMAPPED},
/*042*/ {"Oboe 2001 ", 68, MIDI_UNMAPPED},
/*043*/ {"Echo Pan ", 87, MIDI_UNMAPPED},
/*044*/ {"DoctorSolo", 86, MIDI_UNMAPPED},
/*045*/ {"Schooldaze", 103, MIDI_UNMAPPED},
/*046*/ {"BellSinger", 88, MIDI_UNMAPPED},
/*047*/ {"SquareWave", 80, MIDI_UNMAPPED},
/*048*/ {"Str Sect 1", 48, MIDI_UNMAPPED},
/*049*/ {"Str Sect 2", 48, MIDI_UNMAPPED},
/*050*/ {"Str Sect 3", 49, MIDI_UNMAPPED},
/*051*/ {"Pizzicato ", 45, MIDI_UNMAPPED},
/*052*/ {"Violin 1 ", 40, MIDI_UNMAPPED},
/*053*/ {"Violin 2 ", 40, MIDI_UNMAPPED},
/*054*/ {"Cello 1 ", 42, MIDI_UNMAPPED},
/*055*/ {"Cello 2 ", 42, MIDI_UNMAPPED},
/*056*/ {"Contrabass", 43, MIDI_UNMAPPED},
/*057*/ {"Harp 1 ", 46, MIDI_UNMAPPED},
/*058*/ {"Harp 2 ", 46, MIDI_UNMAPPED},
/*059*/ {"Guitar 1 ", 24, MIDI_UNMAPPED},
/*060*/ {"Guitar 2 ", 25, MIDI_UNMAPPED},
/*061*/ {"Elec Gtr 1", 26, MIDI_UNMAPPED},
/*062*/ {"Elec Gtr 2", 27, MIDI_UNMAPPED},
/*063*/ {"Sitar ", 104, MIDI_UNMAPPED},
/*064*/ {"Acou Bass1", 32, MIDI_UNMAPPED},
/*065*/ {"Acou Bass2", 33, MIDI_UNMAPPED},
/*066*/ {"Elec Bass1", 34, MIDI_UNMAPPED},
/*067*/ {"Elec Bass2", 39, MIDI_UNMAPPED},
/*068*/ {"Slap Bass1", 36, MIDI_UNMAPPED},
/*069*/ {"Slap Bass2", 37, MIDI_UNMAPPED},
/*070*/ {"Fretless 1", 35, MIDI_UNMAPPED},
/*071*/ {"Fretless 2", 35, MIDI_UNMAPPED},
/*072*/ {"Flute 1 ", 73, MIDI_UNMAPPED},
/*073*/ {"Flute 2 ", 73, MIDI_UNMAPPED},
/*074*/ {"Piccolo 1 ", 72, MIDI_UNMAPPED},
/*075*/ {"Piccolo 2 ", 72, MIDI_UNMAPPED},
/*076*/ {"Recorder ", 74, MIDI_UNMAPPED},
/*077*/ {"Panpipes ", 75, MIDI_UNMAPPED},
/*078*/ {"Sax 1 ", 64, MIDI_UNMAPPED},
/*079*/ {"Sax 2 ", 65, MIDI_UNMAPPED},
/*080*/ {"Sax 3 ", 66, MIDI_UNMAPPED},
/*081*/ {"Sax 4 ", 67, MIDI_UNMAPPED},
/*082*/ {"Clarinet 1", 71, MIDI_UNMAPPED},
/*083*/ {"Clarinet 2", 71, MIDI_UNMAPPED},
/*084*/ {"Oboe ", 68, MIDI_UNMAPPED},
/*085*/ {"Engl Horn ", 69, MIDI_UNMAPPED},
/*086*/ {"Bassoon ", 70, MIDI_UNMAPPED},
/*087*/ {"Harmonica ", 22, MIDI_UNMAPPED},
/*088*/ {"Trumpet 1 ", 56, MIDI_UNMAPPED},
/*089*/ {"Trumpet 2 ", 56, MIDI_UNMAPPED},
/*090*/ {"Trombone 1", 57, MIDI_UNMAPPED},
/*091*/ {"Trombone 2", 57, MIDI_UNMAPPED},
/*092*/ {"Fr Horn 1 ", 60, MIDI_UNMAPPED},
/*093*/ {"Fr Horn 2 ", 60, MIDI_UNMAPPED},
/*094*/ {"Tuba ", 58, MIDI_UNMAPPED},
/*095*/ {"Brs Sect 1", 61, MIDI_UNMAPPED},
/*096*/ {"Brs Sect 2", 61, MIDI_UNMAPPED},
/*097*/ {"Vibe 1 ", 11, MIDI_UNMAPPED},
/*098*/ {"Vibe 2 ", 11, MIDI_UNMAPPED},
/*099*/ {"Syn Mallet", 15, MIDI_UNMAPPED},
/*100*/ {"Wind Bell ", 88, MIDI_UNMAPPED},
/*101*/ {"Glock ", 9, MIDI_UNMAPPED},
/*102*/ {"Tube Bell ", 14, MIDI_UNMAPPED},
/*103*/ {"Xylophone ", 13, MIDI_UNMAPPED},
/*104*/ {"Marimba ", 12, MIDI_UNMAPPED},
/*105*/ {"Koto ", 107, MIDI_UNMAPPED},
/*106*/ {"Sho ", 111, MIDI_UNMAPPED},
/*107*/ {"Shakuhachi", 77, MIDI_UNMAPPED},
/*108*/ {"Whistle 1 ", 78, MIDI_UNMAPPED},
/*109*/ {"Whistle 2 ", 78, MIDI_UNMAPPED},
/*110*/ {"BottleBlow", 76, MIDI_UNMAPPED},
/*111*/ {"BreathPipe", 121, MIDI_UNMAPPED},
/*112*/ {"Timpani ", 47, MIDI_UNMAPPED},
/*113*/ {"MelodicTom", 117, MIDI_UNMAPPED},
/*114*/ {"Deep Snare", MIDI_MAPPED_TO_RHYTHM, 38},
/*115*/ {"Elec Perc1", 115, MIDI_UNMAPPED}, // ?
/*116*/ {"Elec Perc2", 118, MIDI_UNMAPPED}, // ?
/*117*/ {"Taiko ", 116, MIDI_UNMAPPED},
/*118*/ {"Taiko Rim ", 118, MIDI_UNMAPPED},
/*119*/ {"Cymbal ", MIDI_MAPPED_TO_RHYTHM, 51},
/*120*/ {"Castanets ", MIDI_MAPPED_TO_RHYTHM, 75}, // approximation
/*121*/ {"Triangle ", 112, MIDI_UNMAPPED},
/*122*/ {"Orche Hit ", 55, MIDI_UNMAPPED},
/*123*/ {"Telephone ", 124, MIDI_UNMAPPED},
/*124*/ {"Bird Tweet", 123, MIDI_UNMAPPED},
/*125*/ {"OneNoteJam", 8, MIDI_UNMAPPED}, // approximation
/*126*/ {"WaterBells", 98, MIDI_UNMAPPED},
/*127*/ {"JungleTune", 75, MIDI_UNMAPPED} // approximation
};
static const Mt32ToGmMap Mt32RhythmTimbreMaps[] = {
/*00*/ {"Acou BD ", MIDI_MAPPED_TO_RHYTHM, 35},
/*01*/ {"Acou SD ", MIDI_MAPPED_TO_RHYTHM, 38},
/*02*/ {"Acou HiTom", 117, 50},
/*03*/ {"AcouMidTom", 117, 47},
/*04*/ {"AcouLowTom", 117, 41},
/*05*/ {"Elec SD ", MIDI_MAPPED_TO_RHYTHM, 40},
/*06*/ {"Clsd HiHat", MIDI_MAPPED_TO_RHYTHM, 42},
/*07*/ {"OpenHiHat1", MIDI_MAPPED_TO_RHYTHM, 46},
/*08*/ {"Crash Cym ", MIDI_MAPPED_TO_RHYTHM, 49},
/*09*/ {"Ride Cym ", MIDI_MAPPED_TO_RHYTHM, 51},
/*10*/ {"Rim Shot ", MIDI_MAPPED_TO_RHYTHM, 37},
/*11*/ {"Hand Clap ", MIDI_MAPPED_TO_RHYTHM, 39},
/*12*/ {"Cowbell ", MIDI_MAPPED_TO_RHYTHM, 56},
/*13*/ {"Mt HiConga", MIDI_MAPPED_TO_RHYTHM, 62},
/*14*/ {"High Conga", MIDI_MAPPED_TO_RHYTHM, 63},
/*15*/ {"Low Conga ", MIDI_MAPPED_TO_RHYTHM, 64},
/*16*/ {"Hi Timbale", MIDI_MAPPED_TO_RHYTHM, 65},
/*17*/ {"LowTimbale", MIDI_MAPPED_TO_RHYTHM, 66},
/*18*/ {"High Bongo", MIDI_MAPPED_TO_RHYTHM, 60},
/*19*/ {"Low Bongo ", MIDI_MAPPED_TO_RHYTHM, 61},
/*20*/ {"High Agogo", 113, 67},
/*21*/ {"Low Agogo ", 113, 68},
/*22*/ {"Tambourine", MIDI_MAPPED_TO_RHYTHM, 54},
/*23*/ {"Claves ", MIDI_MAPPED_TO_RHYTHM, 75},
/*24*/ {"Maracas ", MIDI_MAPPED_TO_RHYTHM, 70},
/*25*/ {"SmbaWhis L", 78, 72},
/*26*/ {"SmbaWhis S", 78, 71},
/*27*/ {"Cabasa ", MIDI_MAPPED_TO_RHYTHM, 69},
/*28*/ {"Quijada ", MIDI_MAPPED_TO_RHYTHM, 73},
/*29*/ {"OpenHiHat2", MIDI_MAPPED_TO_RHYTHM, 44}
};
static const uint8 Mt32PresetRhythmKeymap[] = {
MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED,
MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED,
MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED,
MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
50, 51, MIDI_UNMAPPED, MIDI_UNMAPPED, 54, MIDI_UNMAPPED, 56, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
70, 71, 72, 73, MIDI_UNMAPPED, 75, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED,
MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED,
MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED,
MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED,
MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED,
MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED, MIDI_UNMAPPED
};
/* +++ - Don't change unless you've got a good reason
++ - Looks good, sounds ok
+ - Not too bad, but is it right?
? - Where do I map this one?
?? - Any good ideas?
??? - I'm clueless?
R - Rhythm...
*/
static const Mt32ToGmMap Mt32MemoryTimbreMaps[] = {
{"AccPnoKA2 ", 1, MIDI_UNMAPPED}, // ++ (KQ1)
{"Acou BD ", MIDI_MAPPED_TO_RHYTHM, 35}, // R (PQ2)
{"Acou SD ", MIDI_MAPPED_TO_RHYTHM, 38}, // R (PQ2)
{"AcouPnoKA ", 0, MIDI_UNMAPPED}, // ++ (KQ1)
{"BASS ", 32, MIDI_UNMAPPED}, // + (LSL3)
{"BASSOONPCM", 70, MIDI_UNMAPPED}, // + (LB1)
{"BEACH WAVE", 122, MIDI_UNMAPPED}, // + (LSL3)
{"BagPipes ", 109, MIDI_UNMAPPED},
{"BassPizzMS", 45, MIDI_UNMAPPED}, // ++ (QFG1)
{"BassoonKA ", 70, MIDI_UNMAPPED}, // ++ (KQ1)
{"Bell MS", 112, MIDI_UNMAPPED}, // ++ (Iceman)
{"Bells MS", 112, MIDI_UNMAPPED}, // + (QFG1)
{"Big Bell ", 14, MIDI_UNMAPPED}, // + (LB1)
{"Bird Tweet", 123, MIDI_UNMAPPED},
{"BrsSect MS", 61, MIDI_UNMAPPED}, // +++ (Iceman)
{"CLAPPING ", 126, MIDI_UNMAPPED}, // ++ (LSL3)
{"Cabasa ", MIDI_MAPPED_TO_RHYTHM, 69}, // R (Hoyle)
{"Calliope ", 82, MIDI_UNMAPPED}, // +++ (QFG1)
{"CelticHarp", 46, MIDI_UNMAPPED}, // ++ (Camelot)
{"Chicago MS", 1, MIDI_UNMAPPED}, // ++ (Iceman)
{"Chop ", 117, MIDI_UNMAPPED},
{"Chorale MS", 52, MIDI_UNMAPPED}, // + (Camelot)
{"ClarinetMS", 71, MIDI_UNMAPPED},
{"Claves ", MIDI_MAPPED_TO_RHYTHM, 75}, // R (PQ2)
{"Claw MS", 118, MIDI_UNMAPPED}, // + (QFG1)
{"ClockBell ", 14, MIDI_UNMAPPED}, // + (LB1)
{"ConcertCym", MIDI_MAPPED_TO_RHYTHM, 55}, // R ? (KQ1)
{"Conga MS", MIDI_MAPPED_TO_RHYTHM, 64}, // R (QFG1)
{"CoolPhone ", 124, MIDI_UNMAPPED}, // ++ (LSL3)
{"CracklesMS", 115, MIDI_UNMAPPED}, // ? (Camelot, QFG1)
{"CreakyD MS", MIDI_UNMAPPED, MIDI_UNMAPPED}, // ??? (KQ1)
{"Cricket ", 120, MIDI_UNMAPPED}, // ? (LB1)
{"CrshCymbMS", MIDI_MAPPED_TO_RHYTHM, 57}, // R +++ (Iceman)
{"CstlGateMS", MIDI_UNMAPPED, MIDI_UNMAPPED}, // ? (QFG1)
{"CymSwellMS", MIDI_MAPPED_TO_RHYTHM, 55}, // R ? (Camelot, QFG1)
{"CymbRollKA", MIDI_MAPPED_TO_RHYTHM, 57}, // R ? (KQ1)
{"Cymbal Lo ", MIDI_UNMAPPED, MIDI_UNMAPPED}, // R ? (LSL3)
{"card ", MIDI_UNMAPPED, MIDI_UNMAPPED}, // ? (Hoyle)
{"DirtGtr MS", 30, MIDI_UNMAPPED}, // + (Iceman)
{"DirtGtr2MS", 29, MIDI_UNMAPPED}, // + (Iceman)
{"E Bass MS", 33, MIDI_UNMAPPED}, // + (SQ3)
{"ElecBassMS", 33, MIDI_UNMAPPED},
{"ElecGtr MS", 27, MIDI_UNMAPPED}, // ++ (Iceman)
{"EnglHornMS", 69, MIDI_UNMAPPED},
{"FantasiaKA", 88, MIDI_UNMAPPED},
{"Fantasy ", 99, MIDI_UNMAPPED}, // + (PQ2)
{"Fantasy2MS", 99, MIDI_UNMAPPED}, // ++ (Camelot, QFG1)
{"Filter MS", 95, MIDI_UNMAPPED}, // +++ (Iceman)
{"Filter2 MS", 95, MIDI_UNMAPPED}, // ++ (Iceman)
{"Flame2 MS", 121, MIDI_UNMAPPED}, // ? (QFG1)
{"Flames MS", 121, MIDI_UNMAPPED}, // ? (QFG1)
{"Flute MS", 73, MIDI_UNMAPPED}, // +++ (QFG1)
{"FogHorn MS", 58, MIDI_UNMAPPED},
{"FrHorn1 MS", 60, MIDI_UNMAPPED}, // +++ (QFG1)
{"FunnyTrmp ", 56, MIDI_UNMAPPED}, // ++ (LB1)
{"GameSnd MS", 80, MIDI_UNMAPPED},
{"Glock MS", 9, MIDI_UNMAPPED}, // +++ (QFG1)
{"Gunshot ", 127, MIDI_UNMAPPED}, // +++ (LB1)
{"Hammer MS", MIDI_UNMAPPED, MIDI_UNMAPPED}, // ? (QFG1)
{"Harmonica2", 22, MIDI_UNMAPPED}, // +++ (LB1)
{"Harpsi 1 ", 6, MIDI_UNMAPPED}, // + (Hoyle)
{"Harpsi 2 ", 6, MIDI_UNMAPPED}, // +++ (LB1)
{"Heart MS", 116, MIDI_UNMAPPED}, // ? (Iceman)
{"Horse1 MS", 115, MIDI_UNMAPPED}, // ? (Camelot, QFG1)
{"Horse2 MS", 115, MIDI_UNMAPPED}, // ? (Camelot, QFG1)
{"InHale MS", 121, MIDI_UNMAPPED}, // ++ (Iceman)
{"KNIFE ", 120, MIDI_UNMAPPED}, // ? (LSL3)
{"KenBanjo ", 105, MIDI_UNMAPPED}, // +++ (LB1)
{"Kiss MS", 25, MIDI_UNMAPPED}, // ++ (QFG1)
{"KongHit ", MIDI_UNMAPPED, MIDI_UNMAPPED}, // ??? (KQ1)
{"Koto ", 107, MIDI_UNMAPPED}, // +++ (PQ2)
{"Laser MS", 81, MIDI_UNMAPPED}, // ?? (QFG1)
{"Meeps MS", 62, MIDI_UNMAPPED}, // ? (QFG1)
{"MTrak MS", 62, MIDI_UNMAPPED}, // ?? (Iceman)
{"MachGun MS", 127, MIDI_UNMAPPED}, // ? (Iceman)
{"OCEANSOUND", 122, MIDI_UNMAPPED}, // + (LSL3)
{"Oboe 2001 ", 68, MIDI_UNMAPPED}, // + (PQ2)
{"Ocean MS", 122, MIDI_UNMAPPED}, // + (Iceman)
{"PPG 2.3 MS", 75, MIDI_UNMAPPED}, // ? (Iceman)
{"PianoCrank", MIDI_UNMAPPED, MIDI_UNMAPPED}, // ? (LB1)
{"PicSnareMS", MIDI_MAPPED_TO_RHYTHM, 40}, // R ? (Iceman)
{"PiccoloKA ", 72, MIDI_UNMAPPED}, // +++ (KQ1)
{"PinkBassMS", 39, MIDI_UNMAPPED},
{"Pizz2 ", 45, MIDI_UNMAPPED}, // ++ (LB1)
{"Portcullis", MIDI_UNMAPPED, MIDI_UNMAPPED}, // ? (KQ1)
{"Raspbry MS", 81, MIDI_UNMAPPED}, // ? (QFG1)
{"RatSqueek ", 72, MIDI_UNMAPPED}, // ? (LauraBow1, Camelot)
{"Record78 ", MIDI_UNMAPPED, MIDI_UNMAPPED}, // +++ (LB1)
{"RecorderMS", 74, MIDI_UNMAPPED}, // +++ (Camelot)
{"Red Baron ", 125, MIDI_UNMAPPED}, // ? (LB1)
{"ReedPipMS ", 20, MIDI_UNMAPPED}, // +++ (Camelot)
{"RevCymb MS", 119, MIDI_UNMAPPED},
{"RifleShot ", 127, MIDI_UNMAPPED}, // + (LB1)
{"RimShot MS", MIDI_MAPPED_TO_RHYTHM, 37}, // R
{"SHOWER ", 52, MIDI_UNMAPPED}, // ? (LSL3)
{"SQ Bass MS", 32, MIDI_UNMAPPED}, // + (SQ3)
{"ShakuVibMS", 79, MIDI_UNMAPPED}, // + (Iceman)
{"SlapBassMS", 36, MIDI_UNMAPPED}, // +++ (Iceman)
{"Snare MS", MIDI_MAPPED_TO_RHYTHM, 38}, // R (QFG1)
{"Some Birds", 123, MIDI_UNMAPPED}, // + (LB1)
{"Sonar MS", 78, MIDI_UNMAPPED}, // ? (Iceman)
{"Soundtrk2 ", 97, MIDI_UNMAPPED}, // +++ (LB1)
{"Soundtrack", 97, MIDI_UNMAPPED}, // ++ (Camelot)
{"SqurWaveMS", 80, MIDI_UNMAPPED},
{"StabBassMS", 34, MIDI_UNMAPPED}, // + (Iceman)
{"SteelDrmMS", 114, MIDI_UNMAPPED}, // +++ (Iceman)
{"StrSect1MS", 48, MIDI_UNMAPPED}, // ++ (QFG1)
{"String MS", 45, MIDI_UNMAPPED}, // + (Camelot)
{"Syn-Choir ", 91, MIDI_UNMAPPED},
{"Syn Brass4", 63, MIDI_UNMAPPED}, // ++ (PQ2)
{"SynBass MS", 38, MIDI_UNMAPPED},
{"SwmpBackgr", 120, MIDI_UNMAPPED}, // ?? (LB1, QFG1)
{"T-Bone2 MS", 57, MIDI_UNMAPPED}, // +++ (QFG1)
{"Taiko ", 116, 35}, // +++ (Camelot)
{"Taiko Rim ", 118, 37}, // +++ (LSL3)
{"Timpani1 ", 47, MIDI_UNMAPPED}, // +++ (LB1)
{"Tom MS", 117, 48}, // +++ (Iceman)
{"Toms MS", 117, 48}, // +++ (Camelot, QFG1)
{"Tpt1prtl ", 56, MIDI_UNMAPPED}, // +++ (KQ1)
{"TriangleMS", 112, 81}, // R (Camelot)
{"Trumpet 1 ", 56, MIDI_UNMAPPED}, // +++ (Camelot)
{"Type MS", MIDI_MAPPED_TO_RHYTHM, 39}, // + (Iceman)
{"Warm Pad" , 89, MIDI_UNMAPPED}, // ++ (PQ3)
{"WaterBells", 98, MIDI_UNMAPPED}, // + (PQ2)
{"WaterFallK", MIDI_UNMAPPED, MIDI_UNMAPPED}, // ? (KQ1)
{"Whiporill ", 123, MIDI_UNMAPPED}, // + (LB1)
{"Wind ", MIDI_UNMAPPED, MIDI_UNMAPPED}, // ? (LB1)
{"Wind MS", MIDI_UNMAPPED, MIDI_UNMAPPED}, // ? (QFG1, Iceman)
{"Wind2 MS", MIDI_UNMAPPED, MIDI_UNMAPPED}, // ? (Camelot)
{"Woodpecker", 115, MIDI_UNMAPPED}, // ? (LB1)
{"WtrFall MS", MIDI_UNMAPPED, MIDI_UNMAPPED}, // ? (Camelot, QFG1, Iceman)
{0, 0, 0}
};
typedef Common::List<Mt32ToGmMap> Mt32ToGmMapList;
extern Mt32ToGmMapList *Mt32dynamicMappings;
} // End of namespace Dgds
#endif // DGDS_SOUND_DRIVERS_MAP_MT32_TO_GM_H

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,130 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef DGDS_SOUND_DRIVERS_MIDIDRIVER_H
#define DGDS_SOUND_DRIVERS_MIDIDRIVER_H
#include "audio/mididrv.h"
#include "common/platform.h"
namespace Dgds {
// Music patches in SCI games:
// ===========================
// 1.pat - MT-32 driver music patch
// 2.pat - Yamaha FB01 driver music patch
// 3.pat - Adlib driver music patch
// 4.pat - Casio MT-540 (in earlier SCI0 games)
// 4.pat - GM driver music patch (in later games that support GM)
// 7.pat (newer) / patch.200 (older) - Mac driver music patch / Casio CSM-1
// 9.pat (newer) / patch.005 (older) - Amiga driver music patch
// 98.pat - Unknown, found in later SCI1.1 games. A MIDI format patch
// 101.pat - CMS/PCjr driver music patch.
// Only later PCjr drivers use this patch, earlier ones don't use a patch
// bank.001 - older SCI0 Amiga instruments
class ResourceManager;
enum {
MIDI_CHANNELS = 16,
MIDI_PROP_MASTER_VOLUME = 0
};
#define MIDI_RHYTHM_CHANNEL 9
/* Special SCI sound stuff */
#define SCI_MIDI_TIME_EXPANSION_PREFIX 0xF8
#define SCI_MIDI_TIME_EXPANSION_LENGTH 240
#define SCI_MIDI_EOT 0xFC
#define SCI_MIDI_SET_SIGNAL 0xCF
#define SCI_MIDI_SET_POLYPHONY 0x4B
#define SCI_MIDI_RESET_ON_SUSPEND 0x4C
#define SCI_MIDI_CHANNEL_MUTE 0x4E
#define SCI_MIDI_SET_REVERB 0x50
#define SCI_MIDI_HOLD 0x52
#define SCI_MIDI_CUMULATIVE_CUE 0x60
#define SCI_MIDI_CHANNEL_SOUND_OFF 0x78 /* all-sound-off for Bn */
#define SCI_MIDI_CHANNEL_NOTES_OFF 0x7B /* all-notes-off for Bn */
#define SCI_MIDI_SET_SIGNAL_LOOP 0x7F
/* If this is the parameter of 0xCF, the loop point is set here */
#define SCI_MIDI_CONTROLLER(status) ((status & 0xF0) == 0xB0)
class MidiPlayer : public MidiDriver_BASE {
protected:
MidiDriver *_driver;
int8 _reverb;
public:
MidiPlayer() : _driver(nullptr), _reverb(-1) {}
virtual int open() { return _driver->open(); }
virtual void close() { _driver->close(); }
void send(uint32 b) override { _driver->send(b); }
virtual uint32 getBaseTempo() { return _driver->getBaseTempo(); }
virtual bool hasRhythmChannel() const = 0;
virtual void setTimerCallback(void *timer_param, Common::TimerManager::TimerProc timer_proc) { _driver->setTimerCallback(timer_param, timer_proc); }
virtual byte getPlayId() const = 0;
virtual int getPolyphony() const = 0;
virtual int getFirstChannel() const { return 0; }
virtual int getLastChannel() const { return 15; }
virtual void setVolume(byte volume) {
if(_driver)
_driver->property(MIDI_PROP_MASTER_VOLUME, volume);
}
virtual int getVolume() {
return _driver ? _driver->property(MIDI_PROP_MASTER_VOLUME, 0xffff) : 0;
}
// Returns the current reverb, or -1 when no reverb is active
int8 getReverb() const { return _reverb; }
// Sets the current reverb, used mainly in MT-32
virtual void setReverb(int8 reverb) { _reverb = reverb; }
virtual void playSwitch(bool play) {
if (!play) {
// Send "All Sound Off" on all channels
for (int i = 0; i < MIDI_CHANNELS; ++i)
_driver->send(0xb0 + i, SCI_MIDI_CHANNEL_NOTES_OFF, 0);
}
}
};
class SciResource;
extern SciResource *getMidiPatchData(int num);
extern MidiPlayer *MidiPlayer_AdLib_create();
extern MidiPlayer *MidiPlayer_AmigaMac1_create(Common::Platform platform);
extern MidiPlayer *MidiPlayer_CMS_create();
extern MidiPlayer *MidiPlayer_PCJr_create();
extern MidiPlayer *MidiPlayer_PCSpeaker_create();
extern MidiPlayer *MidiPlayer_Midi_create();
} // End of namespace Dgds
#endif // DGDS_SOUND_DRIVERS_MIDIDRIVER_H

View File

@@ -0,0 +1,117 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/config-manager.h"
#include "common/file.h"
#include "common/memstream.h"
#include "common/ptr.h"
#include "dgds/sound/resource/sci_resource.h"
#include "dgds/dgds.h"
#include "dgds/includes.h"
namespace Dgds {
//
// Unlike the other files in this directory, this is not part of the SCI
// engine. This is a single function to load patch data from the DGDS
// resource system.
//
static const char *PATCH_RESOURCES[] = {
"SXTITLE.OVL", // dragon
"SXCODE1.OVL", // hoc (TODO: when do we load SXCODE2 - maybe when global 0x37 changes)
"SX.OVL", // newer games (beamish, sq5 demo)
};
SciResource *getMidiPatchData(int num) {
assert(num < 999);
DgdsEngine *engine = DgdsEngine::getInstance();
ResourceManager *resource = engine->getResourceManager();
Decompressor *decomp = engine->getDecompressor();
Common::ScopedPtr<ResourceManager> fddMgr;
Common::ScopedPtr<Common::SeekableReadStream> ovlStream;
int resNum = 0;
for (; resNum < ARRAYSIZE(PATCH_RESOURCES); resNum++) {
ovlStream.reset(resource->getResource(PATCH_RESOURCES[resNum]));
if (ovlStream)
break;
}
//
// WORKAROUND: The MT-32 patch data in Willy Beamish CD version is corrupted.
// If the FDD version is avaialble in the "FDD" directory, use that instead.
// This is how the data comes arranged in the GOG version.
//
if (num == 1 && engine->getGameId() == GID_WILLY) {
fddMgr.reset(new ResourceManager("FDD"));
if (fddMgr.get()->hasResource("SX.OVL")) {
debug("Overriding MT32 patch data with patches from FDD version.");
resNum = 2;
ovlStream.reset(fddMgr.get()->getResource("SX.OVL"));
}
}
if (!ovlStream) {
warning("Couldn't load DGDS midi patch data from any known OVL file");
return nullptr;
}
DgdsChunkReader chunk(ovlStream.get());
const Common::String targetSection = Common::String::format("%03d:", num);
while (chunk.readNextHeader(EX_OVL, PATCH_RESOURCES[resNum])) {
if (chunk.isContainer()) {
continue;
}
if (chunk.isSection(targetSection)) {
chunk.readContent(decomp);
Common::SeekableReadStream *stream = chunk.getContent();
byte magic = stream->readSByte(); // always 137?
byte strLen = stream->readSByte(); // header string len
char *buf = new char[strLen + 1];
stream->read(buf, strLen);
buf[strLen] = '\0';
int dataLen = stream->size() - (strLen + 2);
byte *data = new byte[dataLen];
debug(1, "midi patch %s loading magic %d str '%s'", targetSection.c_str(), magic, buf);
delete [] buf;
stream->read(data, dataLen);
return new SciResource(data, dataLen, num);
} else {
chunk.skipContent();
}
}
warning("Didn't find section %s in midi patch resource %s", targetSection.c_str(), PATCH_RESOURCES[resNum]);
return nullptr;
}
} // end namespace Dgds