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

667
engines/gob/sound/adlib.cpp Normal file
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/>.
*
*
* This file is dual-licensed.
* In addition to the GPLv3 license mentioned above, this code is also
* licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
* full text of the license.
*
*/
#include "common/util.h"
#include "common/textconsole.h"
#include "common/debug.h"
#include "common/config-manager.h"
#include "audio/fmopl.h"
#include "gob/gob.h"
#include "gob/sound/adlib.h"
namespace Gob {
static const int kPitchTom = 24;
static const int kPitchTomToSnare = 7;
static const int kPitchSnareDrum = kPitchTom + kPitchTomToSnare;
// Attenuation map for GUI volume slider
// Note: no volume control in the original engine
const uint8 AdLib::kVolumeTable[Audio::Mixer::kMaxMixerVolume + 1] = {
63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 62, 61, 59, 57, 56, 55,
53, 52, 51, 50, 49, 48, 47, 46, 46, 45, 44, 43, 43, 42, 41, 41,
40, 39, 39, 38, 38, 37, 37, 36, 36, 35, 35, 34, 34, 33, 33, 33,
32, 32, 31, 31, 31, 30, 30, 30, 29, 29, 29, 28, 28, 28, 27, 27,
27, 26, 26, 26, 26, 25, 25, 25, 24, 24, 24, 24, 23, 23, 23, 23,
22, 22, 22, 22, 21, 21, 21, 21, 21, 20, 20, 20, 20, 19, 19, 19,
19, 19, 18, 18, 18, 18, 18, 18, 17, 17, 17, 17, 17, 16, 16, 16,
16, 16, 16, 15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 13,
13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11,
11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9,
9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
0
};
// Is the operator a modulator (0) or a carrier (1)?
const uint8 AdLib::kOperatorType[kOperatorCount] = {
0, 0, 0, 1, 1, 1,
0, 0, 0, 1, 1, 1,
0, 0, 0, 1, 1, 1
};
// Operator number to register offset on the OPL
const uint8 AdLib::kOperatorOffset[kOperatorCount] = {
0, 1, 2, 3, 4, 5,
8, 9, 10, 11, 12, 13,
16, 17, 18, 19, 20, 21
};
// For each operator, the voice it belongs to
const uint8 AdLib::kOperatorVoice[kOperatorCount] = {
0, 1, 2,
0, 1, 2,
3, 4, 5,
3, 4, 5,
6, 7, 8,
6, 7, 8,
};
// Voice to operator set, for the 9 melodyvoices (only 6 useable in percussion mode)
const uint8 AdLib::kVoiceMelodyOperator[kOperatorsPerVoice][kMelodyVoiceCount] = {
{0, 1, 2, 6, 7, 8, 12, 13, 14},
{3, 4, 5, 9, 10, 11, 15, 16, 17}
};
// Voice to operator set, for the 5 percussion voices (only useable in percussion mode)
const uint8 AdLib::kVoicePercussionOperator[kOperatorsPerVoice][kPercussionVoiceCount] = {
{12, 16, 14, 17, 13},
{15, 0, 0, 0, 0}
};
// Mask bits to set each percussion instrument on/off
const byte AdLib::kPercussionMasks[kPercussionVoiceCount] = {0x10, 0x08, 0x04, 0x02, 0x01};
// Default instrument presets
const uint16 AdLib::kPianoParams [kOperatorsPerVoice][kParamCount] = {
{ 1, 1, 3, 15, 5, 0, 1, 3, 15, 0, 0, 0, 1, 0},
{ 0, 1, 1, 15, 7, 0, 2, 4, 0, 0, 0, 1, 0, 0} };
const uint16 AdLib::kBaseDrumParams[kOperatorsPerVoice][kParamCount] = {
{ 0, 0, 0, 10, 4, 0, 8, 12, 11, 0, 0, 0, 1, 0 },
{ 0, 0, 0, 13, 4, 0, 6, 15, 0, 0, 0, 0, 1, 0 } };
const uint16 AdLib::kSnareDrumParams[kParamCount] = {
0, 12, 0, 15, 11, 0, 8, 5, 0, 0, 0, 0, 0, 0 };
const uint16 AdLib::kTomParams [kParamCount] = {
0, 4, 0, 15, 11, 0, 7, 5, 0, 0, 0, 0, 0, 0 };
const uint16 AdLib::kCymbalParams [kParamCount] = {
0, 1, 0, 15, 11, 0, 5, 5, 0, 0, 0, 0, 0, 0 };
const uint16 AdLib::kHihatParams [kParamCount] = {
0, 1, 0, 15, 11, 0, 7, 5, 0, 0, 0, 0, 0, 0 };
AdLib::AdLib(int callbackFreq) : _opl(nullptr),
_toPoll(0), _repCount(0), _first(true), _playing(false), _ended(true), _volume(0) {
initFreqs();
createOPL();
initOPL();
syncVolume();
_opl->start(new Common::Functor0Mem<void, AdLib>(this, &AdLib::onTimer), callbackFreq);
}
AdLib::~AdLib() {
delete _opl;
}
// Creates the OPL. Try to use the DOSBox emulator, unless that one is not compiled in,
// or the user explicitly wants the MAME emulator. The MAME one is slightly buggy, leading
// to some wrong sounds, especially noticeable in the title music of Gobliins 2, so we
// really don't want to use it, if we can help it.
void AdLib::createOPL() {
Common::String oplDriver = ConfMan.get("opl_driver");
if (oplDriver.empty() || (oplDriver == "auto") || (OPL::Config::parse(oplDriver) == -1)) {
// User has selected OPL driver auto detection or an invalid OPL driver.
// Set it to our preferred driver (DOSBox), if we can.
if (OPL::Config::parse("db") <= 0) {
warning("The DOSBox AdLib emulator is not compiled in. Please keep in mind that the MAME one is buggy");
} else
oplDriver = "db";
} else if (oplDriver == "mame") {
// User has selected the MAME OPL driver. It is buggy, so warn the user about that.
warning("You have selected the MAME AdLib emulator. It is buggy; AdLib music might be slightly glitchy now");
}
_opl = OPL::Config::create(OPL::Config::parse(oplDriver), OPL::Config::kOpl2);
if (!_opl || !_opl->init()) {
delete _opl;
error("Could not create an AdLib emulator");
}
}
void AdLib::onTimer() {
Common::StackLock slock(_mutex);
// Nothing to do
if (!_playing)
return;
// Check if there's anything to do on this step
// If not, decrease the poll number and move on
if (_toPoll > 0) {
_toPoll--;
return;
}
// Poll until we have to delay until the next poll
while (_toPoll == 0 && _playing) {
// Song ended, break out
if (_ended) {
_toPoll = 0;
break;
}
// Poll more music
_toPoll = pollMusic(_first);
_first = false;
}
// Song ended, loop if requested
if (_ended) {
_toPoll = 0;
// _repCount == 0: No looping (anymore); _repCount < 0: Infinite looping
if (_repCount != 0) {
if (_repCount > 0)
_repCount--;
_first = true;
_ended = false;
reset();
rewind();
} else
_playing = false;
}
}
bool AdLib::isPlaying() const {
return _playing;
}
int32 AdLib::getRepeating() const {
Common::StackLock slock(_mutex);
return _repCount;
}
void AdLib::setRepeating(int32 repCount) {
Common::StackLock slock(_mutex);
_repCount = repCount;
}
void AdLib::startPlay() {
Common::StackLock slock(_mutex);
_playing = true;
_ended = false;
_first = true;
reset();
rewind();
}
void AdLib::stopPlay() {
Common::StackLock slock(_mutex);
end(true);
_playing = false;
}
void AdLib::writeOPL(byte reg, byte val) {
debugC(6, kDebugSound, "AdLib::writeOPL (%02X, %02X)", reg, val);
_opl->writeReg(reg, val);
}
void AdLib::reset() {
allOff();
initOPL();
}
void AdLib::allOff() {
// NOTE: Explicit casts are necessary, because of 5.16 paragraph 4 of the C++ standard
int numVoices = isPercussionMode() ? (int)kMaxVoiceCount : (int)kMelodyVoiceCount;
for (int i = 0; i < numVoices; i++)
noteOff(i);
}
void AdLib::end(bool killRepeat) {
reset();
_ended = true;
if (killRepeat)
_repCount = 0;
}
void AdLib::initOPL() {
_tremoloDepth = false;
_vibratoDepth = false;
_keySplit = false;
_enableWaveSelect = true;
for (int i = 0; i < kMaxVoiceCount; i++) {
_voiceNote[i] = 0;
_voiceOn [i] = 0;
}
/* NOTE: We used to completely reset the OPL here, via _opl->reset(). However,
* with the OPL timer change in 73e8ac2a, reset() must not be called while
* the callback is still active. With the Gob AdLib rewrite in 03ef6689,
* this reset shouldn't be necessary anymore either, since this function
* here cleans everything properly anyway. If suddenly a certain piece of
* music in a Gob game sounds weird, we need to re-examine that. */
initOperatorVolumes();
resetFreqs();
setPercussionMode(false);
setTremoloDepth(false);
setVibratoDepth(false);
setKeySplit(false);
for(int i = 0; i < kMelodyVoiceCount; i++)
voiceOff(i);
setPitchRange(1);
enableWaveSelect(true);
}
bool AdLib::isPercussionMode() const {
return _percussionMode;
}
void AdLib::setPercussionMode(bool percussion) {
if (percussion) {
voiceOff(kVoiceBaseDrum);
voiceOff(kVoiceSnareDrum);
voiceOff(kVoiceTom);
/* set the frequency for the last 4 percussion voices: */
setFreq(kVoiceTom, kPitchTom, 0);
setFreq(kVoiceSnareDrum, kPitchSnareDrum, 0);
}
_percussionMode = percussion;
_percussionBits = 0;
initOperatorParams();
writeTremoloVibratoDepthPercMode();
}
void AdLib::enableWaveSelect(bool enable) {
_enableWaveSelect = enable;
for (int i = 0; i < kOperatorCount; i++)
writeOPL(0xE0 + kOperatorOffset[i], 0);
writeOPL(0x011, _enableWaveSelect ? 0x20 : 0);
}
void AdLib::setPitchRange(uint8 range) {
_pitchRange = CLIP<uint8>(range, 0, 12);
_pitchRangeStep = _pitchRange * kPitchStepCount;
}
void AdLib::setTremoloDepth(bool tremoloDepth) {
_tremoloDepth = tremoloDepth;
writeTremoloVibratoDepthPercMode();
}
void AdLib::setVibratoDepth(bool vibratoDepth) {
_vibratoDepth = vibratoDepth;
writeTremoloVibratoDepthPercMode();
}
void AdLib::setKeySplit(bool keySplit) {
_keySplit = keySplit;
writeKeySplit();
}
void AdLib::setVoiceTimbre(uint8 voice, const uint16 *params) {
const uint16 *params0 = params;
const uint16 *params1 = params + kParamCount - 1;
const uint16 *waves = params + 2 * (kParamCount - 1);
const int voicePerc = voice - kVoiceBaseDrum;
if (!isPercussionMode() || (voice < kVoiceBaseDrum)) {
if (voice < kMelodyVoiceCount) {
setOperatorParams(kVoiceMelodyOperator[0][voice], params0, waves[0]);
setOperatorParams(kVoiceMelodyOperator[1][voice], params1, waves[1]);
}
} else if (voice == kVoiceBaseDrum) {
setOperatorParams(kVoicePercussionOperator[0][voicePerc], params0, waves[0]);
setOperatorParams(kVoicePercussionOperator[1][voicePerc], params1, waves[1]);
} else {
setOperatorParams(kVoicePercussionOperator[0][voicePerc], params0, waves[0]);
}
}
void AdLib::setVoiceVolume(uint8 voice, uint8 volume) {
int oper;
const int voicePerc = voice - kVoiceBaseDrum;
if (!isPercussionMode() || (voice < kVoiceBaseDrum))
oper = kVoiceMelodyOperator[1][ voice];
else
oper = kVoicePercussionOperator[voice == kVoiceBaseDrum ? 1 : 0][voicePerc];
_operatorVolume[oper] = MIN<uint8>(volume, kMaxVolume);
writeKeyScaleLevelVolume(oper);
}
void AdLib::bendVoicePitch(uint8 voice, uint16 pitchBend) {
if (isPercussionMode() && (voice > kVoiceBaseDrum))
return;
changePitch(voice, MIN<uint16>(pitchBend, kMaxPitch));
setFreq(voice, _voiceNote[voice], _voiceOn[voice]);
}
void AdLib::noteOn(uint8 voice, uint8 note) {
note = MAX<int>(0, note - (kStandardMidC - kOPLMidC));
if (isPercussionMode() && (voice >= kVoiceBaseDrum)) {
if (voice == kVoiceBaseDrum) {
setFreq(kVoiceBaseDrum , note , false);
} else if (voice == kVoiceTom) {
setFreq(kVoiceTom , note , false);
setFreq(kVoiceSnareDrum, note + kPitchTomToSnare, false);
}
_percussionBits |= kPercussionMasks[voice - kVoiceBaseDrum];
writeTremoloVibratoDepthPercMode();
} else
setFreq(voice, note, true);
}
void AdLib::noteOff(uint8 voice) {
if (isPercussionMode() && (voice >= kVoiceBaseDrum)) {
_percussionBits &= ~kPercussionMasks[voice - kVoiceBaseDrum];
writeTremoloVibratoDepthPercMode();
} else
setFreq(voice, _voiceNote[voice], false);
}
void AdLib::writeKeyScaleLevelVolume(uint8 oper) {
uint16 volume = 0;
volume = (63 - (_operatorParams[oper][kParamLevel] & 0x3F)) * _operatorVolume[oper];
volume = 63 - ((2 * volume + kMaxVolume) / (2 * kMaxVolume));
// Adjust carriers for GUI volume slider
if (kOperatorType[oper] == 1) {
volume += kVolumeTable[_volume];
if (volume > 63)
volume = 63;
}
uint8 keyScale = _operatorParams[oper][kParamKeyScaleLevel] << 6;
writeOPL(0x40 + kOperatorOffset[oper], volume | keyScale);
}
void AdLib::writeKeySplit() {
writeOPL(0x08, _keySplit ? 0x40 : 0);
}
void AdLib::writeFeedbackFM(uint8 oper) {
if (kOperatorType[oper] == 1)
return;
uint8 value = 0;
value |= _operatorParams[oper][kParamFeedback] << 1;
value |= _operatorParams[oper][kParamFM] ? 0 : 1;
writeOPL(0xC0 + kOperatorVoice[oper], value);
}
void AdLib::writeAttackDecay(uint8 oper) {
uint8 value = 0;
value |= _operatorParams[oper][kParamAttack] << 4;
value |= _operatorParams[oper][kParamDecay] & 0x0F;
writeOPL(0x60 + kOperatorOffset[oper], value);
}
void AdLib::writeSustainRelease(uint8 oper) {
uint8 value = 0;
value |= _operatorParams[oper][kParamSustain] << 4;
value |= _operatorParams[oper][kParamRelease] & 0x0F;
writeOPL(0x80 + kOperatorOffset[oper], value);
}
void AdLib::writeTremoloVibratoSustainingKeyScaleRateFreqMulti(uint8 oper) {
uint8 value = 0;
value |= _operatorParams[oper][kParamAM] ? 0x80 : 0;
value |= _operatorParams[oper][kParamVib] ? 0x40 : 0;
value |= _operatorParams[oper][kParamSustaining] ? 0x20 : 0;
value |= _operatorParams[oper][kParamKeyScaleRate] ? 0x10 : 0;
value |= _operatorParams[oper][kParamFreqMulti] & 0x0F;
writeOPL(0x20 + kOperatorOffset[oper], value);
}
void AdLib::writeTremoloVibratoDepthPercMode() {
uint8 value = 0;
value |= _tremoloDepth ? 0x80 : 0;
value |= _vibratoDepth ? 0x40 : 0;
value |= isPercussionMode() ? 0x20 : 0;
value |= _percussionBits;
writeOPL(0xBD, value);
}
void AdLib::writeWaveSelect(uint8 oper) {
uint8 wave = 0;
if (_enableWaveSelect)
wave = _operatorParams[oper][kParamWaveSelect] & 0x03;
writeOPL(0xE0 + kOperatorOffset[ oper], wave);
}
void AdLib::writeAllParams(uint8 oper) {
writeTremoloVibratoDepthPercMode();
writeKeySplit();
writeKeyScaleLevelVolume(oper);
writeFeedbackFM(oper);
writeAttackDecay(oper);
writeSustainRelease(oper);
writeTremoloVibratoSustainingKeyScaleRateFreqMulti(oper);
writeWaveSelect(oper);
}
void AdLib::initOperatorParams() {
for (int i = 0; i < kOperatorCount; i++)
setOperatorParams(i, kPianoParams[kOperatorType[i]], kPianoParams[kOperatorType[i]][kParamCount - 1]);
if (isPercussionMode()) {
setOperatorParams(12, kBaseDrumParams [0], kBaseDrumParams [0][kParamCount - 1]);
setOperatorParams(15, kBaseDrumParams [1], kBaseDrumParams [1][kParamCount - 1]);
setOperatorParams(16, kSnareDrumParams , kSnareDrumParams [kParamCount - 1]);
setOperatorParams(14, kTomParams , kTomParams [kParamCount - 1]);
setOperatorParams(17, kCymbalParams , kCymbalParams [kParamCount - 1]);
setOperatorParams(13, kHihatParams , kHihatParams [kParamCount - 1]);
}
}
void AdLib::initOperatorVolumes() {
for(int i = 0; i < kOperatorCount; i++)
_operatorVolume[i] = kMaxVolume;
}
void AdLib::setOperatorParams(uint8 oper, const uint16 *params, uint8 wave) {
byte *operParams = _operatorParams[oper];
for (int i = 0; i < (kParamCount - 1); i++)
operParams[i] = params[i];
operParams[kParamCount - 1] = wave & 0x03;
writeAllParams(oper);
}
void AdLib::voiceOff(uint8 voice) {
writeOPL(0xA0 + voice, 0);
writeOPL(0xB0 + voice, 0);
}
int32 AdLib::calcFreq(int32 deltaDemiToneNum, int32 deltaDemiToneDenom) {
int32 freq = 0;
freq = ((deltaDemiToneDenom * 100) + 6 * deltaDemiToneNum) * 52088;
freq /= deltaDemiToneDenom * 2500;
return (freq * 147456) / 111875;
}
void AdLib::setFreqs(uint16 *freqs, int32 num, int32 denom) {
int32 val = calcFreq(num, denom);
*freqs++ = (4 + val) >> 3;
for (int i = 1; i < kHalfToneCount; i++) {
val = (val * 106) / 100;
*freqs++ = (4 + val) >> 3;
}
}
void AdLib::initFreqs() {
const int numStep = 100 / kPitchStepCount;
for (int i = 0; i < kPitchStepCount; i++)
setFreqs(_freqs[i], i * numStep, 100);
resetFreqs();
}
void AdLib::resetFreqs() {
for (int i = 0; i < kMaxVoiceCount; i++) {
_freqPtr [i] = _freqs[0];
_halfToneOffset[i] = 0;
}
}
void AdLib::changePitch(uint8 voice, uint16 pitchBend) {
int full = 0;
int frac = 0;
int amount = ((pitchBend - kMidPitch) * _pitchRangeStep) / kMidPitch;
if (amount >= 0) {
// Bend up
full = amount / kPitchStepCount;
frac = amount % kPitchStepCount;
} else {
// Bend down
amount = kPitchStepCount - 1 - amount;
full = -(amount / kPitchStepCount);
frac = (amount - kPitchStepCount + 1) % kPitchStepCount;
if (frac)
frac = kPitchStepCount - frac;
}
_halfToneOffset[voice] = full;
_freqPtr [voice] = _freqs[frac];
}
void AdLib::setFreq(uint8 voice, uint16 note, bool on) {
_voiceOn [voice] = on;
_voiceNote[voice] = note;
note = CLIP<int>(note + _halfToneOffset[voice], 0, kNoteCount - 1);
uint16 freq = _freqPtr[voice][note % kHalfToneCount];
uint8 value = 0;
value |= on ? 0x20 : 0;
value |= ((note / kHalfToneCount) << 2) | ((freq >> 8) & 0x03);
writeOPL(0xA0 + voice, freq);
writeOPL(0xB0 + voice, value);
}
void AdLib::setTimerFrequency(int timerFrequency) {
_opl->setCallbackFrequency(timerFrequency);
}
void AdLib::syncVolume() {
Common::StackLock slock(_mutex);
bool mute = false;
if (ConfMan.hasKey("mute"))
mute = ConfMan.getBool("mute");
_volume = (mute ? 0 : ConfMan.getInt("music_volume"));
if (_playing) {
for(int i = 0; i < kOperatorCount; i++)
writeKeyScaleLevelVolume(i);
}
}
} // End of namespace Gob

313
engines/gob/sound/adlib.h Normal file
View File

@@ -0,0 +1,313 @@
/* 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/>.
*
*
* This file is dual-licensed.
* In addition to the GPLv3 license mentioned above, this code is also
* licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
* full text of the license.
*
*/
#ifndef GOB_SOUND_ADLIB_H
#define GOB_SOUND_ADLIB_H
#include "common/mutex.h"
#include "audio/mixer.h"
namespace OPL {
class OPL;
}
namespace Gob {
/** Base class for a player of an AdLib music format. */
class AdLib {
public:
AdLib(int callbackFrequency);
virtual ~AdLib();
bool isPlaying() const; ///< Are we currently playing?
int32 getRepeating() const; ///< Return number of times left to loop.
/** Set the loop counter.
*
* @param repCount Number of times to loop (i.e. number of additional
* paythroughs to the first one, not overall).
* A negative value means infinite looping.
*/
void setRepeating(int32 repCount);
void startPlay();
void stopPlay();
void syncVolume();
protected:
enum kVoice {
kVoiceMelody0 = 0,
kVoiceMelody1 = 1,
kVoiceMelody2 = 2,
kVoiceMelody3 = 3,
kVoiceMelody4 = 4,
kVoiceMelody5 = 5,
kVoiceMelody6 = 6, // Only available in melody mode.
kVoiceMelody7 = 7, // Only available in melody mode.
kVoiceMelody8 = 8, // Only available in melody mode.
kVoiceBaseDrum = 6, // Only available in percussion mode.
kVoiceSnareDrum = 7, // Only available in percussion mode.
kVoiceTom = 8, // Only available in percussion mode.
kVoiceCymbal = 9, // Only available in percussion mode.
kVoiceHihat = 10 // Only available in percussion mode.
};
/** Operator parameters. */
enum kParam {
kParamKeyScaleLevel = 0,
kParamFreqMulti = 1,
kParamFeedback = 2,
kParamAttack = 3,
kParamSustain = 4,
kParamSustaining = 5,
kParamDecay = 6,
kParamRelease = 7,
kParamLevel = 8,
kParamAM = 9,
kParamVib = 10,
kParamKeyScaleRate = 11,
kParamFM = 12,
kParamWaveSelect = 13
};
static const int kOperatorCount = 18; ///< Number of operators.
static const int kParamCount = 14; ///< Number of operator parameters.
static const int kPitchStepCount = 25; ///< Number of pitch bend steps in a half tone.
static const int kOctaveCount = 8; ///< Number of octaves we can play.
static const int kHalfToneCount = 12; ///< Number of half tones in an octave.
static const int kOperatorsPerVoice = 2; ///< Number of operators per voice.
static const int kMelodyVoiceCount = 9; ///< Number of melody voices.
static const int kPercussionVoiceCount = 5; ///< Number of percussion voices.
static const int kMaxVoiceCount = 11; ///< Max number of voices.
/** Number of notes we can play. */
static const int kNoteCount = kHalfToneCount * kOctaveCount;
static const int kMaxVolume = 0x007F;
static const int kMaxPitch = 0x3FFF;
static const int kMidPitch = 0x2000;
static const int kStandardMidC = 60; ///< A mid C in standard MIDI.
static const int kOPLMidC = 48; ///< A mid C for the OPL.
/** Write a value into an OPL register. */
void writeOPL(byte reg, byte val);
/** Signal that the playback ended.
*
* @param killRepeat Explicitly request that the song is not to be looped.
*/
void end(bool killRepeat = false);
/** The callback function that's called for polling more AdLib commands.
*
* @param first Is this the first poll since the start of the song?
* @return The number of ticks until the next poll.
*/
virtual uint32 pollMusic(bool first) = 0;
/** Rewind the song. */
virtual void rewind() = 0;
/** Return whether we're in percussion mode. */
bool isPercussionMode() const;
/** Set percussion or melody mode. */
void setPercussionMode(bool percussion);
/** Enable/Disable the wave select operator parameters.
*
* When disabled, all operators use the sine wave, regardless of the parameter.
*/
void enableWaveSelect(bool enable);
/** Change the pitch bend range.
*
* @param range The range in half tones from 1 to 12 inclusive.
* See bendVoicePitch() for how this works in practice.
*/
void setPitchRange(uint8 range);
/** Set the tremolo (amplitude vibrato) depth.
*
* @param tremoloDepth false: 1.0dB, true: 4.8dB.
*/
void setTremoloDepth(bool tremoloDepth);
/** Set the frequency vibrato depth.
*
* @param vibratoDepth false: 7 cent, true: 14 cent. 1 cent = 1/100 half tone.
*/
void setVibratoDepth(bool vibratoDepth);
/** Set the keyboard split point. */
void setKeySplit(bool keySplit);
/** Set the timbre of a voice.
*
* Layout of the operator parameters is as follows:
* - First 13 parameter for the first operator
* - First 13 parameter for the second operator
* - 14th parameter (wave select) for the first operator
* - 14th parameter (wave select) for the second operator
*/
void setVoiceTimbre(uint8 voice, const uint16 *params);
/** Set a voice's volume. */
void setVoiceVolume(uint8 voice, uint8 volume);
/** Bend a voice's pitch.
*
* The pitchBend parameter is a value between 0 (full down) and kMaxPitch (full up).
* The actual frequency depends on the pitch range set previously by setPitchRange(),
* with full down being -range half tones and full up range half tones.
*/
void bendVoicePitch(uint8 voice, uint16 pitchBend);
/** Switch a voice on.
*
* Plays one of the kNoteCount notes. However, the valid range of a note is between
* 0 and 127, of which only 12 to 107 are audible.
*/
void noteOn(uint8 voice, uint8 note);
/** Switch a voice off. */
void noteOff(uint8 voice);
/**
* Set the OPL timer frequency
*/
void setTimerFrequency(int timerFrequency);
private:
static const uint8 kVolumeTable[Audio::Mixer::kMaxMixerVolume + 1];
static const uint8 kOperatorType [kOperatorCount];
static const uint8 kOperatorOffset[kOperatorCount];
static const uint8 kOperatorVoice [kOperatorCount];
static const uint8 kVoiceMelodyOperator [kOperatorsPerVoice][kMelodyVoiceCount];
static const uint8 kVoicePercussionOperator[kOperatorsPerVoice][kPercussionVoiceCount];
static const byte kPercussionMasks[kPercussionVoiceCount];
static const uint16 kPianoParams [kOperatorsPerVoice][kParamCount];
static const uint16 kBaseDrumParams [kOperatorsPerVoice][kParamCount];
static const uint16 kSnareDrumParams[kParamCount];
static const uint16 kTomParams [kParamCount];
static const uint16 kCymbalParams [kParamCount];
static const uint16 kHihatParams [kParamCount];
OPL::OPL *_opl;
Common::Mutex _mutex;
int _volume;
uint32 _toPoll;
int32 _repCount;
bool _first;
bool _playing;
bool _ended;
bool _tremoloDepth;
bool _vibratoDepth;
bool _keySplit;
bool _enableWaveSelect;
bool _percussionMode;
byte _percussionBits;
uint8 _pitchRange;
uint16 _pitchRangeStep;
uint8 _voiceNote[kMaxVoiceCount]; // Last note of each voice
uint8 _voiceOn [kMaxVoiceCount]; // Whether each voice is currently on
uint8 _operatorVolume[kOperatorCount]; // Volume of each operator
byte _operatorParams[kOperatorCount][kParamCount]; // All operator parameters
uint16 _freqs[kPitchStepCount][kHalfToneCount];
uint16 *_freqPtr[kMaxVoiceCount];
int _halfToneOffset[kMaxVoiceCount];
void createOPL();
void initOPL();
void reset();
void allOff();
// Write global parameters into the OPL
void writeTremoloVibratoDepthPercMode();
void writeKeySplit();
// Write operator parameters into the OPL
void writeWaveSelect(uint8 oper);
void writeTremoloVibratoSustainingKeyScaleRateFreqMulti(uint8 oper);
void writeSustainRelease(uint8 oper);
void writeAttackDecay(uint8 oper);
void writeFeedbackFM(uint8 oper);
void writeKeyScaleLevelVolume(uint8 oper);
void writeAllParams(uint8 oper);
void initOperatorParams();
void initOperatorVolumes();
void setOperatorParams(uint8 oper, const uint16 *params, uint8 wave);
void voiceOff(uint8 voice);
void initFreqs();
void setFreqs(uint16 *freqs, int32 num, int32 denom);
int32 calcFreq(int32 deltaDemiToneNum, int32 deltaDemiToneDenom);
void resetFreqs();
void changePitch(uint8 voice, uint16 pitchBend);
void setFreq(uint8 voice, uint16 note, bool on);
/**
* Callback function for OPL
*/
void onTimer();
};
} // End of namespace Gob
#endif // GOB_SOUND_ADLIB_H

View File

@@ -0,0 +1,255 @@
/* 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/>.
*
*
* This file is dual-licensed.
* In addition to the GPLv3 license mentioned above, this code is also
* licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
* full text of the license.
*
*/
#include "common/stream.h"
#include "common/memstream.h"
#include "common/textconsole.h"
#include "gob/sound/adlplayer.h"
namespace Gob {
ADLPlayer::ADLPlayer() : AdLib(1000),
_songData(nullptr), _songDataSize(0), _playPos(nullptr) {
}
ADLPlayer::~ADLPlayer() {
unload();
}
void ADLPlayer::unload() {
stopPlay();
_timbres.clear();
delete[] _songData;
_songData = nullptr;
_songDataSize = 0;
_playPos = nullptr;
}
uint32 ADLPlayer::pollMusic(bool first) {
if (_timbres.empty() || !_songData || !_playPos || (_playPos >= (_songData + _songDataSize))) {
end();
return 0;
}
// We'll ignore the first delay
if (first)
_playPos += (*_playPos & 0x80) ? 2 : 1;
byte cmd = *_playPos++;
// Song end marker
if (cmd == 0xFF) {
end();
return 0;
}
// Set the instrument that should be modified
if (cmd == 0xFE)
_modifyInstrument = *_playPos++;
if (cmd >= 0xD0) {
// Modify an instrument
if (_modifyInstrument == 0xFF)
warning("ADLPlayer: No instrument to modify");
else if (_modifyInstrument >= _timbres.size())
warning("ADLPlayer: Can't modify invalid instrument %d (%d)", _modifyInstrument, _timbres.size());
else
_timbres[_modifyInstrument].params[_playPos[0]] = _playPos[1];
_playPos += 2;
// If we currently have that instrument loaded, reload it
for (int i = 0; i < kMaxVoiceCount; i++)
if (_currentInstruments[i] == _modifyInstrument)
setInstrument(i, _modifyInstrument);
} else {
// Voice command
uint8 voice = cmd & 0x0F;
uint8 note, volume;
switch (cmd & 0xF0) {
case 0x00: // Note on with volume
note = *_playPos++;
volume = *_playPos++;
setVoiceVolume(voice, volume);
noteOn(voice, note);
break;
case 0xA0: // Pitch bend
bendVoicePitch(voice, ((uint16)*_playPos++) << 7);
break;
case 0xB0: // Set volume
setVoiceVolume(voice, *_playPos++);
break;
case 0xC0: // Set instrument
setInstrument(voice, *_playPos++);
break;
case 0x90: // Note on
noteOn(voice, *_playPos++);
break;
case 0x80: // Note off
noteOff(voice);
break;
default:
warning("ADLPlayer: Unsupported command: 0x%02X. Stopping playback.", cmd);
end(true);
return 0;
}
}
uint16 delay = *_playPos++;
if (delay & 0x80)
delay = ((delay & 3) << 8) | *_playPos++;
return delay;
}
void ADLPlayer::rewind() {
// Reset song data
_playPos = _songData;
// Set melody/percussion mode
setPercussionMode(_soundMode != 0);
// Reset instruments
for (Common::Array<Timbre>::iterator t = _timbres.begin(); t != _timbres.end(); ++t)
memcpy(t->params, t->startParams, kOperatorsPerVoice * kParamCount * sizeof(uint16));
for (int i = 0; i < kMaxVoiceCount; i++)
_currentInstruments[i] = 0;
// Reset voices
int numVoice = MIN<int>(_timbres.size(), _soundMode ? (int)kMaxVoiceCount : (int)kMelodyVoiceCount);
for (int i = 0; i < numVoice; i++) {
setInstrument(i, _currentInstruments[i]);
setVoiceVolume(i, kMaxVolume);
}
_modifyInstrument = 0xFF;
}
bool ADLPlayer::load(Common::SeekableReadStream &adl) {
unload();
int timbreCount;
if (!readHeader(adl, timbreCount)) {
unload();
return false;
}
if (!readTimbres(adl, timbreCount) || !readSongData(adl) || adl.err()) {
unload();
return false;
}
rewind();
return true;
}
bool ADLPlayer::readHeader(Common::SeekableReadStream &adl, int &timbreCount) {
// Sanity check
if (adl.size() < 60) {
warning("ADLPlayer::readHeader(): File too small (%d)", (int)adl.size());
return false;
}
_soundMode = adl.readByte();
timbreCount = adl.readByte() + 1;
adl.skip(1);
return true;
}
bool ADLPlayer::readTimbres(Common::SeekableReadStream &adl, int timbreCount) {
_timbres.resize(timbreCount);
for (auto &timbre : _timbres) {
for (int i = 0; i < (kOperatorsPerVoice * kParamCount); i++)
timbre.startParams[i] = adl.readUint16LE();
}
if (adl.err()) {
warning("ADLPlayer::readTimbres(): Read failed");
return false;
}
return true;
}
bool ADLPlayer::readSongData(Common::SeekableReadStream &adl) {
_songDataSize = adl.size() - adl.pos();
_songData = new byte[_songDataSize];
if (adl.read(_songData, _songDataSize) != _songDataSize) {
warning("ADLPlayer::readSongData(): Read failed");
return false;
}
return true;
}
bool ADLPlayer::load(const byte *data, uint32 dataSize, int index) {
unload();
Common::MemoryReadStream stream(data, dataSize);
if (!load(stream))
return false;
_index = index;
return true;
}
void ADLPlayer::setInstrument(int voice, int instrument) {
if ((voice >= kMaxVoiceCount) || ((uint)instrument >= _timbres.size()))
return;
_currentInstruments[voice] = instrument;
setVoiceTimbre(voice, _timbres[instrument].params);
}
int ADLPlayer::getIndex() const {
return _index;
}
} // End of namespace Gob

View File

@@ -0,0 +1,88 @@
/* 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/>.
*
*
* This file is dual-licensed.
* In addition to the GPLv3 license mentioned above, this code is also
* licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
* full text of the license.
*
*/
#ifndef GOB_SOUND_ADLPLAYER_H
#define GOB_SOUND_ADLPLAYER_H
#include "common/array.h"
#include "gob/sound/adlib.h"
namespace Common {
class SeekableReadStream;
}
namespace Gob {
/** A player for Coktel Vision's ADL music format. */
class ADLPlayer : public AdLib {
public:
ADLPlayer();
~ADLPlayer() override;
bool load(Common::SeekableReadStream &adl);
bool load(const byte *data, uint32 dataSize, int index = -1);
void unload();
int getIndex() const;
protected:
// AdLib interface
uint32 pollMusic(bool first) override;
void rewind() override;
private:
struct Timbre {
uint16 startParams[kOperatorsPerVoice * kParamCount];
uint16 params[kOperatorsPerVoice * kParamCount];
};
uint8 _soundMode;
Common::Array<Timbre> _timbres;
byte *_songData;
uint32 _songDataSize;
const byte *_playPos;
int _index;
uint8 _modifyInstrument;
uint16 _currentInstruments[kMaxVoiceCount];
void setInstrument(int voice, int instrument);
bool readHeader (Common::SeekableReadStream &adl, int &timbreCount);
bool readTimbres (Common::SeekableReadStream &adl, int timbreCount);
bool readSongData(Common::SeekableReadStream &adl);
};
} // End of namespace Gob
#endif // GOB_SOUND_ADLPLAYER_H

View File

@@ -0,0 +1,145 @@
/* 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/>.
*
*
* This file is dual-licensed.
* In addition to the GPLv3 license mentioned above, this code is also
* licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
* full text of the license.
*
*/
#include "common/array.h"
#include "gob/sound/bgatmosphere.h"
#include "gob/sound/sound.h"
#include "gob/sound/sounddesc.h"
namespace Gob {
BackgroundAtmosphere::BackgroundAtmosphere(Audio::Mixer &mixer) :
SoundMixer(mixer, Audio::Mixer::kMusicSoundType), _rnd("gobBA") {
_playMode = Sound::kPlayModeLinear;
_queuePos = -1;
_shaded = false;
_shadable = true;
}
BackgroundAtmosphere::~BackgroundAtmosphere() {
queueClear();
}
void BackgroundAtmosphere::playBA() {
Common::StackLock slock(_mutex);
_queuePos = -1;
getNextQueuePos();
if (_queuePos == -1)
return;
SoundMixer::play(*_queue[_queuePos], 1, 0);
}
void BackgroundAtmosphere::stopBA() {
SoundMixer::stop(0);
}
void BackgroundAtmosphere::setPlayMode(Sound::BackgroundPlayMode mode) {
_playMode = mode;
}
void BackgroundAtmosphere::queueSample(SoundDesc &sndDesc) {
Common::StackLock slock(_mutex);
_queue.push_back(&sndDesc);
}
void BackgroundAtmosphere::queueClear() {
Common::StackLock slock(_mutex);
SoundMixer::stop(0);
for (uint i = 0; i < _queue.size(); i++)
delete _queue[i];
_queue.clear();
_queuePos = -1;
}
void BackgroundAtmosphere::checkEndSample() {
Common::StackLock slock(_mutex);
getNextQueuePos();
if (_queuePos == -1) {
_end = true;
_playingSound = 0;
} else {
SoundMixer::setSample(*_queue[_queuePos], 1, 0, 0);
if (_shaded)
_fadeVol = 20000;
}
}
void BackgroundAtmosphere::getNextQueuePos() {
if (_queue.size() == 0) {
_queuePos = -1;
return;
}
switch (_playMode) {
case Sound::kPlayModeLinear:
default:
_queuePos = (_queuePos + 1) % _queue.size();
break;
case Sound::kPlayModeRandom:
_queuePos = _rnd.getRandomNumber(_queue.size() - 1);
break;
}
}
void BackgroundAtmosphere::setShadable(bool shadable) {
if (!shadable) {
unshade();
_shadable = false;
} else
_shadable = true;
}
void BackgroundAtmosphere::shade() {
if (!_shadable)
return;
_shaded = true;
_fadeVol = 32768;
}
void BackgroundAtmosphere::unshade() {
if (!_shadable)
return;
_shaded = false;
_fadeVol = 65536;
}
} // End of namespace Gob

View File

@@ -0,0 +1,81 @@
/* 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/>.
*
*
* This file is dual-licensed.
* In addition to the GPLv3 license mentioned above, this code is also
* licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
* full text of the license.
*
*/
#ifndef GOB_SOUND_BGATMOSPHERE_H
#define GOB_SOUND_BGATMOSPHERE_H
#include "common/array.h"
#include "common/mutex.h"
#include "common/random.h"
#include "gob/sound/sound.h"
#include "gob/sound/soundmixer.h"
namespace Audio {
class Mixer;
}
namespace Gob {
class SoundDesc;
class BackgroundAtmosphere : private SoundMixer {
public:
BackgroundAtmosphere(Audio::Mixer &mixer);
~BackgroundAtmosphere() override;
void playBA();
void stopBA();
void setPlayMode(Sound::BackgroundPlayMode mode);
void queueSample(SoundDesc &sndDesc);
void queueClear();
void setShadable(bool shadable);
void shade();
void unshade();
private:
Sound::BackgroundPlayMode _playMode;
Common::Array<SoundDesc *> _queue;
int _queuePos;
bool _shaded;
bool _shadable;
Common::Mutex _mutex;
Common::RandomSource _rnd;
void checkEndSample() override;
void getNextQueuePos();
};
} // End of namespace Gob
#endif // GOB_SOUND_BGATMOSPHERE_H

206
engines/gob/sound/cdrom.cpp Normal file
View File

@@ -0,0 +1,206 @@
/* 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/>.
*
*
* This file is dual-licensed.
* In addition to the GPLv3 license mentioned above, this code is also
* licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
* full text of the license.
*
*/
#include "common/endian.h"
#include "common/str.h"
#include "common/textconsole.h"
#include "common/util.h"
#include "backends/audiocd/audiocd.h"
#include "gob/gob.h"
#include "gob/sound/cdrom.h"
#include "gob/dataio.h"
namespace Gob {
CDROM::CDROM() {
_cdPlaying = false;
_LICbuffer = nullptr;
for (int i = 0; i < 16; i++)
_curTrack[i] = 0;
_numTracks = 0;
_trackStop = 0;
_startTime = 0;
}
CDROM::~CDROM() {
stop();
}
void CDROM::readLIC(Common::SeekableReadStream &stream) {
uint16 version, startChunk, pos;
freeLICBuffer();
*_curTrack = 0;
version = stream.readUint16LE();
startChunk = stream.readUint16LE();
_numTracks = stream.readUint16LE();
if (version != 3)
error("Unknown version %d while reading LIC", version);
stream.seek(50);
for (int i = 0; i < startChunk; i++) {
pos = stream.readUint16LE();
if (!pos)
break;
stream.skip(pos);
}
_LICbuffer = new byte[_numTracks * 22];
stream.read(_LICbuffer, _numTracks * 22);
}
void CDROM::freeLICBuffer() {
delete[] _LICbuffer;
_LICbuffer = nullptr;
}
void CDROM::startTrack(const char *trackName) {
if (!_LICbuffer)
return;
byte *matchPtr = getTrackBuffer(trackName);
if (!matchPtr) {
warning("CDROM: Track \"%s\" not found", trackName);
return;
}
Common::String curTrack(trackName);
curTrack.toUppercase();
Common::strlcpy(_curTrack, curTrack.c_str(), 16);
stopPlaying();
_curTrackBuffer = matchPtr;
while (getTrackPos() >= 0)
;
uint32 start = READ_LE_UINT32(matchPtr + 12);
uint32 end = READ_LE_UINT32(matchPtr + 16);
play(start, end);
_startTime = g_system->getMillis();
_trackStop = _startTime + (end - start + 1 + 150) * 40 / 3;
}
void CDROM::play(uint32 from, uint32 to) {
// play from sector [from] to sector [to]
// format is HSG:
// HSG encodes frame information into a double word:
// minute multiplied by 4500, plus second multiplied by 75,
// plus frame, minus 150
g_system->getAudioCDManager()->play(1, 1, from, to - from + 1);
_cdPlaying = true;
}
bool CDROM::isPlaying() const {
return _cdPlaying;
}
int32 CDROM::getTrackPos(const char *keyTrack) const {
byte *keyBuffer = getTrackBuffer(keyTrack);
uint32 curPos = (g_system->getMillis() - _startTime) * 3 / 40;
if (_cdPlaying && (g_system->getMillis() < _trackStop)) {
if (keyBuffer && _curTrackBuffer && (keyBuffer != _curTrackBuffer)) {
uint32 kStart = READ_LE_UINT32(keyBuffer + 12);
uint32 kEnd = READ_LE_UINT32(keyBuffer + 16);
uint32 cStart = READ_LE_UINT32(_curTrackBuffer + 12);
uint32 cEnd = READ_LE_UINT32(_curTrackBuffer + 16);
if ((kStart >= cStart) && (kEnd <= cEnd)) {
if ((kStart - cStart) > curPos)
return -2;
if ((kEnd - cStart) < curPos)
return -1;
}
}
return curPos;
} else
return -1;
}
const char *CDROM::getCurTrack() const {
return _curTrack;
}
void CDROM::stopPlaying() {
stop();
while (getTrackPos() != -1)
;
}
void CDROM::stop() {
_curTrackBuffer = nullptr;
g_system->getAudioCDManager()->stop();
_cdPlaying = false;
}
void CDROM::testCD(int trySubst, const char *label) {
if (!trySubst) {
error("CDROM track substitution is not supported");
return;
}
_LICbuffer = nullptr;
_cdPlaying = false;
// Original checked CD label here
// but will skip it as it will require OSystem extensions of direct
// CD secor reading
}
byte *CDROM::getTrackBuffer(const char *trackName) const {
if (!_LICbuffer || !trackName)
return nullptr;
byte *matchPtr = nullptr;
byte *curPtr = _LICbuffer;
for (int i = 0; i < _numTracks; i++) {
if (!scumm_stricmp((char *)curPtr, trackName)) {
matchPtr = curPtr;
break;
}
curPtr += 22;
}
return matchPtr;
}
} // End of namespace Gob

68
engines/gob/sound/cdrom.h Normal file
View File

@@ -0,0 +1,68 @@
/* 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/>.
*
*
* This file is dual-licensed.
* In addition to the GPLv3 license mentioned above, this code is also
* licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
* full text of the license.
*
*/
#ifndef GOB_SOUND_CDROM_H
#define GOB_SOUND_CDROM_H
namespace Gob {
class CDROM {
public:
CDROM();
~CDROM();
void readLIC(Common::SeekableReadStream &stream);
void freeLICBuffer();
void startTrack(const char *trackName);
void stopPlaying();
bool isPlaying() const;
int32 getTrackPos(const char *keyTrack = 0) const;
const char *getCurTrack() const;
void testCD(int trySubst, const char *label);
protected:
byte *_LICbuffer;
byte *_curTrackBuffer;
char _curTrack[16];
uint16 _numTracks;
uint32 _trackStop;
uint32 _startTime;
bool _cdPlaying;
void play(uint32 from, uint32 to);
void stop();
byte *getTrackBuffer(const char *trackName) const;
};
} // End of namespace Gob
#endif // GOB_SOUND_CDROM_H

View File

@@ -0,0 +1,107 @@
/* 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/>.
*
*
* This file is dual-licensed.
* In addition to the GPLv3 license mentioned above, this code is also
* licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
* full text of the license.
*
*/
#include "common/textconsole.h"
#include "gob/sound/infogrames.h"
namespace Gob {
Infogrames::Infogrames(Audio::Mixer &mixer) : _mixer(&mixer) {
_instruments = nullptr;
_song = nullptr;
}
Infogrames::~Infogrames() {
clearSong();
clearInstruments();
}
bool Infogrames::loadInstruments(const char *fileName) {
clearSong();
clearInstruments();
return loadInst(fileName);
}
bool Infogrames::loadSong(const char *fileName) {
clearSong();
if (!_instruments)
if (!loadInst("i1.ins"))
return false;
_song = new Audio::Infogrames(*_instruments, true,
_mixer->getOutputRate(), _mixer->getOutputRate() / 75);
if (!_song->load(fileName)) {
warning("Infogrames: Couldn't load music \"%s\"", fileName);
clearSong();
return false;
}
return true;
}
void Infogrames::play() {
if (_song && !_mixer->isSoundHandleActive(_handle)) {
_song->restart();
_mixer->playStream(Audio::Mixer::kMusicSoundType,
&_handle, _song, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO);
}
}
void Infogrames::stop() {
_mixer->stopHandle(_handle);
}
void Infogrames::clearInstruments() {
delete _instruments;
_instruments = nullptr;
}
void Infogrames::clearSong() {
if (_song) {
_mixer->stopHandle(_handle);
delete _song;
_song = nullptr;
}
}
bool Infogrames::loadInst(const char *fileName) {
_instruments = new Audio::Infogrames::Instruments;
if (!_instruments->load(fileName)) {
warning("Infogrames: Couldn't load instruments \"%s\"", fileName);
clearInstruments();
return false;
}
return true;
}
} // End of namespace Gob

View File

@@ -0,0 +1,62 @@
/* 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/>.
*
*
* This file is dual-licensed.
* In addition to the GPLv3 license mentioned above, this code is also
* licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
* full text of the license.
*
*/
#ifndef GOB_SOUND_INFOGRAMES_H
#define GOB_SOUND_INFOGRAMES_H
#include "audio/mixer.h"
#include "audio/mods/infogrames.h"
namespace Gob {
class Infogrames {
public:
Infogrames(Audio::Mixer &mixer);
~Infogrames();
bool loadInstruments(const char *fileName);
bool loadSong(const char *fileName);
void play();
void stop();
private:
Audio::Mixer *_mixer;
Audio::Infogrames::Instruments *_instruments;
Audio::Infogrames *_song;
Audio::SoundHandle _handle;
void clearInstruments();
void clearSong();
bool loadInst(const char *fileName);
};
} // End of namespace Gob
#endif // GOB_SOUND_INFOGRAMES_H

View File

@@ -0,0 +1,392 @@
/* 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/>.
*
*
* This file is dual-licensed.
* In addition to the GPLv3 license mentioned above, this code is also
* licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
* full text of the license.
*
*/
#include "common/stream.h"
#include "common/textconsole.h"
#include "gob/sound/musplayer.h"
namespace Gob {
MUSPlayer::MUSPlayer() : AdLib(60),
_songData(nullptr), _songDataSize(0), _playPos(nullptr), _songID(0) {
}
MUSPlayer::~MUSPlayer() {
unload();
}
void MUSPlayer::unload() {
stopPlay();
unloadSND();
unloadMUS();
}
void MUSPlayer::skipToTiming() {
while (*_playPos < 0x80)
_playPos++;
if (*_playPos != 0xF8)
_playPos--;
}
uint32 MUSPlayer::pollMusic(bool first) {
if (_timbres.empty() || !_songData || !_playPos || (_playPos >= (_songData + _songDataSize))) {
end();
return 0;
}
if (first) {
// Set the timer frequency on first run.
// Do not set it in rewind() for thread safety reasons.
setTimerFrequency((_ticksPerBeat * _tempo) / 60);
return *_playPos++;
}
uint16 delay = 0;
while (delay == 0) {
byte cmd = *_playPos;
// Delay overflow
if (cmd == 0xF8) {
_playPos++;
delay = 0xF8;
break;
}
// Song end marker
if (cmd == 0xFC) {
end();
return 0;
}
// Global command
if (cmd == 0xF0) {
_playPos++;
byte type1 = *_playPos++;
byte type2 = *_playPos++;
if ((type1 == 0x7F) && (type2 == 0)) {
// Tempo change, as a fraction of the base tempo
uint32 num = *_playPos++;
uint32 denom = *_playPos++;
_tempo = _baseTempo * num + ((_baseTempo * denom) >> 7);
setTimerFrequency((_ticksPerBeat * _tempo) / 60);
_playPos++;
} else {
// Unsupported global command, skip it
_playPos -= 2;
while(*_playPos++ != 0xF7)
;
}
delay = *_playPos++;
break;
}
// Voice command
if (cmd >= 0x80) {
_playPos++;
_lastCommand = cmd;
} else
cmd = _lastCommand;
uint8 voice = cmd & 0x0F;
uint8 note, volume;
uint16 pitch;
switch (cmd & 0xF0) {
case 0x80: // Note off
_playPos += 2;
noteOff(voice);
break;
case 0x90: // Note on
note = *_playPos++;
volume = *_playPos++;
if (volume) {
setVoiceVolume(voice, volume);
noteOn(voice, note);
} else
noteOff(voice);
break;
case 0xA0: // Set volume
setVoiceVolume(voice, *_playPos++);
break;
case 0xB0:
_playPos += 2;
break;
case 0xC0: // Set instrument
setInstrument(voice, *_playPos++);
break;
case 0xD0:
_playPos++;
break;
case 0xE0: // Pitch bend
pitch = *_playPos++;
pitch += *_playPos++ << 7;
bendVoicePitch(voice, pitch);
break;
default:
warning("MUSPlayer: Unsupported command: 0x%02X", cmd);
skipToTiming();
break;
}
delay = *_playPos++;
}
if (delay == 0xF8) {
delay = 240;
if (*_playPos != 0xF8)
delay += *_playPos++;
}
return delay;
}
void MUSPlayer::rewind() {
_playPos = _songData;
_tempo = _baseTempo;
_lastCommand = 0;
setPercussionMode(_soundMode != 0);
setPitchRange(_pitchBendRange);
}
bool MUSPlayer::loadSND(Common::SeekableReadStream &snd) {
unloadSND();
int timbreCount, timbrePos;
if (!readSNDHeader(snd, timbreCount, timbrePos))
return false;
if (!readSNDTimbres(snd, timbreCount, timbrePos) || snd.err()) {
unloadSND();
return false;
}
return true;
}
bool MUSPlayer::readString(Common::SeekableReadStream &stream, Common::String &string, byte *buffer, uint size) {
if (stream.read(buffer, size) != size)
return false;
buffer[size] = '\0';
string = (char *) buffer;
return true;
}
bool MUSPlayer::readSNDHeader(Common::SeekableReadStream &snd, int &timbreCount, int &timbrePos) {
// Sanity check
if (snd.size() <= 6) {
warning("MUSPlayer::readSNDHeader(): File too small (%d)", (int)snd.size());
return false;
}
// Version
const uint8 versionMajor = snd.readByte();
const uint8 versionMinor = snd.readByte();
if ((versionMajor != 1) && (versionMinor != 0)) {
warning("MUSPlayer::readSNDHeader(): Unsupported version %d.%d", versionMajor, versionMinor);
return false;
}
// Number of timbres and where they start
timbreCount = snd.readUint16LE();
timbrePos = snd.readUint16LE();
const uint16 minTimbrePos = 6 + timbreCount * 9;
// Sanity check
if (timbrePos < minTimbrePos) {
warning("MUSPlayer::readSNDHeader(): Timbre offset too small: %d < %d", timbrePos, minTimbrePos);
return false;
}
const uint32 timbreParametersSize = snd.size() - timbrePos;
const uint32 paramSize = kOperatorsPerVoice * kParamCount * sizeof(uint16);
// Sanity check
if (timbreParametersSize != (timbreCount * paramSize)) {
warning("MUSPlayer::loadSND(): Timbre parameters size mismatch: %d != %d",
timbreParametersSize, timbreCount * paramSize);
return false;
}
return true;
}
bool MUSPlayer::readSNDTimbres(Common::SeekableReadStream &snd, int timbreCount, int timbrePos) {
_timbres.resize(timbreCount);
// Read names
byte nameBuffer[10];
for (auto &timbre : _timbres) {
if (!readString(snd, timbre.name, nameBuffer, 9)) {
warning("MUSPlayer::readMUSTimbres(): Failed to read timbre name");
return false;
}
}
if (!snd.seek(timbrePos)) {
warning("MUSPlayer::readMUSTimbres(): Failed to seek to timbres");
return false;
}
// Read parameters
for (auto &timbre : _timbres) {
for (int i = 0; i < (kOperatorsPerVoice * kParamCount); i++)
timbre.params[i] = snd.readUint16LE();
}
return true;
}
bool MUSPlayer::loadMUS(Common::SeekableReadStream &mus) {
unloadMUS();
if (!readMUSHeader(mus) || !readMUSSong(mus) || mus.err()) {
unloadMUS();
return false;
}
rewind();
return true;
}
bool MUSPlayer::readMUSHeader(Common::SeekableReadStream &mus) {
// Sanity check
if (mus.size() <= 6)
return false;
// Version
const uint8 versionMajor = mus.readByte();
const uint8 versionMinor = mus.readByte();
if ((versionMajor != 1) && (versionMinor != 0)) {
warning("MUSPlayer::readMUSHeader(): Unsupported version %d.%d", versionMajor, versionMinor);
return false;
}
_songID = mus.readUint32LE();
byte nameBuffer[31];
if (!readString(mus, _songName, nameBuffer, 30)) {
warning("MUSPlayer::readMUSHeader(): Failed to read the song name");
return false;
}
_ticksPerBeat = mus.readByte();
_beatsPerMeasure = mus.readByte();
mus.skip(4); // Length of song in ticks
_songDataSize = mus.readUint32LE();
mus.skip(4); // Number of commands
mus.skip(8); // Unused
_soundMode = mus.readByte();
_pitchBendRange = mus.readByte();
_baseTempo = mus.readUint16LE();
mus.skip(8); // Unused
return true;
}
bool MUSPlayer::readMUSSong(Common::SeekableReadStream &mus) {
const uint32 realSongDataSize = mus.size() - mus.pos();
if (realSongDataSize < _songDataSize) {
warning("MUSPlayer::readMUSSong(): File too small for the song data: %d < %d", realSongDataSize, _songDataSize);
return false;
}
_songData = new byte[_songDataSize];
if (mus.read(_songData, _songDataSize) != _songDataSize) {
warning("MUSPlayer::readMUSSong(): Read failed");
return false;
}
return true;
}
void MUSPlayer::unloadSND() {
_timbres.clear();
}
void MUSPlayer::unloadMUS() {
delete[] _songData;
_songData = nullptr;
_songDataSize = 0;
_playPos = nullptr;
}
uint32 MUSPlayer::getSongID() const {
return _songID;
}
const Common::String &MUSPlayer::getSongName() const {
return _songName;
}
void MUSPlayer::setInstrument(uint8 voice, uint8 instrument) {
if (instrument >= _timbres.size())
return;
setVoiceTimbre(voice, _timbres[instrument].params);
}
} // End of namespace Gob

View File

@@ -0,0 +1,113 @@
/* 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/>.
*
*
* This file is dual-licensed.
* In addition to the GPLv3 license mentioned above, this code is also
* licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
* full text of the license.
*
*/
#ifndef GOB_SOUND_MUSPLAYER_H
#define GOB_SOUND_MUSPLAYER_H
#include "common/str.h"
#include "common/array.h"
#include "gob/sound/adlib.h"
namespace Common {
class SeekableReadStream;
}
namespace Gob {
/** A player for the AdLib MUS format, with the instrument information in SND files.
*
* In the Gob engine, those files are usually named .MDY and .TBR instead.
*/
class MUSPlayer : public AdLib {
public:
MUSPlayer();
~MUSPlayer() override;
/** Load the instruments (.SND or .TBR) */
bool loadSND(Common::SeekableReadStream &snd);
/** Load the melody (.MUS or .MDY) */
bool loadMUS(Common::SeekableReadStream &mus);
void unload();
uint32 getSongID() const;
const Common::String &getSongName() const;
protected:
// AdLib interface
uint32 pollMusic(bool first) override;
void rewind() override;
private:
struct Timbre {
Common::String name;
uint16 params[kOperatorsPerVoice * kParamCount];
};
Common::Array<Timbre> _timbres;
byte *_songData;
uint32 _songDataSize;
const byte *_playPos;
uint32 _songID;
Common::String _songName;
uint8 _ticksPerBeat;
uint8 _beatsPerMeasure;
uint8 _soundMode;
uint8 _pitchBendRange;
uint16 _baseTempo;
uint16 _tempo;
byte _lastCommand;
void unloadSND();
void unloadMUS();
bool readSNDHeader (Common::SeekableReadStream &snd, int &timbreCount, int &timbrePos);
bool readSNDTimbres(Common::SeekableReadStream &snd, int timbreCount, int timbrePos);
bool readMUSHeader(Common::SeekableReadStream &mus);
bool readMUSSong (Common::SeekableReadStream &mus);
void setInstrument(uint8 voice, uint8 instrument);
void skipToTiming();
static bool readString(Common::SeekableReadStream &stream, Common::String &string, byte *buffer, uint size);
};
} // End of namespace Gob
#endif // GOB_SOUND_MUSPLAYER_H

View File

@@ -0,0 +1,55 @@
/* 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/>.
*
*
* This file is dual-licensed.
* In addition to the GPLv3 license mentioned above, this code is also
* licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
* full text of the license.
*
*/
#include "audio/softsynth/pcspk.h"
#include "gob/sound/pcspeaker.h"
namespace Gob {
PCSpeaker::PCSpeaker() {
_speaker = new Audio::PCSpeaker();
_speaker->init();
}
PCSpeaker::~PCSpeaker() {
delete _speaker;
}
void PCSpeaker::speakerOn(int16 frequency, int32 length) {
_speaker->play(Audio::PCSpeaker::kWaveFormSquare, frequency, length);
}
void PCSpeaker::speakerOff() {
_speaker->stop();
}
void PCSpeaker::onUpdate(uint32 millis) {
if (_speaker->isPlaying())
_speaker->stop(millis);
}
} // End of namespace Gob

View File

@@ -0,0 +1,54 @@
/* 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/>.
*
*
* This file is dual-licensed.
* In addition to the GPLv3 license mentioned above, this code is also
* licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
* full text of the license.
*
*/
#ifndef GOB_SOUND_PCSPEAKER_H
#define GOB_SOUND_PCSPEAKER_H
#include "common/scummsys.h"
namespace Audio {
class PCSpeaker;
}
namespace Gob {
class PCSpeaker {
public:
PCSpeaker();
~PCSpeaker();
void speakerOn(int16 frequency, int32 length = -1);
void speakerOff();
void onUpdate(uint32 millis);
private:
Audio::PCSpeaker *_speaker;
};
} // End of namespace Gob
#endif // GOB_SOUND_PCSPEAKER_H

View File

@@ -0,0 +1,73 @@
/* 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/>.
*
*
* This file is dual-licensed.
* In addition to the GPLv3 license mentioned above, this code is also
* licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
* full text of the license.
*
*/
#include "common/file.h"
#include "audio/audiostream.h"
#include "audio/mods/protracker.h"
#include "gob/sound/protracker.h"
namespace Gob {
Protracker::Protracker(Audio::Mixer &mixer) : _mixer(&mixer) {
_protrackerStream = nullptr;
}
Protracker::~Protracker() {
stop();
}
bool Protracker::play(const char *fileName) {
stop();
Common::File f;
if (!f.open(fileName))
return false;
_protrackerStream = Audio::makeProtrackerStream(&f);
if (!_protrackerStream)
return false;
_mixer->playStream(Audio::Mixer::kMusicSoundType, &_handle,
_protrackerStream, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO);
return true;
}
void Protracker::stop() {
if (_protrackerStream) {
_mixer->stopHandle(_handle);
delete _protrackerStream;
_protrackerStream = nullptr;
}
}
} // End of namespace Gob

View File

@@ -0,0 +1,56 @@
/* 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/>.
*
*
* This file is dual-licensed.
* In addition to the GPLv3 license mentioned above, this code is also
* licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
* full text of the license.
*
*/
#ifndef GOB_SOUND_PROTRACKER_H
#define GOB_SOUND_PROTRACKER_H
#include "audio/mixer.h"
namespace Audio {
class AudioStream;
}
namespace Gob {
class Protracker {
public:
Protracker(Audio::Mixer &mixer);
~Protracker();
bool play(const char *fileName);
void stop();
private:
Audio::Mixer *_mixer;
Audio::AudioStream *_protrackerStream;
Audio::SoundHandle _handle;
};
} // End of namespace Gob
#endif // GOB_SOUND_PROTRACKER_H

778
engines/gob/sound/sound.cpp Normal file
View File

@@ -0,0 +1,778 @@
/* 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/>.
*
*
* This file is dual-licensed.
* In addition to the GPLv3 license mentioned above, this code is also
* licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
* full text of the license.
*
*/
#include "gob/gob.h"
#include "gob/sound/sound.h"
#include "gob/global.h"
#include "gob/util.h"
#include "gob/dataio.h"
#include "gob/game.h"
#include "gob/inter.h"
#include "gob/sound/bgatmosphere.h"
#include "gob/sound/pcspeaker.h"
#include "gob/sound/soundblaster.h"
#include "gob/sound/adlplayer.h"
#include "gob/sound/musplayer.h"
#include "gob/sound/infogrames.h"
#include "gob/sound/protracker.h"
#include "gob/sound/cdrom.h"
namespace Gob {
Sound::Sound(GobEngine *vm) : _vm(vm) {
_pcspeaker = new PCSpeaker();
_blaster = new SoundBlaster(*_vm->_mixer);
_adlPlayer = nullptr;
_mdyPlayer = nullptr;
_infogrames = nullptr;
_protracker = nullptr;
_cdrom = nullptr;
_bgatmos = nullptr;
_hasAdLib = (!_vm->_noMusic && _vm->hasAdLib());
_hasAdLibBg = _hasAdLib;
if (!_vm->_noMusic && (_vm->getPlatform() == Common::kPlatformAmiga)) {
_infogrames = new Infogrames(*_vm->_mixer);
_protracker = new Protracker(*_vm->_mixer);
}
if (_vm->isCD())
_cdrom = new CDROM;
if (_vm->getGameType() == kGameTypeWoodruff)
_bgatmos = new BackgroundAtmosphere(*_vm->_mixer);
if (_vm->getGameType() == kGameTypeUrban ||
_vm->getGameType() == kGameTypeAdibou2 ||
_vm->getGameType() == kGameTypeAdi4) {
_bgatmos = new BackgroundAtmosphere(*_vm->_mixer);
_bgatmos->setShadable(false);
}
}
Sound::~Sound() {
delete _pcspeaker;
delete _blaster;
delete _adlPlayer;
delete _mdyPlayer;
delete _infogrames;
delete _protracker;
delete _cdrom;
delete _bgatmos;
for (int i = 0; i < kSoundsCount; i++)
_sounds[i].free();
}
void Sound::convToSigned(byte *buffer, int length) {
while (length-- > 0)
*buffer++ ^= 0x80;
}
SoundDesc *Sound::sampleGetBySlot(int slot) {
if ((slot < 0) || (slot >= kSoundsCount))
return nullptr;
return &_sounds[slot];
}
const SoundDesc *Sound::sampleGetBySlot(int slot) const {
if ((slot < 0) || (slot >= kSoundsCount))
return nullptr;
return &_sounds[slot];
}
int Sound::sampleGetNextFreeSlot() const {
for (int i = 0; i < kSoundsCount; i++)
if (_sounds[i].empty())
return i;
return -1;
}
bool Sound::sampleLoad(SoundDesc *sndDesc, SoundType type, const char *fileName) {
if (!sndDesc)
return false;
debugC(2, kDebugSound, "Loading sample \"%s\"", fileName);
int32 size;
byte *data = _vm->_dataIO->getFile(fileName, size);
if (!data || !sndDesc->load(type, data, size)) {
delete[] data;
warning("Sound::sampleLoad(): Failed to load sound \"%s\"", fileName);
return false;
}
return true;
}
void Sound::sampleFree(SoundDesc *sndDesc, bool noteAdLib, int index) {
if (!sndDesc || sndDesc->empty())
return;
if (sndDesc->getType() == SOUND_ADL) {
if (noteAdLib) {
if (_adlPlayer)
if ((index == -1) || (_adlPlayer->getIndex() == index))
_adlPlayer->unload();
}
} else {
if (_blaster)
_blaster->stopSound(0, sndDesc);
}
sndDesc->free();
}
void Sound::speakerOn(int16 frequency, int32 length) {
if (!_pcspeaker)
return;
debugC(1, kDebugSound, "PCSpeaker: Playing tone (%d, %d)", frequency, length);
_pcspeaker->speakerOn(frequency, length);
}
void Sound::speakerOff() {
if (!_pcspeaker)
return;
debugC(1, kDebugSound, "PCSpeaker: Stopping tone");
_pcspeaker->speakerOff();
}
void Sound::speakerOnUpdate(uint32 millis) {
if (!_pcspeaker)
return;
_pcspeaker->onUpdate(millis);
}
bool Sound::infogramesLoadInstruments(const char *fileName) {
if (!_infogrames)
return false;
debugC(1, kDebugSound, "Infogrames: Loading instruments \"%s\"", fileName);
return _infogrames->loadInstruments(fileName);
}
bool Sound::infogramesLoadSong(const char *fileName) {
if (!_infogrames)
return false;
debugC(1, kDebugSound, "Infogrames: Loading song \"%s\"", fileName);
return _infogrames->loadSong(fileName);
}
bool Sound::protrackerPlay(const char *fileName) {
if (!_protracker)
return false;
debugC(1, kDebugSound, "Protracker: Playing song \"%s\"", fileName);
return _protracker->play(fileName);
}
void Sound::protrackerStop() {
if (!_protracker)
return;
debugC(1, kDebugSound, "Protracker: Stopping playback");
_protracker->stop();
}
void Sound::infogramesPlay() {
if (!_infogrames)
return;
debugC(1, kDebugSound, "Infogrames: Starting playback");
_infogrames->play();
}
void Sound::infogramesStop() {
if (!_infogrames)
return;
debugC(1, kDebugSound, "Infogrames: Stopping playback");
_infogrames->stop();
}
bool Sound::adlibLoadADL(const char *fileName) {
if (!_hasAdLib)
return false;
if (!_adlPlayer)
_adlPlayer = new ADLPlayer();
debugC(1, kDebugSound, "AdLib: Loading ADL data (\"%s\")", fileName);
Common::SeekableReadStream *stream = _vm->_dataIO->getFile(fileName);
if (!stream) {
warning("Can't open ADL file \"%s\"", fileName);
return false;
}
bool loaded = _adlPlayer->load(*stream);
delete stream;
return loaded;
}
bool Sound::adlibLoadADL(byte *data, uint32 size, int index) {
if (!_hasAdLib)
return false;
if (!_adlPlayer)
_adlPlayer = new ADLPlayer();
debugC(1, kDebugSound, "AdLib: Loading ADL data (%d)", index);
return _adlPlayer->load(data, size, index);
}
void Sound::adlibUnload() {
if (!_hasAdLib)
return;
debugC(1, kDebugSound, "AdLib: Unloading data");
if (_adlPlayer)
_adlPlayer->unload();
if (_mdyPlayer)
_mdyPlayer->unload();
}
bool Sound::adlibLoadMDY(const char *fileName) {
if (!_hasAdLib)
return false;
createMDYPlayer();
debugC(1, kDebugSound, "AdLib: Loading MDY data (\"%s\")", fileName);
Common::SeekableReadStream *stream = _vm->_dataIO->getFile(fileName);
if (!stream) {
warning("Can't open MDY file \"%s\"", fileName);
return false;
}
bool loaded = _mdyPlayer->loadMUS(*stream);
delete stream;
return loaded;
}
bool Sound::adlibLoadTBR(const char *fileName) {
if (!_hasAdLib)
return false;
createMDYPlayer();
Common::SeekableReadStream *stream = _vm->_dataIO->getFile(fileName);
if (!stream) {
warning("Can't open TBR file \"%s\"", fileName);
return false;
}
debugC(1, kDebugSound, "AdLib: Loading MDY instruments (\"%s\")", fileName);
bool loaded = _mdyPlayer->loadSND(*stream);
delete stream;
return loaded;
}
void Sound::adlibPlayTrack(const char *trackname) {
if (!_hasAdLib)
return;
createADLPlayer();
if (_adlPlayer->isPlaying())
return;
if (adlibLoadADL(trackname))
adlibPlay();
}
void Sound::adlibPlayBgMusic() {
if (!_hasAdLib || !_hasAdLibBg) // If one of those is disabled, then stop there
return;
createADLPlayer();
static const char *const tracksMac[] = {
// "musmac1.adl", // This track seems to be missing instruments...
"musmac2.adl",
"musmac3.adl",
"musmac4.adl",
"musmac5.adl",
"musmac6.adl"
};
static const char *const tracksWin[] = {
"musmac1.mid",
"musmac2.mid",
"musmac3.mid",
"musmac4.mid",
"musmac5.mid"
};
const char *track = nullptr;
if (_vm->getPlatform() == Common::kPlatformWindows)
track = tracksWin[_vm->_util->getRandom(ARRAYSIZE(tracksWin))];
else
track = tracksMac[_vm->_util->getRandom(ARRAYSIZE(tracksMac))];
if (!track || !_vm->_dataIO->hasFile(track)) {
_hasAdLibBg = false;
return;
}
adlibPlayTrack(track);
}
void Sound::adlibPlay() {
if (!_hasAdLib)
return;
debugC(1, kDebugSound, "AdLib: Starting playback");
if (_adlPlayer)
_adlPlayer->startPlay();
if (_mdyPlayer)
_mdyPlayer->startPlay();
}
void Sound::adlibStop() {
if (!_hasAdLib)
return;
debugC(1, kDebugSound, "AdLib: Stopping playback");
if (_adlPlayer)
_adlPlayer->stopPlay();
if (_mdyPlayer)
_mdyPlayer->stopPlay();
}
bool Sound::adlibIsPlaying() const {
if (!_hasAdLib)
return false;
if (_adlPlayer && _adlPlayer->isPlaying())
return true;
if (_mdyPlayer && _mdyPlayer->isPlaying())
return true;
return false;
}
int Sound::adlibGetIndex() const {
if (!_hasAdLib)
return -1;
if (_adlPlayer)
return _adlPlayer->getIndex();
return -1;
}
int32 Sound::adlibGetRepeating() const {
if (!_hasAdLib)
return false;
if (_adlPlayer)
return _adlPlayer->getRepeating();
if (_mdyPlayer)
return _mdyPlayer->getRepeating();
return false;
}
void Sound::adlibSyncVolume() {
if (!_hasAdLib)
return;
if (_adlPlayer)
_adlPlayer->syncVolume();
if (_mdyPlayer)
_mdyPlayer->syncVolume();
}
void Sound::adlibSetRepeating(int32 repCount) {
if (!_hasAdLib)
return;
if (_adlPlayer)
_adlPlayer->setRepeating(repCount);
if (_mdyPlayer)
_mdyPlayer->setRepeating(repCount);
}
void Sound::blasterPlay(SoundDesc *sndDesc, int16 repCount,
int16 frequency, int16 fadeLength) {
if (!_blaster || !sndDesc)
return;
debugC(1, kDebugSound, "SoundBlaster: Playing sample (%d, %d, %d)",
repCount, frequency, fadeLength);
blasterStopComposition();
_blaster->playSample(*sndDesc, repCount, frequency, fadeLength);
}
void Sound::blasterRepeatComposition(int32 repCount) {
_blaster->repeatComposition(repCount);
}
void Sound::blasterStop(int16 fadeLength, SoundDesc *sndDesc) {
if (!_blaster)
return;
debugC(1, kDebugSound, "SoundBlaster: Stopping playback");
_blaster->stopSound(fadeLength, sndDesc);
}
void Sound::blasterPlayComposition(const int16 *composition, int16 freqVal,
SoundDesc *sndDescs, int8 sndCount) {
if (!_blaster)
return;
debugC(1, kDebugSound, "SoundBlaster: Playing composition (%d, %d)",
freqVal, sndCount);
blasterWaitEndPlay();
_blaster->stopComposition();
if (!sndDescs)
sndDescs = _sounds;
_blaster->playComposition(composition, freqVal, sndDescs, sndCount);
}
void Sound::blasterStopComposition() {
if (!_blaster)
return;
debugC(1, kDebugSound, "SoundBlaster: Stopping composition");
_blaster->stopComposition();
}
char Sound::blasterPlayingSound() const {
if (!_blaster)
return 0;
return _blaster->getPlayingSound();
}
void Sound::blasterSetRepeating(int32 repCount) {
if (!_blaster)
return;
_blaster->setRepeating(repCount);
}
void Sound::blasterWaitEndPlay(bool interruptible, bool stopComp) {
if (!_blaster)
return;
debugC(1, kDebugSound, "SoundBlaster: Waiting for playback to end");
if (stopComp)
_blaster->endComposition();
while (_blaster->isPlaying() && !_vm->shouldQuit()) {
if (interruptible && (_vm->_util->checkKey() == kKeyEscape)) {
WRITE_VAR(57, (uint32) -1);
return;
}
_vm->_util->longDelay(200);
}
_blaster->stopSound(0);
}
void Sound::cdLoadLIC(const Common::String &fname) {
if (!_cdrom)
return;
debugC(1, kDebugSound, "CDROM: Loading LIC \"%s\"", fname.c_str());
Common::SeekableReadStream *stream = _vm->_dataIO->getFile(fname);
if (!stream)
return;
_cdrom->readLIC(*stream);
delete stream;
}
void Sound::cdUnloadLIC() {
if (!_cdrom)
return;
debugC(1, kDebugSound, "CDROM: Unloading LIC");
_cdrom->freeLICBuffer();
}
void Sound::cdPlayBgMusic() {
if (!_cdrom)
return;
static const char *const tracks[][2] = {
{"avt00.tot", "mine"},
{"avt001.tot", "nuit"},
{"avt002.tot", "campagne"},
{"avt003.tot", "extsor1"},
{"avt004.tot", "interieure"},
{"avt005.tot", "zombie"},
{"avt006.tot", "zombie"},
{"avt007.tot", "campagne"},
{"avt008.tot", "campagne"},
{"avt009.tot", "extsor1"},
{"avt010.tot", "extsor1"},
{"avt011.tot", "interieure"},
{"avt012.tot", "zombie"},
{"avt014.tot", "nuit"},
{"avt015.tot", "interieure"},
{"avt016.tot", "statue"},
{"avt017.tot", "zombie"},
{"avt018.tot", "statue"},
{"avt019.tot", "mine"},
{"avt020.tot", "statue"},
{"avt021.tot", "mine"},
{"avt022.tot", "zombie"}
};
for (int i = 0; i < ARRAYSIZE(tracks); i++)
if (_vm->isCurrentTot(tracks[i][0])) {
debugC(1, kDebugSound, "CDROM: Playing background music \"%s\" (\"%s\")", tracks[i][1], tracks[i][0]);
_cdrom->startTrack(tracks[i][1]);
break;
}
}
void Sound::cdPlayMultMusic() {
if (!_cdrom)
return;
static const char *const tracks[][6] = {
{"avt005.tot", "fra1", "all1", "ang1", "esp1", "ita1"},
{"avt006.tot", "fra2", "all2", "ang2", "esp2", "ita2"},
{"avt012.tot", "fra3", "all3", "ang3", "esp3", "ita3"},
{"avt016.tot", "fra4", "all4", "ang4", "esp4", "ita4"},
{"avt019.tot", "fra5", "all5", "ang5", "esp5", "ita5"},
{"avt022.tot", "fra6", "all6", "ang6", "esp6", "ita6"}
};
// Default to "ang?" for other languages (including EN_USA)
int language = _vm->_global->_language <= 4 ? _vm->_global->_language : 2;
for (int i = 0; i < ARRAYSIZE(tracks); i++)
if (_vm->isCurrentTot(tracks[i][0])) {
debugC(1, kDebugSound, "CDROM: Playing mult music \"%s\" (\"%s\")", tracks[i][language + 1], tracks[i][0]);
_cdrom->startTrack(tracks[i][language + 1]);
break;
}
}
void Sound::cdPlay(const Common::String &trackName) {
if (!_cdrom)
return;
debugC(1, kDebugSound, "CDROM: Playing track \"%s\"", trackName.c_str());
// WORKAROUND - In Fascination CD, in the storage room, a track has the wrong
// name in the scripts, and therefore doesn't play. This fixes the problem.
if ((_vm->getGameType() == kGameTypeFascination) && trackName.equalsIgnoreCase("boscle"))
_cdrom->startTrack("bosscle");
// WORKAROUND - In Goblins 3 CD, in the chess room, a couple of tracks have the wrong name
// in the scripts, and therefore don't play. This fixes the problem (ticket #11335).
else if ((_vm->getGameType() == kGameTypeGob3) && trackName.matchString("ECHEQUI?")) {
char name[] = "ECHIQUI1";
name[7] = trackName[7];
_cdrom->startTrack(name);
} else
_cdrom->startTrack(trackName.c_str());
}
void Sound::cdStop() {
if (!_cdrom)
return;
debugC(1, kDebugSound, "CDROM: Stopping playback");
_cdrom->stopPlaying();
}
bool Sound::cdIsPlaying() const {
if (!_cdrom)
return false;
return _cdrom->isPlaying();
}
int32 Sound::cdGetTrackPos(const char *keyTrack) const {
if (!_cdrom)
return -1;
return _cdrom->getTrackPos(keyTrack);
}
const char *Sound::cdGetCurrentTrack() const {
if (!_cdrom)
return "";
return _cdrom->getCurTrack();
}
void Sound::cdTest(int trySubst, const char *label) {
if (!_cdrom)
return;
_cdrom->testCD(trySubst, label);
}
void Sound::bgPlay(const char *file, SoundType type) {
if (!_bgatmos)
return;
debugC(1, kDebugSound, "BackgroundAtmosphere: Playing \"%s\"", file);
_bgatmos->stopBA();
_bgatmos->queueClear();
SoundDesc *sndDesc = new SoundDesc;
if (!sampleLoad(sndDesc, type, file)) {
delete sndDesc;
return;
}
_bgatmos->queueSample(*sndDesc);
_bgatmos->playBA();
}
void Sound::bgPlay(const char *base, const char *ext, SoundType type, int count) {
if (!_bgatmos)
return;
debugC(1, kDebugSound, "BackgroundAtmosphere: Playing \"%s\" (%d)", base, count);
_bgatmos->stopBA();
_bgatmos->queueClear();
SoundDesc *sndDesc;
for (int i = 1; i <= count; i++) {
Common::String fileName = Common::String::format("%s%02d.%s", base, i, ext);
sndDesc = new SoundDesc;
if (sampleLoad(sndDesc, type, fileName.c_str()))
_bgatmos->queueSample(*sndDesc);
else
delete sndDesc;
}
_bgatmos->playBA();
}
void Sound::bgStop() {
if (!_bgatmos)
return;
debugC(1, kDebugSound, "BackgroundAtmosphere: Stopping playback");
_bgatmos->stopBA();
_bgatmos->queueClear();
}
void Sound::bgSetPlayMode(Sound::BackgroundPlayMode mode) {
if (!_bgatmos)
return;
_bgatmos->setPlayMode(mode);
}
void Sound::bgShade() {
if (!_bgatmos)
return;
debugC(1, kDebugSound, "BackgroundAtmosphere: Shading playback");
_bgatmos->shade();
}
void Sound::bgUnshade() {
if (!_bgatmos)
return;
debugC(1, kDebugSound, "BackgroundAtmosphere: Unshading playback");
_bgatmos->unshade();
}
void Sound::createMDYPlayer() {
if (_mdyPlayer)
return;
delete _adlPlayer;
_adlPlayer = nullptr;
_mdyPlayer = new MUSPlayer();
}
void Sound::createADLPlayer() {
if (_adlPlayer)
return;
delete _mdyPlayer;
_mdyPlayer= nullptr;
_adlPlayer = new ADLPlayer();
}
} // End of namespace Gob

186
engines/gob/sound/sound.h Normal file
View File

@@ -0,0 +1,186 @@
/* 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/>.
*
*
* This file is dual-licensed.
* In addition to the GPLv3 license mentioned above, this code is also
* licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
* full text of the license.
*
*/
#ifndef GOB_SOUND_SOUND_H
#define GOB_SOUND_SOUND_H
#include "common/str.h"
#include "gob/sound/sounddesc.h"
namespace Gob {
class GobEngine;
class BackgroundAtmosphere;
class PCSpeaker;
class SoundBlaster;
class ADLPlayer;
class MUSPlayer;
class Infogrames;
class Protracker;
class CDROM;
class Sound {
public:
enum BackgroundPlayMode {
kPlayModeLinear,
kPlayModeRandom
};
static const int kSoundsCount = 60;
Sound(GobEngine *vm);
~Sound();
static void convToSigned(byte *buffer, int length);
// Samples
SoundDesc *sampleGetBySlot(int slot);
const SoundDesc *sampleGetBySlot(int slot) const;
int sampleGetNextFreeSlot() const;
bool sampleLoad(SoundDesc *sndDesc, SoundType type, const char *fileName);
void sampleFree(SoundDesc *sndDesc, bool noteAdLib = false, int index = -1);
// SoundBlaster
void blasterPlay(SoundDesc *sndDesc, int16 repCount,
int16 frequency, int16 fadeLength = 0);
void blasterStop(int16 fadeLength, SoundDesc *sndDesc = 0);
void blasterPlayComposition(const int16 *composition, int16 freqVal,
SoundDesc *sndDescs = 0, int8 sndCount = kSoundsCount);
void blasterStopComposition();
void blasterRepeatComposition(int32 repCount);
char blasterPlayingSound() const;
void blasterSetRepeating(int32 repCount);
void blasterWaitEndPlay(bool interruptible = false, bool stopComp = true);
// PCSpeaker
void speakerOn(int16 frequency, int32 length = -1);
void speakerOff();
void speakerOnUpdate(uint32 millis);
// AdLib
bool adlibLoadADL(const char *fileName);
bool adlibLoadADL(byte *data, uint32 size, int index = -1);
bool adlibLoadMDY(const char *fileName);
bool adlibLoadTBR(const char *fileName);
void adlibUnload();
void adlibPlayTrack(const char *trackname);
void adlibPlayBgMusic();
void adlibPlay();
void adlibStop();
bool adlibIsPlaying() const;
int adlibGetIndex() const;
int32 adlibGetRepeating() const;
void adlibSetRepeating(int32 repCount);
void adlibSyncVolume();
// Infogrames
bool infogramesLoadInstruments(const char *fileName);
bool infogramesLoadSong(const char *fileName);
void infogramesPlay();
void infogramesStop();
// Protracker
bool protrackerPlay(const char *fileName);
void protrackerStop();
// CD-ROM
void cdLoadLIC(const Common::String &fname);
void cdUnloadLIC();
void cdPlayBgMusic();
void cdPlayMultMusic();
void cdPlay(const Common::String &);
void cdStop();
bool cdIsPlaying() const;
int32 cdGetTrackPos(const char *keyTrack = 0) const;
const char *cdGetCurrentTrack() const;
void cdTest(int trySubst, const char *label);
// Background Atmosphere
void bgPlay(const char *file, SoundType type);
void bgPlay(const char *base, const char *ext, SoundType type, int count);
void bgStop();
void bgSetPlayMode(BackgroundPlayMode mode);
void bgShade();
void bgUnshade();
private:
GobEngine *_vm;
bool _hasAdLib;
bool _hasAdLibBg;
SoundDesc _sounds[kSoundsCount];
// Speaker
PCSpeaker *_pcspeaker;
// PCM based
SoundBlaster *_blaster;
BackgroundAtmosphere *_bgatmos;
// AdLib
MUSPlayer *_mdyPlayer;
ADLPlayer *_adlPlayer;
// Amiga Paula
Infogrames *_infogrames;
Protracker *_protracker;
// Audio CD
CDROM *_cdrom;
void createMDYPlayer();
void createADLPlayer();
};
} // End of namespace Gob
#endif // GOB_SOUND_SOUND_H

View File

@@ -0,0 +1,150 @@
/* 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/>.
*
*
* This file is dual-licensed.
* In addition to the GPLv3 license mentioned above, this code is also
* licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
* full text of the license.
*
*/
#include "gob/sound/soundblaster.h"
#include "gob/sound/sounddesc.h"
namespace Gob {
SoundBlaster::SoundBlaster(Audio::Mixer &mixer) : SoundMixer(mixer, Audio::Mixer::kSFXSoundType) {
_curSoundDesc = nullptr;
_compositionSamples = nullptr;
_compositionSampleCount = 0;
_compositionPos = -1;
_compositionRepCount = 0;
}
SoundBlaster::~SoundBlaster() {
}
void SoundBlaster::playSample(SoundDesc &sndDesc, int16 repCount,
int16 frequency, int16 fadeLength) {
SoundMixer::play(sndDesc, repCount, frequency, fadeLength);
}
void SoundBlaster::stopSound(int16 fadeLength, SoundDesc *sndDesc) {
Common::StackLock slock(_mutex);
if (sndDesc && (sndDesc != _curSoundDesc))
return;
_compositionRepCount = 0;
if (fadeLength <= 0)
_curSoundDesc = nullptr;
SoundMixer::stop(fadeLength);
}
void SoundBlaster::stopComposition() {
if (_compositionPos != -1) {
stopSound(0);
_compositionPos = -1;
}
}
void SoundBlaster::endComposition() {
_compositionPos = -1;
_compositionRepCount = 0;
}
void SoundBlaster::nextCompositionPos() {
int8 slot;
while ((++_compositionPos < 50) &&
((slot = _composition[_compositionPos]) != -1)) {
if ((slot >= 0) && (slot < _compositionSampleCount)) {
SoundDesc &sample = _compositionSamples[slot];
if (!sample.empty() && (sample.getType() == SOUND_SND)) {
setSample(sample, 1, 0, 0);
return;
}
}
if (_compositionPos == 49)
_compositionPos = -1;
}
_compositionPos = -1;
}
void SoundBlaster::playComposition(const int16 *composition, int16 freqVal,
SoundDesc *sndDescs, int8 sndCount) {
_compositionSamples = sndDescs;
_compositionSampleCount = sndCount;
int i = -1;
do {
i++;
_composition[i] = composition[i];
} while ((i < 49) && (composition[i] != -1));
_compositionPos = -1;
nextCompositionPos();
}
void SoundBlaster::repeatComposition(int32 repCount) {
_compositionRepCount = repCount;
}
void SoundBlaster::setSample(SoundDesc &sndDesc, int16 repCount, int16 frequency,
int16 fadeLength) {
_curSoundDesc = &sndDesc;
SoundMixer::setSample(sndDesc, repCount, frequency, fadeLength);
}
void SoundBlaster::checkEndSample() {
if (_compositionPos != -1) {
nextCompositionPos();
return;
}
if (_compositionRepCount != 0) {
if (_compositionRepCount > 0)
_compositionRepCount--;
nextCompositionPos();
if (_compositionPos != -1)
return;
}
SoundMixer::checkEndSample();
}
void SoundBlaster::endFade() {
if (_fadeVolStep > 0) {
_compositionPos = -1;
_curSoundDesc = nullptr;
}
SoundMixer::endFade();
}
} // End of namespace Gob

View File

@@ -0,0 +1,81 @@
/* 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/>.
*
*
* This file is dual-licensed.
* In addition to the GPLv3 license mentioned above, this code is also
* licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
* full text of the license.
*
*/
#ifndef GOB_SOUND_SOUNDBLASTER_H
#define GOB_SOUND_SOUNDBLASTER_H
#include "common/mutex.h"
#include "gob/sound/soundmixer.h"
namespace Audio {
class Mixer;
}
namespace Gob {
class SoundDesc;
class SoundBlaster : public SoundMixer {
public:
SoundBlaster(Audio::Mixer &mixer);
~SoundBlaster() override;
void playSample(SoundDesc &sndDesc, int16 repCount,
int16 frequency, int16 fadeLength = 0);
void stopSound(int16 fadeLength, SoundDesc *sndDesc = 0);
void playComposition(const int16 *composition, int16 freqVal,
SoundDesc *sndDescs = 0, int8 sndCount = 60);
void stopComposition();
void endComposition();
void repeatComposition(int32 repCount);
protected:
Common::Mutex _mutex;
SoundDesc *_compositionSamples;
int8 _compositionSampleCount;
int16 _composition[50];
int8 _compositionPos;
int32 _compositionRepCount;
SoundDesc *_curSoundDesc;
void setSample(SoundDesc &sndDesc, int16 repCount,
int16 frequency, int16 fadeLength) override;
void checkEndSample() override;
void endFade() override;
void nextCompositionPos();
};
} // End of namespace Gob
#endif // GOB_SOUND_SOUNDBLASTER_H

View File

@@ -0,0 +1,197 @@
/* 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/>.
*
*
* This file is dual-licensed.
* In addition to the GPLv3 license mentioned above, this code is also
* licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
* full text of the license.
*
*/
#include "common/util.h"
#include "common/memstream.h"
#include "common/textconsole.h"
#include "audio/decoders/raw.h"
#include "audio/decoders/wave.h"
#include "gob/sound/sounddesc.h"
#include "gob/resources.h"
namespace Gob {
SoundDesc::SoundDesc() {
_resource = nullptr;
_data = _dataPtr = nullptr;
_size = 0;
_type = SOUND_SND;
_repCount = 0;
_frequency = 0;
_flag = 0;
_id = 0;
_mixerFlags = 0;
}
SoundDesc::~SoundDesc() {
free();
}
void SoundDesc::swap(SoundDesc &desc) {
SWAP(_repCount , desc._repCount);
SWAP(_frequency , desc._frequency);
SWAP(_flag , desc._flag);
SWAP(_id , desc._id);
SWAP(_mixerFlags, desc._mixerFlags);
SWAP(_resource , desc._resource);
SWAP(_data , desc._data);
SWAP(_dataPtr , desc._dataPtr);
SWAP(_size , desc._size);
SWAP(_type , desc._type);
}
void SoundDesc::set(SoundType type, byte *data, uint32 dSize) {
free();
_type = type;
_data = _dataPtr = data;
_size = dSize;
}
bool SoundDesc::load(SoundType type, byte *data, uint32 dSize) {
free();
switch (type) {
case SOUND_ADL:
return loadADL(data, dSize);
case SOUND_SND:
return loadSND(data, dSize);
case SOUND_WAV:
return loadWAV(data, dSize);
default:
break;
}
return false;
}
bool SoundDesc::load(SoundType type, Resource *resource) {
if (!resource || (resource->getSize() <= 0))
return false;
if (!load(type, resource->getData(), resource->getSize()))
return false;
_resource = resource;
return true;
}
void SoundDesc::free() {
if (_resource)
delete _resource; // _data is owned by the resource, so don't delete _data
else
delete[] _data;
_resource = nullptr;
_data = nullptr;
_dataPtr = nullptr;
_id = 0;
}
void SoundDesc::convToSigned() {
if ((_type != SOUND_SND) && (_type != SOUND_WAV))
return;
if (!_data || !_dataPtr)
return;
if (_mixerFlags & Audio::FLAG_16BITS) {
byte *data = _dataPtr;
for (uint32 i = 0; i < _size; i++, data += 2)
WRITE_LE_UINT16(data, READ_LE_UINT16(data) ^ 0x8000);
} else
for (uint32 i = 0; i < _size; i++)
_dataPtr[i] ^= 0x80;
}
int16 SoundDesc::calcFadeOutLength(int16 frequency) {
return (10 * (_size / 2)) / frequency;
}
uint32 SoundDesc::calcLength(int16 repCount, int16 frequency, bool fade) {
uint32 fadeSize = fade ? _size / 2 : 0;
return ((_size * repCount - fadeSize) * 1000) / frequency;
}
bool SoundDesc::loadSND(byte *data, uint32 dSize) {
assert(dSize > 6);
_type = SOUND_SND;
_data = data;
_dataPtr = data + 6;
_frequency = MAX((int16) READ_BE_UINT16(data + 4), (int16) 4700);
_flag = data[0] ? (data[0] & 0x7F) : 8;
data[0] = 0;
_size = MIN(READ_BE_UINT32(data), dSize - 6);
return true;
}
bool SoundDesc::loadWAV(byte *data, uint32 dSize) {
Common::MemoryReadStream stream(data, dSize);
int wavSize, wavRate;
byte wavFlags;
uint16 wavtype;
if (!Audio::loadWAVFromStream(stream, wavSize, wavRate, wavFlags, &wavtype, nullptr))
return false;
if (wavFlags & Audio::FLAG_16BITS) {
_mixerFlags |= Audio::FLAG_16BITS;
wavSize >>= 1;
}
if (wavFlags & Audio::FLAG_STEREO) {
_mixerFlags |= Audio::FLAG_STEREO;
}
_data = data;
_dataPtr = data + stream.pos();
_size = wavSize;
_frequency = wavRate;
if (wavFlags & Audio::FLAG_UNSIGNED)
convToSigned();
return true;
}
bool SoundDesc::loadADL(byte *data, uint32 dSize) {
_type = SOUND_ADL;
_data = _dataPtr = data;
_size = dSize;
return true;
}
} // End of namespace Gob

View File

@@ -0,0 +1,90 @@
/* 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/>.
*
*
* This file is dual-licensed.
* In addition to the GPLv3 license mentioned above, this code is also
* licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
* full text of the license.
*
*/
#ifndef GOB_SOUND_SOUNDDESC_H
#define GOB_SOUND_SOUNDDESC_H
#include "common/endian.h"
namespace Gob {
class Resource;
enum SoundType {
SOUND_SND,
SOUND_WAV,
SOUND_ADL
};
class SoundDesc {
public:
int16 _repCount;
int16 _frequency;
int16 _flag;
int16 _id;
byte _mixerFlags;
SoundDesc();
~SoundDesc();
void swap(SoundDesc &desc);
byte *getData() { return _dataPtr; }
uint32 size() const { return _size; }
bool empty() const { return !_dataPtr; }
SoundType getType() const { return _type; }
bool isId(int16 id) const { return _dataPtr && (_id == id); }
void set(SoundType type, byte *data, uint32 dSize);
bool load(SoundType type, byte *data, uint32 dSize);
bool load(SoundType type, Resource *resource);
void free();
void convToSigned();
// Which fade out length to use when the fade starts half-way through?
int16 calcFadeOutLength(int16 frequency);
uint32 calcLength(int16 repCount, int16 frequency, bool fade);
private:
Resource *_resource;
byte *_data;
byte *_dataPtr;
uint32 _size;
SoundType _type;
bool loadSND(byte *data, uint32 dSize);
bool loadWAV(byte *data, uint32 dSize);
bool loadADL(byte *data, uint32 dSize);
};
} // End of namespace Gob
#endif // GOB_SOUND_SOUNDDESC_H

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/>.
*
*
* This file is dual-licensed.
* In addition to the GPLv3 license mentioned above, this code is also
* licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
* full text of the license.
*
*/
#include "common/util.h"
#include "gob/sound/soundmixer.h"
#include "gob/sound/sounddesc.h"
#include "audio/decoders/raw.h"
namespace Gob {
SoundMixer::SoundMixer(Audio::Mixer &mixer, Audio::Mixer::SoundType type) : _mixer(&mixer) {
_playingSound = 0;
_rate = _mixer->getOutputRate();
_end = true;
_data = nullptr;
_length = 0;
_freq = 0;
_repCount = 0;
_offset = 0;
_offsetFrac = 0;
_offsetInc = 0;
_cur = 0;
_last = 0;
_fade = false;
_fadeVol = 65536;
_fadeVolStep = 0;
_fadeSamples = 0;
_curFadeSamples = 0;
_mixer->playStream(type, &_handle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true);
}
SoundMixer::~SoundMixer() {
_mixer->stopHandle(_handle);
}
inline int16 SoundMixer::getData(int offset) {
if (!_16bit)
return (int16) ((int8) _data[offset]);
else
return (int16) READ_LE_UINT16(_data + (offset * 2));
}
bool SoundMixer::isPlaying() const {
return !_end;
}
char SoundMixer::getPlayingSound() const {
return _playingSound;
}
void SoundMixer::stop(int16 fadeLength) {
Common::StackLock slock(_mutex);
if (fadeLength <= 0) {
_data = nullptr;
_end = true;
_playingSound = 0;
return;
}
_fade = true;
_fadeVol = 65536;
_fadeSamples = (int)(fadeLength * (((double) _rate) / 10.0));
_fadeVolStep = MAX((int32) 1, (int32) (65536 / _fadeSamples));
_curFadeSamples = 0;
}
void SoundMixer::setRepeating(int32 repCount) {
Common::StackLock slock(_mutex);
_repCount = repCount;
}
void SoundMixer::setSample(SoundDesc &sndDesc, int16 repCount, int16 frequency,
int16 fadeLength) {
if (frequency <= 0)
frequency = sndDesc._frequency;
sndDesc._repCount = repCount - 1;
sndDesc._frequency = frequency;
_16bit = (sndDesc._mixerFlags & Audio::FLAG_16BITS) != 0;
_data = sndDesc.getData();
_length = sndDesc.size();
_freq = frequency;
_repCount = repCount;
_end = false;
_playingSound = 1;
_offset = 0;
_offsetFrac = 0;
_offsetInc = (_freq << FRAC_BITS) / _rate;
_last = _cur;
_cur = getData(0);
_curFadeSamples = 0;
if (fadeLength == 0) {
_fade = false;
_fadeVol = 65536;
_fadeSamples = 0;
_fadeVolStep = 0;
} else {
_fade = true;
_fadeVol = 0;
_fadeSamples = (int)(fadeLength * (((double) _rate) / 10.0));
_fadeVolStep = - MAX((int32) 1, (int32) (65536 / _fadeSamples));
}
}
void SoundMixer::play(SoundDesc &sndDesc, int16 repCount, int16 frequency,
int16 fadeLength) {
Common::StackLock slock(_mutex);
if (!_end)
return;
setSample(sndDesc, repCount, frequency, fadeLength);
}
void SoundMixer::checkEndSample() {
if ((_repCount == -1) || (_repCount - 1 > 0)) {
if (_repCount != -1)
--_repCount;
_offset = 0;
_offsetFrac = 0;
_end = false;
_playingSound = 1;
} else {
_end = true;
_playingSound = 0;
}
}
int SoundMixer::readBuffer(int16 *buffer, const int numSamples) {
Common::StackLock slock(_mutex);
for (int i = 0; i < numSamples; i++) {
if (!_data)
return i;
if (_end || (_offset >= _length))
checkEndSample();
if (_end)
return i;
// Linear interpolation. See sound/rate.cpp
int16 val = (_last + (((_cur - _last) * _offsetFrac +
FRAC_HALF) >> FRAC_BITS)) << (_16bit ? 0 : 8);
*buffer++ = (val * _fadeVol) >> 16;
_offsetFrac += _offsetInc;
// Was there an integral change?
if (fracToInt(_offsetFrac) > 0) {
_last = _cur;
_cur = getData(_offset);
_offset += fracToInt(_offsetFrac);
_offsetFrac &= FRAC_LO_MASK;
}
if (_fade) {
if (++_curFadeSamples >= _fadeSamples)
endFade();
else
_fadeVol -= _fadeVolStep;
if (_fadeVol < 0)
_fadeVol = 0;
}
}
return numSamples;
}
void SoundMixer::endFade() {
if (_fadeVolStep > 0) {
_data = nullptr;
_end = true;
_playingSound = 0;
} else {
_fadeVol = 65536;
_fade = false;
}
}
} // End of namespace Gob

View File

@@ -0,0 +1,102 @@
/* 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/>.
*
*
* This file is dual-licensed.
* In addition to the GPLv3 license mentioned above, this code is also
* licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
* full text of the license.
*
*/
#ifndef GOB_SOUND_SOUNDMIXER_H
#define GOB_SOUND_SOUNDMIXER_H
#include "common/mutex.h"
#include "common/frac.h"
#include "audio/audiostream.h"
#include "audio/mixer.h"
namespace Gob {
class SoundDesc;
class SoundMixer : public Audio::AudioStream {
public:
SoundMixer(Audio::Mixer &mixer, Audio::Mixer::SoundType type);
~SoundMixer() override;
virtual void play(SoundDesc &sndDesc, int16 repCount,
int16 frequency, int16 fadeLength = 0);
virtual void stop(int16 fadeLength);
bool isPlaying() const;
char getPlayingSound() const;
void setRepeating(int32 repCount);
int readBuffer(int16 *buffer, const int numSamples) override;
bool isStereo() const override { return false; }
bool endOfData() const override { return _end; }
bool endOfStream() const override { return false; }
int getRate() const override { return _rate; }
protected:
Audio::Mixer *_mixer;
Audio::SoundHandle _handle;
Common::Mutex _mutex;
bool _16bit;
bool _end;
byte *_data;
uint32 _length;
uint32 _rate;
int32 _freq;
int32 _repCount;
uint32 _offset;
frac_t _offsetFrac;
frac_t _offsetInc;
int16 _cur;
int16 _last;
bool _fade;
int32 _fadeVol;
int32 _fadeVolStep;
uint8 _fadeLength;
uint32 _fadeSamples;
uint32 _curFadeSamples;
char _playingSound;
virtual void setSample(SoundDesc &sndDesc, int16 repCount,
int16 frequency, int16 fadeLength);
virtual void checkEndSample();
virtual void endFade();
private:
inline int16 getData(int offset);
};
} // End of namespace Gob
#endif // GOB_SOUND_SOUNDMIXER_H