aboutsummaryrefslogtreecommitdiff
path: root/engines/mortevielle
diff options
context:
space:
mode:
Diffstat (limited to 'engines/mortevielle')
-rw-r--r--engines/mortevielle/actions.cpp15
-rw-r--r--engines/mortevielle/dialogs.cpp3
-rw-r--r--engines/mortevielle/module.mk1
-rw-r--r--engines/mortevielle/mortevielle.cpp11
-rw-r--r--engines/mortevielle/mortevielle.h9
-rw-r--r--engines/mortevielle/sound.cpp802
-rw-r--r--engines/mortevielle/sound.h107
-rw-r--r--engines/mortevielle/speech.cpp611
-rw-r--r--engines/mortevielle/speech.h106
-rw-r--r--engines/mortevielle/utils.cpp52
10 files changed, 775 insertions, 942 deletions
diff --git a/engines/mortevielle/actions.cpp b/engines/mortevielle/actions.cpp
index 361917d53b..3e3db5b224 100644
--- a/engines/mortevielle/actions.cpp
+++ b/engines/mortevielle/actions.cpp
@@ -30,7 +30,6 @@
#include "mortevielle/menu.h"
#include "mortevielle/mouse.h"
#include "mortevielle/outtext.h"
-#include "mortevielle/speech.h"
#include "common/scummsys.h"
@@ -630,7 +629,7 @@ void MortevielleEngine::fctOpen() {
|| (_coreVar._currPlace == PURPLE_ROOM)
|| (_coreVar._currPlace == BLUE_ROOM)) {
if (getRandomNumber(1, 4) == 3)
- _speechManager.startSpeech(7, 9, 1);
+ _soundManager.startSpeech(7, 9, 1);
}
_openObjects[i] = _num;
displayAnimFrame(1, _num);
@@ -699,7 +698,7 @@ void MortevielleEngine::fctPlace() {
displayAnimFrame(1, 1);
handleDescriptionText(2, 165);
displayEmptyHand();
- _speechManager.startSpeech(6, -9, 1);
+ _soundManager.startSpeech(6, -9, 1);
// Do you want to enter the hidden passage?
int answer = _dialogManager.show(getEngineString(S_YES_NO), 1);
@@ -800,7 +799,7 @@ void MortevielleEngine::fctTurn() {
_crep = 997;
if ((_coreVar._currPlace == ATTIC) && (_coreVar._atticRodHoleObjectId == 159) && (_coreVar._atticBallHoleObjectId == 141)) {
handleDescriptionText(2, 167);
- _speechManager.startSpeech(7, 9, 1);
+ _soundManager.startSpeech(7, 9, 1);
int answer = _dialogManager.show(getEngineString(S_YES_NO), 1);
if (answer == 1)
_endGame = true;
@@ -810,7 +809,7 @@ void MortevielleEngine::fctTurn() {
if ((_coreVar._currPlace == SECRET_PASSAGE) && (_coreVar._secretPassageObjectId == 143)) {
handleDescriptionText(2, 175);
clearVerbBar();
- _speechManager.startSpeech(6, -9, 1);
+ _soundManager.startSpeech(6, -9, 1);
int answer = _dialogManager.show(getEngineString(S_YES_NO), 1);
if (answer == 1) {
_coreVar._currPlace = CRYPT;
@@ -932,7 +931,7 @@ void MortevielleEngine::fctKnock() {
if (_coreVar._currPlace == ROOM26) {
int rand = (getRandomNumber(0, 8)) - 4;
- _speechManager.startSpeech(11, rand, 1);
+ _soundManager.startSpeech(11, rand, 1);
int p = getPresenceStats(rand, _coreVar._faithScore, _roomDoorId);
int l = _roomDoorId;
if (l != OWN_ROOM) {
@@ -1146,7 +1145,7 @@ void MortevielleEngine::fctEnter() {
_crep = 179;
else {
int randVal = (getRandomNumber(0, 10)) - 5;
- _speechManager.startSpeech(7, randVal, 1);
+ _soundManager.startSpeech(7, randVal, 1);
displayAnimFrame(1, 1);
int charIndex = convertBitIndexToCharacterIndex(z);
@@ -1167,7 +1166,7 @@ void MortevielleEngine::fctEnter() {
}
} else {
int randVal = (getRandomNumber(0, 10)) - 5;
- _speechManager.startSpeech(7, randVal, 1);
+ _soundManager.startSpeech(7, randVal, 1);
displayAnimFrame(1, 1);
_coreVar._currPlace = _roomDoorId;
diff --git a/engines/mortevielle/dialogs.cpp b/engines/mortevielle/dialogs.cpp
index ba5d984886..264839c158 100644
--- a/engines/mortevielle/dialogs.cpp
+++ b/engines/mortevielle/dialogs.cpp
@@ -30,7 +30,6 @@
#include "mortevielle/dialogs.h"
#include "mortevielle/mouse.h"
#include "mortevielle/outtext.h"
-#include "mortevielle/speech.h"
#include "common/str.h"
@@ -428,7 +427,7 @@ void DialogManager::drawF3F8() {
void DialogManager::checkForF8(int SpeechNum, bool drawFrame2Fl) {
_vm->testKeyboard();
do {
- _vm->_speechManager.startSpeech(SpeechNum, 0, 0);
+ _vm->_soundManager.startSpeech(SpeechNum, 0, 0);
_vm->_key = waitForF3F8();
if (_vm->shouldQuit())
return;
diff --git a/engines/mortevielle/module.mk b/engines/mortevielle/module.mk
index e18657cb6a..a9f02c2a67 100644
--- a/engines/mortevielle/module.mk
+++ b/engines/mortevielle/module.mk
@@ -12,7 +12,6 @@ MODULE_OBJS := \
outtext.o \
saveload.o \
sound.o \
- speech.o \
utils.o
# This module can be built as a plugin
diff --git a/engines/mortevielle/mortevielle.cpp b/engines/mortevielle/mortevielle.cpp
index 7126df933f..0b6b82c1a9 100644
--- a/engines/mortevielle/mortevielle.cpp
+++ b/engines/mortevielle/mortevielle.cpp
@@ -56,7 +56,6 @@ MortevielleEngine::MortevielleEngine(OSystem *system, const ADGameDescription *g
_mouse.setParent(this);
_text.setParent(this);
_soundManager.setParent(this);
- _speechManager.setParent(this);
_savegameManager.setParent(this);
_lastGameFrame = 0;
@@ -100,18 +99,15 @@ MortevielleEngine::MortevielleEngine(OSystem *system, const ADGameDescription *g
_caff = -1;
_day = 0;
- memset(_mem, 0, sizeof(_mem));
_curPict = nullptr;
_curAnim = nullptr;
_rightFramePict = nullptr;
- _compMusicBuf1 = nullptr;
}
MortevielleEngine::~MortevielleEngine() {
free(_curPict);
free(_curAnim);
free(_rightFramePict);
- free(_compMusicBuf1);
}
/**
@@ -229,6 +225,9 @@ Common::ErrorCode MortevielleEngine::initialize() {
_currGraphicalDevice = _newGraphicalDevice;
hirs();
+ _soundManager.loadNoise();
+ _soundManager.loadAmbiantSounds();
+
return Common::kNoError;
}
@@ -365,7 +364,7 @@ Common::Error MortevielleEngine::run() {
// Cleanup (allocated in initialize())
_screenSurface.free();
- free(_speechManager._cfiphBuffer);
+ free(_soundManager._cfiphBuffer);
free(_cfiecBuffer);
return Common::kNoError;
@@ -376,7 +375,6 @@ Common::Error MortevielleEngine::run() {
*/
void MortevielleEngine::showIntroduction() {
_dialogManager.displayIntroScreen(false);
- _speechManager._mlec = 0;
_dialogManager.checkForF8(142, false);
if (shouldQuit())
return;
@@ -402,7 +400,6 @@ void MortevielleEngine::mainGame() {
for (_crep = 1; _crep <= _x26KeyCount; ++_crep)
decodeNumber(&_cfiecBuffer[161 * 16], (_cfiecBufferSize - (161 * 16)) / 64);
- loadBRUIT5();
_menu.initMenu(this);
charToHour();
diff --git a/engines/mortevielle/mortevielle.h b/engines/mortevielle/mortevielle.h
index 8c7da8cc97..699ee3f37a 100644
--- a/engines/mortevielle/mortevielle.h
+++ b/engines/mortevielle/mortevielle.h
@@ -44,7 +44,6 @@
#include "mortevielle/mouse.h"
#include "mortevielle/saveload.h"
#include "mortevielle/sound.h"
-#include "mortevielle/speech.h"
#include "mortevielle/outtext.h"
namespace Mortevielle {
@@ -52,7 +51,8 @@ namespace Mortevielle {
// Debug channels
enum {
kMortevielleCore = 1 << 0,
- kMortevielleGraphics = 1 << 1
+ kMortevielleGraphics = 1 << 1,
+ kMortevielleSounds = 1 << 2
};
// Game languages
@@ -258,7 +258,6 @@ private:
void displayCGAPattern(int n, Pattern *p, nhom *pal);
void loadPalette();
void loadTexts();
- void loadBRUIT5();
void loadCFIEC();
void loadCFIPH();
void showTitleScreen();
@@ -434,12 +433,9 @@ public:
int _resolutionScaler;
byte _destinationArray[7][25];
- // TODO: Replace the following with proper implementations, or refactor out the code using them
- byte _mem[65536 * 16];
byte *_curPict;
byte *_curAnim;
byte *_rightFramePict;
- byte *_compMusicBuf1;
Debugger _debugger;
ScreenSurface _screenSurface;
@@ -448,7 +444,6 @@ public:
Common::RandomSource _randomSource;
SoundManager _soundManager;
SavegameManager _savegameManager;
- SpeechManager _speechManager;
Menu _menu;
MouseHandler _mouse;
TextHandler _text;
diff --git a/engines/mortevielle/sound.cpp b/engines/mortevielle/sound.cpp
index 24cec8911d..30dc4ce79f 100644
--- a/engines/mortevielle/sound.cpp
+++ b/engines/mortevielle/sound.cpp
@@ -33,116 +33,52 @@
namespace Mortevielle {
-/**
- * Constructor
- */
-PCSpeaker::PCSpeaker(int rate) {
- _rate = rate;
- _oscLength = 0;
- _oscSamples = 0;
- _remainingSamples = 0;
- _volume = 255;
-}
-
-/**
- * Destructor
- */
-PCSpeaker::~PCSpeaker() {
-}
-
-/**
- * Adds a new note to the queue of notes to be played.
- */
-void PCSpeaker::play(int freq, uint32 length) {
- assert((freq > 0) && (length > 0));
- Common::StackLock lock(_mutex);
-
- _pendingNotes.push(SpeakerNote(freq, length));
-}
-
-/**
- * Stops the currently playing song
- */
-void PCSpeaker::stop() {
- Common::StackLock lock(_mutex);
-
- _remainingSamples = 0;
- _pendingNotes.clear();
-}
-
-void PCSpeaker::setVolume(byte volume) {
- _volume = volume;
-}
-
-/**
- * Return true if a song is currently playing
- */
-bool PCSpeaker::isPlaying() const {
- return !_pendingNotes.empty() || (_remainingSamples != 0);
-}
-
-/**
- * Method used by the mixer to pull off pending samples to play
- */
-int PCSpeaker::readBuffer(int16 *buffer, const int numSamples) {
- Common::StackLock lock(_mutex);
-
- int i;
-
- for (i = 0; (_remainingSamples || !_pendingNotes.empty()) && (i < numSamples); ++i) {
- if (!_remainingSamples)
- // Used up the current note, so queue the next one
- dequeueNote();
-
- buffer[i] = generateSquare(_oscSamples, _oscLength) * _volume;
- if (_oscSamples++ >= _oscLength)
- _oscSamples = 0;
-
- _remainingSamples--;
- }
-
- // Clear the rest of the buffer
- if (i < numSamples)
- memset(buffer + i, 0, (numSamples - i) * sizeof(int16));
-
- return numSamples;
-}
-
-/**
- * Dequeues a note from the pending note list
- */
-void PCSpeaker::dequeueNote() {
- SpeakerNote note = _pendingNotes.pop();
-
- _oscLength = _rate / note.freq;
- _oscSamples = 0;
- _remainingSamples = (_rate * note.length) / 1000000;
- assert((_oscLength > 0) && (_remainingSamples > 0));
-}
-
-/**
- * Support method for generating a square wave
- */
-int8 PCSpeaker::generateSquare(uint32 x, uint32 oscLength) {
- return (x < (oscLength / 2)) ? 127 : -128;
-}
-
-/*-------------------------------------------------------------------------*/
-
-// The PC timer chip works at a frequency of 1.19318Mhz
-#define TIMER_FREQUENCY 1193180
+ const byte _tnocon[364] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+ };
+
+ const byte _intcon[26] = {1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0};
+ const byte _typcon[26] = {0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3};
+ const byte _tabdph[16] = {0, 10, 2, 0, 2, 10, 3, 0, 3, 7, 5, 0, 6, 7, 7, 10};
+ const byte _tabdbc[18] = {7, 23, 7, 14, 13, 9, 14, 9, 5, 12, 6, 12, 13, 4, 0, 4, 5, 9};
SoundManager::SoundManager(Audio::Mixer *mixer) {
_mixer = mixer;
- _speakerStream = new PCSpeaker(mixer->getOutputRate());
- _mixer->playStream(Audio::Mixer::kSFXSoundType, &_speakerHandle,
- _speakerStream, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true);
+ _audioStream = nullptr;
+ _ambiantNoiseBuf = nullptr;
+ _noiseBuf = nullptr;
+
+ _soundType = 0;
+ _phonemeNumb = 0;
+
+ for (int i = 0; i < 3; i++) {
+ _queue[i]._val = 0;
+ _queue[i]._code = 0;
+ _queue[i]._acc = 0;
+ _queue[i]._freq = 0;
+ _queue[i]._rep = 0;
+ }
+ _buildingSentence = false;
}
SoundManager::~SoundManager() {
- _mixer->stopHandle(_speakerHandle);
- delete _speakerStream;
-
+ if (_audioStream)
+ _audioStream->finish();
+ free(_ambiantNoiseBuf);
+ free(_noiseBuf);
}
/**
@@ -176,17 +112,165 @@ int SoundManager::decodeMusic(const byte *PSrc, byte *PDest, int size) {
return decompSize;
}
-void SoundManager::litph(tablint &t, int typ, int tempo) {
- return;
+/**
+ * Load sonmus.mor file
+ * @remarks Originally called 'charge_son'
+ */
+void SoundManager::loadAmbiantSounds() {
+ Common::File f;
+ if (!f.open("sonmus.mor"))
+ error("Missing file - sonmus.mor");
+
+ free(_ambiantNoiseBuf);
+ int size = f.size();
+ byte *compMusicBuf1 = (byte *)malloc(sizeof(byte) * size);
+ _ambiantNoiseBuf = (byte *)malloc(sizeof(byte) * size * 2);
+ f.read(compMusicBuf1, size);
+ f.close();
+
+ decodeMusic(compMusicBuf1, _ambiantNoiseBuf, size);
+ free(compMusicBuf1);
+}
+
+/**
+ * Speech function - Load Noise files
+ * @remarks Originally called 'charge_bruit' and 'charge_bruit5'
+ */
+void SoundManager::loadNoise() {
+ Common::File f1, f2;
+
+ if (!f1.open("bruits")) //Translation: "noise"
+ error("Missing file - bruits");
+ if (!f2.open("bruit5"))
+ error("Missing file - bruit5");
+
+ _noiseBuf = (byte *)malloc(sizeof(byte) * (f1.size() + f2.size()));
+ assert(f1.size() > 32000);
+
+ f1.read(_noiseBuf, 32000); // 250 * 128
+ f2.read(&_noiseBuf[32000], f2.size());
+ f1.read(&_noiseBuf[32000 + f2.size()], f1.size() - 32000); // 19072
+
+ f1.close();
+ f2.close();
}
-void SoundManager::playNote(int frequency, int32 length) {
- _speakerStream->play(frequency, length);
+void SoundManager::regenbruit() {
+ int i = 69876;
+ for (int j = 0; j < 100; j++) {
+ _cfiphBuffer[j] = READ_BE_UINT16(&_noiseBuf[i]);
+ i += 2;
+ }
}
+void SoundManager::litph(tablint &t, int typ, int tempo) {
+ // Skip speech
+ if (_soundType == 0)
+ return;
+
+ if (!_buildingSentence) {
+ if (_mixer->isSoundHandleActive(_soundHandle))
+ _mixer->stopHandle(_soundHandle);
+ _buildingSentence = true;
+ }
+ int freq = tempo * 252; // 25.2 * 10
+ int i = 0;
+ while (i < _ptr_oct) {
+ int idx = _troctBuf[i];
+ i++;
+ switch(idx) {
+ case 0: {
+ int val = _troctBuf[i];
+ i++;
+ if (_soundType == 0)
+ warning("TODO: vclas");
+ else if (_soundType == 1) {
+ debugC(5, kMortevielleSounds, "litph - duson");
+ const static int noiseAdr[] = {0, 17224,
+ 17224, 33676,
+ 33676, 51014,
+ 51014, 59396,
+ 59396, 61286,
+ 61286, 69875};
+ if (val > 5) {
+ warning("unhandled index %d", val);
+ } else {
+ if (!_audioStream)
+ _audioStream = Audio::makeQueuingAudioStream(freq, false);
+ _audioStream->queueBuffer(&_noiseBuf[noiseAdr[val * 2]], noiseAdr[(val * 2) + 1] - noiseAdr[(val * 2)], DisposeAfterUse::NO, Audio::FLAG_UNSIGNED);
+ }
+ } else { // 2
+ debugC(5, kMortevielleSounds, "litph - vadson");
+ const static int ambiantNoiseAdr[] = {0, 14020,
+ 14020, 18994,
+ 18994, 19630,
+ 19630, 22258,
+ 22258, 37322,
+ 37322, 44472,
+ 44472, 52324,
+ 52324, 59598,
+ 59598, 69748};
+ if (val > 8) {
+ warning("unhandled index %d", val);
+ } else {
+ if (!_audioStream)
+ _audioStream = Audio::makeQueuingAudioStream(freq, false);
+ _audioStream->queueBuffer(&_ambiantNoiseBuf[ambiantNoiseAdr[val * 2]], ambiantNoiseAdr[(val * 2) + 1] - ambiantNoiseAdr[(val * 2)], DisposeAfterUse::NO, Audio::FLAG_UNSIGNED);
+ }
+ }
+ i++;
+ break;
+ }
+ case 2: {
+ int val = _troctBuf[i];
+ i++;
+ int tmpidx = (val * 12) + 268;
+ val = _troctBuf[i];
+ i++;
+ warning("TODO: reech %d %d", tmpidx, val);
+ }
+ break;
+ case 4:
+ if (_soundType) {
+ i += 2;
+ } else {
+ // Speech
+ warning("TODO: Interphoneme: consonne:%d voyelle:%d", _troctBuf[i], _troctBuf[i + 1]);
+ i += 2;
+ }
+ break;
+ case 6:
+ warning("TODO: pari2");
+ i += 2;
+ break;
+ default:
+ static byte emptyBuf[19] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ if (idx == 62)
+ warning("TODO: blab");
+ else if (idx == 32) {
+ if (!_audioStream)
+ _audioStream = Audio::makeQueuingAudioStream(freq, false);
+ _audioStream->queueBuffer(emptyBuf, 19, DisposeAfterUse::NO, Audio::FLAG_UNSIGNED);
+ } else if (idx == 35) {
+ if (i < _ptr_oct)
+ warning("unexpected 35 - stop the buffering");
+ i = _ptr_oct;
+ } else if (idx == 46) {
+ if (!_audioStream)
+ _audioStream = Audio::makeQueuingAudioStream(freq, false);
+ for (int i = 0; i < 10; i++)
+ _audioStream->queueBuffer(emptyBuf, 19, DisposeAfterUse::NO, Audio::FLAG_UNSIGNED);
+ } else {
+ warning("Other code: %d - %d %d", idx, _troctBuf[i], _troctBuf[i + 1]);
+ }
+ break;
+ }
+ }
+}
void SoundManager::playSong(const byte* buf, uint size, uint loops) {
- Audio::SeekableAudioStream *raw = Audio::makeRawStream(buf, size, 11025, Audio::FLAG_UNSIGNED, DisposeAfterUse::NO);
+ int freq = kTempoMusic * 252; // 25.2 * 10
+ Audio::SeekableAudioStream *raw = Audio::makeRawStream(buf, size, freq, Audio::FLAG_UNSIGNED, DisposeAfterUse::NO);
Audio::AudioStream *stream = Audio::makeLoopingAudioStream(raw, loops);
Audio::SoundHandle songHandle;
_mixer->playStream(Audio::Mixer::kSFXSoundType, &songHandle, stream, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::YES);
@@ -200,4 +284,504 @@ void SoundManager::playSong(const byte* buf, uint size, uint loops) {
void SoundManager::setParent(MortevielleEngine *vm) {
_vm = vm;
}
+
+void SoundManager::spfrac(int wor) {
+ _queue[2]._rep = (uint)wor >> 12;
+ if ((_soundType == 0) && (_queue[2]._code != 9)) {
+ if (((_queue[2]._code > 4) && (_queue[2]._val != 20) && (_queue[2]._rep != 3) && (_queue[2]._rep != 6) && (_queue[2]._rep != 9)) ||
+ ((_queue[2]._code < 5) && ((_queue[2]._val != 19) && (_queue[2]._val != 22) && (_queue[2]._rep != 4) && (_queue[2]._rep != 9)))) {
+ ++_queue[2]._rep;
+ }
+ }
+
+ _queue[2]._freq = ((uint)wor >> 6) & 7;
+ _queue[2]._acc = ((uint)wor >> 9) & 7;
+}
+
+void SoundManager::charg_car(int &currWordNumb) {
+ assert(currWordNumb < 1712);
+ int wor = READ_BE_UINT16(&_wordBuf[currWordNumb]);
+ int int_ = wor & 0x3f; // 63
+
+ if ((int_ >= 0) && (int_ <= 13)) {
+ _queue[2]._val = int_;
+ _queue[2]._code = 5;
+ } else if ((int_ >= 14) && (int_ <= 21)) {
+ _queue[2]._val = int_;
+ _queue[2]._code = 6;
+ } else if ((int_ >= 22) && (int_ <= 47)) {
+ int_ -= 22;
+ _queue[2]._val = int_;
+ _queue[2]._code = _typcon[int_];
+ } else if ((int_ >= 48) && (int_ <= 56)) {
+ _queue[2]._val = int_ - 22;
+ _queue[2]._code = 4;
+ } else {
+ switch (int_) {
+ case 60:
+ _queue[2]._val = 32; /* " " */
+ _queue[2]._code = 9;
+ break;
+ case 61:
+ _queue[2]._val = 46; /* "." */
+ _queue[2]._code = 9;
+ break;
+ case 62:
+ _queue[2]._val = 35; /* "#" */
+ _queue[2]._code = 9;
+ default:
+ break;
+ }
+ }
+
+ spfrac(wor);
+ currWordNumb += 2;
+}
+
+
+void SoundManager::entroct(byte o) {
+ assert(_ptr_oct < 10576);
+ _troctBuf[_ptr_oct] = o;
+ ++_ptr_oct;
+}
+
+void SoundManager::cctable(tablint &t) {
+ float tb[257];
+
+ tb[0] = 0;
+ for (int k = 0; k <= 255; ++k) {
+ tb[k + 1] = _vm->_addFix + tb[k];
+ t[255 - k] = abs((int)tb[k] + 1);
+ }
+}
+
+/**
+ * Load phoneme sound file
+ * @remarks Originally called 'charge_phbruit'
+ */
+void SoundManager::loadPhonemeSounds() {
+ Common::File f;
+
+ if (!f.open("phbrui.mor"))
+ error("Missing file - phbrui.mor");
+
+ for (int i = 1; i <= f.size() / 2; ++i)
+ _cfiphBuffer[i] = f.readUint16BE();
+
+ f.close();
+}
+
+void SoundManager::trait_car() {
+ byte d3;
+ int d2, i;
+
+ switch (_queue[1]._code) {
+ case 9:
+ if (_queue[1]._val != (int)'#') {
+ for (i = 0; i <= _queue[1]._rep; ++i)
+ entroct(_queue[1]._val);
+ }
+ break;
+ case 5:
+ case 6:
+ if (_queue[1]._code == 6)
+ d3 = _tabdph[(_queue[1]._val - 14) << 1];
+ else
+ d3 = kNullValue;
+ if (_queue[0]._code >= 5) {
+ if (_queue[0]._code == 9) {
+ entroct(4);
+ if (d3 == kNullValue)
+ entroct(_queue[1]._val);
+ else
+ entroct(d3);
+ entroct(22);
+ }
+ }
+
+ switch (_queue[1]._rep) {
+ case 0:
+ entroct(0);
+ entroct(_queue[1]._val);
+ if (d3 == kNullValue)
+ if (_queue[2]._code == 9)
+ entroct(2);
+ else
+ entroct(4);
+ else if (_queue[2]._code == 9)
+ entroct(0);
+ else
+ entroct(1);
+ break;
+ case 4:
+ case 5:
+ case 6:
+ if (_queue[1]._rep != 4) {
+ i = _queue[1]._rep - 5;
+ do {
+ --i;
+ entroct(0);
+ if (d3 == kNullValue)
+ entroct(_queue[1]._val);
+ else
+ entroct(d3);
+ entroct(3);
+ } while (i >= 0);
+ }
+ if (d3 == kNullValue) {
+ entroct(4);
+ entroct(_queue[1]._val);
+ entroct(0);
+ } else {
+ entroct(0);
+ entroct(_queue[1]._val);
+ entroct(3);
+ }
+
+ break;
+ case 7:
+ case 8:
+ case 9:
+ if (_queue[1]._rep != 7) {
+ i = _queue[1]._rep - 8;
+ do {
+ --i;
+ entroct(0);
+ if (d3 == kNullValue)
+ entroct(_queue[1]._val);
+ else
+ entroct(d3);
+ entroct(3);
+ } while (i >= 0);
+ }
+ if (d3 == kNullValue) {
+ entroct(0);
+ entroct(_queue[1]._val);
+ entroct(2);
+ } else {
+ entroct(0);
+ entroct(_queue[1]._val);
+ entroct(0);
+ }
+ break;
+ case 1:
+ case 2:
+ case 3:
+ if (_queue[1]._rep != 1) {
+ i = _queue[1]._rep - 2;
+ do {
+ --i;
+ entroct(0);
+ if (d3 == kNullValue)
+ entroct(_queue[1]._val);
+ else
+ entroct(d3);
+ entroct(3);
+ } while (i >= 0);
+ }
+ entroct(0);
+ entroct(_queue[1]._val);
+ if (_queue[2]._code == 9)
+ entroct(0);
+ else
+ entroct(1);
+
+ break;
+ default:
+ break;
+ } // switch c2.rep
+ break;
+
+ case 2:
+ case 3:
+ d3 = _queue[1]._code + 5; // 7 ou 8 => Corresponding vowel
+ if (_queue[0]._code > 4) {
+ if (_queue[0]._code == 9) {
+ entroct(4);
+ entroct(d3);
+ entroct(22);
+ }
+ }
+ i = _queue[1]._rep;
+ assert(i >= 0);
+ if (i != 0) {
+ do {
+ --i;
+ entroct(0);
+ entroct(d3);
+ entroct(3);
+ } while (i > 0);
+ }
+ if (_queue[2]._code == 6) {
+ entroct(4);
+ entroct(_tabdph[(_queue[2]._val - 14) << 1]);
+ entroct(_queue[1]._val);
+ } else {
+ entroct(4);
+ if (_queue[2]._val == 4)
+ entroct(3);
+ else
+ entroct(_queue[2]._val);
+ entroct(_queue[1]._val);
+ }
+ break;
+ case 0:
+ case 1:
+ switch (_queue[2]._code) {
+ case 2:
+ d2 = 7;
+ break;
+ case 3:
+ d2 = 8;
+ break;
+ case 6:
+ d2 = _tabdph[(_queue[2]._val - 14) << 1];
+ break;
+ case 5:
+ d2 = _queue[2]._val;
+ break;
+ default:
+ d2 = 10;
+ break;
+ } // switch c3._code
+ d2 = (d2 * 26) + _queue[1]._val;
+ if (_tnocon[d2] == 0)
+ d3 = 2;
+ else
+ d3 = 6;
+ if (_queue[1]._rep >= 5) {
+ _queue[1]._rep -= 5;
+ d3 = 8 - d3; // Swap 2 and 6
+ }
+ if (_queue[1]._code == 0) {
+ i = _queue[1]._rep;
+ if (i != 0) {
+ do {
+ --i;
+ entroct(d3);
+ entroct(_queue[1]._val);
+ entroct(3);
+ } while (i > 0);
+ }
+ entroct(d3);
+ entroct(_queue[1]._val);
+ entroct(4);
+ } else {
+ entroct(d3);
+ entroct(_queue[1]._val);
+ entroct(3);
+ i = _queue[1]._rep;
+ if (i != 0) {
+ do {
+ --i;
+ entroct(d3);
+ entroct(_queue[1]._val);
+ entroct(4);
+ } while (i > 0);
+ }
+ }
+ if (_queue[2]._code == 9) {
+ entroct(d3);
+ entroct(_queue[1]._val);
+ entroct(5);
+ } else if ((_queue[2]._code != 0) && (_queue[2]._code != 1) && (_queue[2]._code != 4)) {
+ switch (_queue[2]._code) {
+ case 3:
+ d2 = 8;
+ break;
+ case 6:
+ d2 = _tabdph[(_queue[2]._val - 14) << 1];
+ break;
+ case 5:
+ d2 = _queue[2]._val;
+ break;
+ default:
+ d2 = 7;
+ break;
+ } // switch c3._code
+ if (d2 == 4)
+ d2 = 3;
+
+ if (_intcon[_queue[1]._val] != 0)
+ ++_queue[1]._val;
+
+ if ((_queue[1]._val == 17) || (_queue[1]._val == 18))
+ _queue[1]._val = 16;
+
+ entroct(4);
+ entroct(d2);
+ entroct(_queue[1]._val);
+ }
+
+ break;
+ case 4:
+ i = _queue[1]._rep;
+ if (i != 0) {
+ do {
+ --i;
+ entroct(2);
+ entroct(_queue[1]._val);
+ entroct(3);
+ } while (i > 0);
+ }
+ entroct(2);
+ entroct(_queue[1]._val);
+ entroct(4);
+ if (_queue[2]._code == 9) {
+ entroct(2);
+ entroct(_queue[1]._val);
+ entroct(5);
+ } else if ((_queue[2]._code != 0) && (_queue[2]._code != 1) && (_queue[2]._code != 4)) {
+ switch (_queue[2]._code) {
+ case 3:
+ d2 = 8;
+ break;
+ case 6:
+ d2 = _tabdph[(_queue[2]._val - 14) << 1];
+ break;
+ case 5:
+ d2 = _queue[2]._val;
+ break;
+ default:
+ d2 = 7;
+ break;
+ } // switch c3._code
+
+ if (d2 == 4)
+ d2 = 3;
+
+ if (_intcon[_queue[1]._val] != 0)
+ ++_queue[1]._val;
+
+ entroct(4);
+ entroct(d2);
+ entroct(_tabdbc[((_queue[1]._val - 26) << 1) + 1]);
+ }
+
+ break;
+ default:
+ break;
+ } // switch c2.code
+}
+
+/**
+ * Make the queue evolve by 1 value
+ * @remarks Originally called 'rot_chariot'
+ */
+void SoundManager::moveQueue() {
+ _queue[0] = _queue[1];
+ _queue[1] = _queue[2];
+ _queue[2]._val = 32;
+ _queue[2]._code = 9;
+}
+
+/**
+ * initialize the queue
+ * @remarks Originally called 'init_chariot'
+ */
+void SoundManager::initQueue() {
+ _queue[2]._rep = 0;
+ _queue[2]._freq = 0;
+ _queue[2]._acc = 0;
+ moveQueue();
+ moveQueue();
+}
+
+/**
+ * Handle a phoneme
+ * @remarks Originally called 'trait_ph'
+ */
+void SoundManager::handlePhoneme() {
+ const uint16 deca[3] = {300, 30, 40};
+
+ uint16 startPos = _cfiphBuffer[_phonemeNumb - 1] + deca[_soundType];
+ uint16 endPos = _cfiphBuffer[_phonemeNumb] + deca[_soundType];
+ int wordCount = endPos - startPos;
+
+ startPos /= 2;
+ endPos /= 2;
+ assert((endPos - startPos) < 1711);
+ for (int i = startPos, currWord = 0; i < endPos; i++, currWord += 2)
+ WRITE_BE_UINT16(&_wordBuf[currWord], _cfiphBuffer[i]);
+
+ _ptr_oct = 0;
+ int currWord = 0;
+ initQueue();
+
+ do {
+ moveQueue();
+ charg_car(currWord);
+ trait_car();
+ } while (currWord < wordCount);
+
+ moveQueue();
+ trait_car();
+ entroct((int)'#');
+
+#ifdef DEBUG
+ warning("---");
+ for (int i = 0; i < _ptr_oct; ) {
+ if ((_troctBuf[i] == 32) || (_troctBuf[i] == 35) || (_troctBuf[i] == 46)) {
+ warning("%d", _troctBuf[i]);
+ i++;
+ } else {
+ warning("%d %d %d", _troctBuf[i], _troctBuf[i + 1], _troctBuf[i + 1]);
+ i += 3;
+ }
+ }
+ warning("---");
+#endif
+}
+
+/**
+ * Start speech
+ * @remarks Originally called 'parole'
+ */
+void SoundManager::startSpeech(int rep, int ht, int typ) {
+ uint16 savph[501];
+ int tempo;
+
+ if (_vm->_soundOff)
+ return;
+
+ _phonemeNumb = rep;
+ int haut = ht;
+ _soundType = typ;
+ if (_soundType != 0) {
+ for (int i = 0; i <= 500; ++i)
+ savph[i] = _cfiphBuffer[i];
+ tempo = kTempoNoise;
+ } else if (haut > 5)
+ tempo = kTempoF;
+ else
+ tempo = kTempoM;
+ _vm->_addFix = (float)((tempo - 8)) / 256;
+ cctable(_tbi);
+ switch (typ) {
+ case 1:
+ regenbruit();
+ break;
+ case 2:
+ loadPhonemeSounds();
+ break;
+ default:
+ break;
+ }
+ handlePhoneme();
+ litph(_tbi, typ, tempo);
+
+ _buildingSentence = false;
+ if (typ != 0) {
+ _audioStream->finish();
+ _mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundHandle, _audioStream);
+ _audioStream = nullptr;
+ }
+
+ if (_soundType != 0) {
+ for (int i = 0; i <= 500; ++i)
+ _cfiphBuffer[i] = savph[i];
+ }
+ _vm->setPal(_vm->_numpal);
+}
+
} // End of namespace Mortevielle
diff --git a/engines/mortevielle/sound.h b/engines/mortevielle/sound.h
index 1f9e0d9c4d..1e4a4cd54c 100644
--- a/engines/mortevielle/sound.h
+++ b/engines/mortevielle/sound.h
@@ -36,79 +36,68 @@
namespace Mortevielle {
class MortevielleEngine;
-typedef int tablint[256];
-
-/**
- * Structure used to store pending notes to play
- */
-struct SpeakerNote {
- int freq;
- uint32 length;
-
- SpeakerNote(int noteFreq, uint32 noteLength) {
- freq = noteFreq;
- length = noteLength;
- }
+const int kNullValue = 255;
+const int kTempoMusic = 71;
+const int kTempoNoise = 78;
+const int kTempoF = 80;
+const int kTempoM = 89;
+
+struct SpeechQueue {
+ int _val;
+ int _code;
+ int _acc;
+ int _freq;
+ int _rep;
};
-/**
- * This is a modified PC Speaker class that allows the queueing of an entire song
- * sequence one note at a time.
- */
-class PCSpeaker : public Audio::AudioStream {
-private:
- Common::Queue<SpeakerNote> _pendingNotes;
- Common::Mutex _mutex;
-
- int _rate;
- uint32 _oscLength;
- uint32 _oscSamples;
- uint32 _remainingSamples;
- uint32 _mixedSamples;
- byte _volume;
-
- void dequeueNote();
-protected:
- static int8 generateSquare(uint32 x, uint32 oscLength);
-public:
- PCSpeaker(int rate = 44100);
- ~PCSpeaker();
-
- /** Play a note for length microseconds.
- */
- void play(int freq, uint32 length);
- /** Stop the currently playing sequence */
- void stop();
- /** Adjust the volume. */
- void setVolume(byte volume);
-
- bool isPlaying() const;
-
- int readBuffer(int16 *buffer, const int numSamples);
-
- bool isStereo() const { return false; }
- bool endOfData() const { return false; }
- bool endOfStream() const { return false; }
- int getRate() const { return _rate; }
-};
+typedef int tablint[256];
class SoundManager {
private:
MortevielleEngine *_vm;
- Audio::Mixer *_mixer;
- PCSpeaker *_speakerStream;
- Audio::SoundHandle _speakerHandle;
+
+ byte *_ambiantNoiseBuf;
+ byte *_noiseBuf;
+ int _phonemeNumb;
+ int _soundType;
+ SpeechQueue _queue[3];
+ byte _wordBuf[1712];
+ byte _troctBuf[10576];
+ bool _buildingSentence;
+ int _ptr_oct;
+ int _tbi[256];
+
+ Audio::QueuingAudioStream *_audioStream;
+
+ void loadPhonemeSounds();
+ void moveQueue();
+ void initQueue();
+ void handlePhoneme();
+
+ void spfrac(int wor);
+ void charg_car(int &currWordNumb);
+ void entroct(byte o);
+ void cctable(tablint &t);
+ void trait_car();
+
+ void regenbruit();
+ void litph(tablint &t, int typ, int tempo);
+
public:
SoundManager(Audio::Mixer *mixer);
~SoundManager();
+ Audio::Mixer *_mixer;
+ Audio::SoundHandle _soundHandle;
+ uint16 *_cfiphBuffer;
+
void setParent(MortevielleEngine *vm);
- void playNote(int frequency, int32 length);
int decodeMusic(const byte *PSrc, byte *PDest, int size);
void playSong(const byte *buf, uint usize, uint loops);
-
- void litph(tablint &t, int typ, int tempo);
+ void loadAmbiantSounds();
+ void loadNoise();
+ void startSpeech(int rep, int ht, int typ);
};
} // End of namespace Mortevielle
diff --git a/engines/mortevielle/speech.cpp b/engines/mortevielle/speech.cpp
deleted file mode 100644
index 35eefc898f..0000000000
--- a/engines/mortevielle/speech.cpp
+++ /dev/null
@@ -1,611 +0,0 @@
-/* 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 2
- * 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, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-/*
- * This code is based on original Mortville Manor DOS source code
- * Copyright (c) 1987-1989 Lankhor
- */
-
-#include "mortevielle/mortevielle.h"
-
-#include "mortevielle/speech.h"
-#include "mortevielle/sound.h"
-
-#include "common/endian.h"
-#include "common/file.h"
-
-namespace Mortevielle {
-
-const byte _tnocon[364] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-};
-
-const byte _intcon[26] = {1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0};
-const byte _typcon[26] = {0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3};
-const byte _tabdph[16] = {0, 10, 2, 0, 2, 10, 3, 0, 3, 7, 5, 0, 6, 7, 7, 10};
-const byte _tabdbc[18] = {7, 23, 7, 14, 13, 9, 14, 9, 5, 12, 6, 12, 13, 4, 0, 4, 5, 9};
-
-SpeechManager::SpeechManager() {
- _typlec = 0;
- _phonemeNumb = 0;
-
- for (int i = 0; i < 3; i++) {
- _queue[i]._val = 0;
- _queue[i]._code = 0;
- _queue[i]._acc = 0;
- _queue[i]._freq = 0;
- _queue[i]._rep = 0;
- }
- _noise5Buf = nullptr;
-}
-
-SpeechManager::~SpeechManager() {
- free(_noise5Buf);
-}
-
-void SpeechManager::spfrac(int wor) {
- _queue[2]._rep = (uint)wor >> 12;
- if ((_typlec == 0) && (_queue[2]._code != 9))
- if (((_queue[2]._code > 4) && (_queue[2]._val != 20) && (_queue[2]._rep != 3) && (_queue[2]._rep != 6) && (_queue[2]._rep != 9)) ||
- ((_queue[2]._code < 5) && ((_queue[2]._val != 19) && (_queue[2]._val != 22) && (_queue[2]._rep != 4) && (_queue[2]._rep != 9)))) {
- ++_queue[2]._rep;
- }
-
- _queue[2]._freq = ((uint)wor >> 6) & 7;
- _queue[2]._acc = ((uint)wor >> 9) & 7;
-}
-
-void SpeechManager::charg_car(int &currWordNumb) {
- int wor = READ_BE_UINT16(&_vm->_mem[(kAdrWord * 16) + currWordNumb]);
- int int_ = wor & 0x3f; // 63
-
- if ((int_ >= 0) && (int_ <= 13)) {
- _queue[2]._val = int_;
- _queue[2]._code = 5;
- } else if ((int_ >= 14) && (int_ <= 21)) {
- _queue[2]._val = int_;
- _queue[2]._code = 6;
- } else if ((int_ >= 22) && (int_ <= 47)) {
- int_ = int_ - 22;
- _queue[2]._val = int_;
- _queue[2]._code = _typcon[int_];
- } else if ((int_ >= 48) && (int_ <= 56)) {
- _queue[2]._val = int_ - 22;
- _queue[2]._code = 4;
- } else {
- switch (int_) {
- case 60:
- _queue[2]._val = 32; /* " " */
- _queue[2]._code = 9;
- break;
- case 61:
- _queue[2]._val = 46; /* "." */
- _queue[2]._code = 9;
- break;
- case 62:
- _queue[2]._val = 35; /* "#" */
- _queue[2]._code = 9;
- default:
- break;
- }
- }
-
- spfrac(wor);
- currWordNumb += 2;
-}
-
-
-void SpeechManager::entroct(byte o) {
- _vm->_mem[(kAdrTroct * 16) + _ptr_oct] = o;
- ++_ptr_oct;
-}
-
-void SpeechManager::veracf(byte b) {
- ;
-}
-
-void SpeechManager::cctable(tablint &t) {
- float tb[257];
-
- tb[0] = 0;
- for (int k = 0; k <= 255; ++k) {
- tb[k + 1] = _vm->_addFix + tb[k];
- t[255 - k] = abs((int)tb[k] + 1);
- }
-}
-
-void SpeechManager::regenbruit() {
- int i = kOffsetB3 + 8590;
- int j = 0;
- do {
- _cfiphBuffer[j] = READ_BE_UINT16(&_vm->_mem[(kAdrNoise3 * 16) + i]);
- i += 2;
- ++j;
- } while (i < kOffsetB3 + 8790);
-}
-
-/**
- * Load sonmus.mor file
- * @remarks Originally called 'charge_son'
- */
-void SpeechManager::loadMusicSound() {
- Common::File f;
- if (!f.open("sonmus.mor"))
- error("Missing file - sonmus.mor");
-
- free(_vm->_compMusicBuf1);
- int size = f.size();
- _vm->_compMusicBuf1 = (byte *)malloc(sizeof(byte) * size);
- f.read(_vm->_compMusicBuf1, size);
-
- _vm->_soundManager.decodeMusic(_vm->_compMusicBuf1, &_vm->_mem[kAdrNoise * 16], size);
- f.close();
-}
-
-/**
- * Load phoneme sound file
- * @remarks Originally called 'charge_phbruit'
- */
-void SpeechManager::loadPhonemeSounds() {
- Common::File f;
-
- if (!f.open("phbrui.mor"))
- error("Missing file - phbrui.mor");
-
- for (int i = 1; i <= f.size() / 2; ++i)
- _cfiphBuffer[i] = f.readUint16BE();
-
- f.close();
-}
-
-/**
- * Speech function - Load Noise file
- * @remarks Originally called 'charge_bruit'
- */
-void SpeechManager::loadNoise() {
- Common::File f;
-
- if (!f.open("bruits")) //Translation: "noise"
- error("Missing file - bruits");
-
- f.read(&_vm->_mem[kAdrNoise * 16], 250 * 128); // 32000
- for (int i = 0; i < _noise5Size; ++i)
- _vm->_mem[(kAdrNoise * 16) + 32000 + i] = _noise5Buf[i];
- f.read(&_vm->_mem[(kAdrNoise1 * 16) + kOffsetB1], 149 * 128); // 19072
-
- f.close();
-}
-
-void SpeechManager::trait_car() {
- byte d3;
- int d2, i;
-
- switch (_queue[1]._code) {
- case 9:
- if (_queue[1]._val != (int)'#')
- for (i = 0; i <= _queue[1]._rep; ++i)
- entroct(_queue[1]._val);
- break;
- case 5:
- case 6:
- if (_queue[1]._code == 6)
- d3 = _tabdph[(_queue[1]._val - 14) << 1];
- else
- d3 = kNullValue;
- if (_queue[0]._code >= 5) {
- veracf(_queue[1]._acc);
- if (_queue[0]._code == 9) {
- entroct(4);
- if (d3 == kNullValue)
- entroct(_queue[1]._val);
- else
- entroct(d3);
- entroct(22);
- }
- }
-
- switch (_queue[1]._rep) {
- case 0:
- entroct(0);
- entroct(_queue[1]._val);
- if (d3 == kNullValue)
- if (_queue[2]._code == 9)
- entroct(2);
- else
- entroct(4);
- else if (_queue[2]._code == 9)
- entroct(0);
- else
- entroct(1);
- break;
- case 4:
- case 5:
- case 6:
- if (_queue[1]._rep != 4) {
- i = _queue[1]._rep - 5;
- do {
- --i;
- entroct(0);
- if (d3 == kNullValue)
- entroct(_queue[1]._val);
- else
- entroct(d3);
- entroct(3);
- } while (i >= 0);
- }
- if (d3 == kNullValue) {
- entroct(4);
- entroct(_queue[1]._val);
- entroct(0);
- } else {
- entroct(0);
- entroct(_queue[1]._val);
- entroct(3);
- }
- break;
- case 7:
- case 8:
- case 9:
- if (_queue[1]._rep != 7) {
- i = _queue[1]._rep - 8;
- do {
- --i;
- entroct(0);
- if (d3 == kNullValue)
- entroct(_queue[1]._val);
- else
- entroct(d3);
- entroct(3);
- } while (i >= 0);
- }
- if (d3 == kNullValue) {
- entroct(0);
- entroct(_queue[1]._val);
- entroct(2);
- } else {
- entroct(0);
- entroct(_queue[1]._val);
- entroct(0);
- }
- break;
- case 1:
- case 2:
- case 3:
- if (_queue[1]._rep != 1) {
- i = _queue[1]._rep - 2;
- do {
- --i;
- entroct(0);
- if (d3 == kNullValue)
- entroct(_queue[1]._val);
- else
- entroct(d3);
- entroct(3);
- } while (i >= 0);
- }
- entroct(0);
- entroct(_queue[1]._val);
- if (_queue[2]._code == 9)
- entroct(0);
- else
- entroct(1);
- break;
- default:
- break;
- } // switch c2.rep
- break;
-
- case 2:
- case 3:
- d3 = _queue[1]._code + 5; // 7 ou 8 => Corresponding vowel
- if (_queue[0]._code > 4) {
- veracf(_queue[1]._acc);
- if (_queue[0]._code == 9) {
- entroct(4);
- entroct(d3);
- entroct(22);
- }
- }
- i = _queue[1]._rep;
- assert(i >= 0);
- if (i != 0) {
- do {
- --i;
- entroct(0);
- entroct(d3);
- entroct(3);
- } while (i > 0);
- }
- veracf(_queue[2]._acc);
- if (_queue[2]._code == 6) {
- entroct(4);
- entroct(_tabdph[(_queue[2]._val - 14) << 1]);
- entroct(_queue[1]._val);
- } else {
- entroct(4);
- if (_queue[2]._val == 4)
- entroct(3);
- else
- entroct(_queue[2]._val);
- entroct(_queue[1]._val);
- }
- break;
- case 0:
- case 1:
- veracf(_queue[1]._acc);
- switch (_queue[2]._code) {
- case 2:
- d2 = 7;
- break;
- case 3:
- d2 = 8;
- break;
- case 6:
- d2 = _tabdph[(_queue[2]._val - 14) << 1];
- break;
- case 5:
- d2 = _queue[2]._val;
- break;
- default:
- d2 = 10;
- break;
- } // switch c3._code
- d2 = (d2 * 26) + _queue[1]._val;
- if (_tnocon[d2] == 0)
- d3 = 2;
- else
- d3 = 6;
- if (_queue[1]._rep >= 5) {
- _queue[1]._rep -= 5;
- d3 = 8 - d3; // Swap 2 and 6
- }
- if (_queue[1]._code == 0) {
- i = _queue[1]._rep;
- if (i != 0) {
- do {
- --i;
- entroct(d3);
- entroct(_queue[1]._val);
- entroct(3);
- } while (i > 0);
- }
- entroct(d3);
- entroct(_queue[1]._val);
- entroct(4);
- } else {
- entroct(d3);
- entroct(_queue[1]._val);
- entroct(3);
- i = _queue[1]._rep;
- if (i != 0) {
- do {
- --i;
- entroct(d3);
- entroct(_queue[1]._val);
- entroct(4);
- } while (i > 0);
- }
- }
- if (_queue[2]._code == 9) {
- entroct(d3);
- entroct(_queue[1]._val);
- entroct(5);
- } else if ((_queue[2]._code != 0) && (_queue[2]._code != 1) && (_queue[2]._code != 4)) {
- veracf(_queue[2]._acc);
- switch (_queue[2]._code) {
- case 3:
- d2 = 8;
- break;
- case 6:
- d2 = _tabdph[(_queue[2]._val - 14) << 1];
- break;
- case 5:
- d2 = _queue[2]._val;
- break;
- default:
- d2 = 7;
- break;
- } // switch c3._code
- if (d2 == 4)
- d2 = 3;
-
- if (_intcon[_queue[1]._val] != 0)
- ++_queue[1]._val;
-
- if ((_queue[1]._val == 17) || (_queue[1]._val == 18))
- _queue[1]._val = 16;
-
- entroct(4);
- entroct(d2);
- entroct(_queue[1]._val);
- }
-
- break;
- case 4:
- veracf(_queue[1]._acc);
- i = _queue[1]._rep;
- if (i != 0) {
- do {
- --i;
- entroct(2);
- entroct(_queue[1]._val);
- entroct(3);
- } while (i > 0);
- }
- entroct(2);
- entroct(_queue[1]._val);
- entroct(4);
- if (_queue[2]._code == 9) {
- entroct(2);
- entroct(_queue[1]._val);
- entroct(5);
- } else if ((_queue[2]._code != 0) && (_queue[2]._code != 1) && (_queue[2]._code != 4)) {
- veracf(_queue[2]._acc);
- switch (_queue[2]._code) {
- case 3:
- d2 = 8;
- break;
- case 6:
- d2 = _tabdph[(_queue[2]._val - 14) << 1];
- break;
- case 5:
- d2 = _queue[2]._val;
- break;
- default:
- d2 = 7;
- break;
- } // switch c3._code
-
- if (d2 == 4)
- d2 = 3;
-
- if (_intcon[_queue[1]._val] != 0)
- ++_queue[1]._val;
-
- entroct(4);
- entroct(d2);
- entroct(_tabdbc[((_queue[1]._val - 26) << 1) + 1]);
- }
-
- break;
- default:
- break;
- } // switch c2.code
-}
-
-/**
- * Make the queue evolve by 1 value
- * @remarks Originally called 'rot_chariot'
- */
-void SpeechManager::moveQueue() {
- _queue[0] = _queue[1];
- _queue[1] = _queue[2];
- _queue[2]._val = 32;
- _queue[2]._code = 9;
-}
-
-/**
- * initialize the queue
- * @remarks Originally called 'init_chariot'
- */
-void SpeechManager::initQueue() {
- _queue[2]._rep = 0;
- _queue[2]._freq = 0;
- _queue[2]._acc = 0;
- moveQueue();
- moveQueue();
-}
-
-/**
- * Handle a phoneme
- * @remarks Originally called 'trait_ph'
- */
-void SpeechManager::handlePhoneme() {
- const uint16 deca[3] = {300, 30, 40};
-
- uint16 startPos = _cfiphBuffer[_phonemeNumb - 1] + deca[_typlec];
- uint16 endPos = _cfiphBuffer[_phonemeNumb] + deca[_typlec];
- int wordCount = endPos - startPos;
-
- startPos /= 2;
- endPos /= 2;
- for (int i = startPos, currWord = 0; i < endPos; i++, currWord += 2)
- WRITE_BE_UINT16(&_vm->_mem[(kAdrWord * 16) + currWord], _cfiphBuffer[i]);
-
- _ptr_oct = 0;
- int currWord = 0;
- initQueue();
-
- do {
- moveQueue();
- charg_car(currWord);
- trait_car();
- } while (currWord < wordCount);
-
- moveQueue();
- trait_car();
- entroct((int)'#');
-}
-
-/**
- * Start speech
- * @remarks Originally called 'parole'
- */
-void SpeechManager::startSpeech(int rep, int ht, int typ) {
- uint16 savph[501];
- int tempo;
-
- if (_vm->_soundOff)
- return;
-
- _phonemeNumb = rep;
- int haut = ht;
- _typlec = typ;
- if (_typlec != 0) {
- for (int i = 0; i <= 500; ++i)
- savph[i] = _cfiphBuffer[i];
- tempo = kTempoNoise;
- } else if (haut > 5)
- tempo = kTempoF;
- else
- tempo = kTempoM;
- _vm->_addFix = (float)((tempo - 8)) / 256;
- cctable(_tbi);
- switch (typ) {
- case 1:
- loadNoise();
- regenbruit();
- break;
- case 2:
- loadMusicSound();
- loadPhonemeSounds();
- break;
- default:
- break;
- }
- handlePhoneme();
- _vm->_soundManager.litph(_tbi, typ, tempo);
- if (_typlec != 0)
- for (int i = 0; i <= 500; ++i) {
- _cfiphBuffer[i] = savph[i];
- _mlec = _typlec;
- }
- _vm->setPal(_vm->_numpal);
-}
-
-void SpeechManager::setParent(MortevielleEngine *vm) {
- _vm = vm;
-}
-} // End of namespace Mortevielle
diff --git a/engines/mortevielle/speech.h b/engines/mortevielle/speech.h
deleted file mode 100644
index c3c4c32942..0000000000
--- a/engines/mortevielle/speech.h
+++ /dev/null
@@ -1,106 +0,0 @@
-/* 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 2
- * 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, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-/*
- * This code is based on original Mortville Manor DOS source code
- * Copyright (c) 1987-1989 Lankhor
- */
-
-#ifndef MORTEVIELLE_SPEECH_H
-#define MORTEVIELLE_SPEECH_H
-
-#include "mortevielle/sound.h"
-
-#include "common/scummsys.h"
-
-namespace Mortevielle {
-
-const int kAdrNoise = 0x5cb0;/*2C00;*/
-const int kAdrNoise1 = 0x6924;
-const int kAdrNoise3 = 0x6ba6;/*3AF6;*/
-const int kAdrTroct = 0x406b;
-const int kAdrWord = 0x4000;
-const int kOffsetB1 = 6;
-const int kOffsetB3 = 6;
-
-const float kfreq0 = 1.19318e6;
-const int kNullValue = 255;
-const int kTempoMusic = 71;
-const int kTempoNoise = 78;
-const int kTempoF = 80;
-const int kTempoM = 89;
-
-// Useless constants
-//const int segdon = 0x6c00;
-//const int adbruit2 = 0x6b30;/*3A80;*/
-//const int adson2 = 0x60b0;/*3000;*/
-//const int seg_syst = 0x6fed;
-//const int offsetb2 = 4;
-
-struct SpeechQueue {
- int _val;
- int _code;
- int _acc;
- int _freq;
- int _rep;
-};
-
-class SpeechManager {
-private:
- MortevielleEngine *_vm;
-
- int _typlec;
- int _phonemeNumb;
-
- SpeechQueue _queue[3];
- int _ptr_oct;
-
-public:
- uint16 *_cfiphBuffer;
- int _tbi[256];
- int _mlec;
- byte *_noise5Buf;
- int _noise5Size;
-
- SpeechManager();
- ~SpeechManager();
- void setParent(MortevielleEngine *vm);
- void spfrac(int wor);
- void charg_car(int &currWordNumb);
- void entroct(byte o);
- void veracf(byte b);
- void cctable(tablint &t);
- void regenbruit();
- void loadMusicSound();
- void loadPhonemeSounds();
- void loadNoise();
- void trait_car();
-
- void moveQueue();
- void initQueue();
- void handlePhoneme();
- void startSpeech(int rep, int ht, int typ);
-};
-
-} // End of namespace Mortevielle
-
-#endif
diff --git a/engines/mortevielle/utils.cpp b/engines/mortevielle/utils.cpp
index 5667e6e5c0..80f19277df 100644
--- a/engines/mortevielle/utils.cpp
+++ b/engines/mortevielle/utils.cpp
@@ -31,7 +31,6 @@
#include "mortevielle/menu.h"
#include "mortevielle/mouse.h"
#include "mortevielle/outtext.h"
-#include "mortevielle/speech.h"
#include "common/scummsys.h"
#include "graphics/cursorman.h"
@@ -276,6 +275,9 @@ void MortevielleEngine::handleAction() {
if (shouldQuit())
return;
++temps;
+ if (keyPressed() || _mouseClick) {
+ _soundManager._mixer->stopHandle(_soundManager._soundHandle);
+ }
} while (!((_menu._menuSelected) || (temps > lim) || (funct) || (_anyone)));
_inMainGameLoop = false;
@@ -1256,24 +1258,24 @@ void MortevielleEngine::startMusicOrSpeech(int so) {
;
} else if ((!_introSpeechPlayed) && (!_coreVar._alreadyEnteredManor)) {
// Type 1: Speech
- _speechManager.startSpeech(10, 1, 1);
+ _soundManager.startSpeech(10, 1, 1);
_introSpeechPlayed = true;
} else {
if (((_coreVar._currPlace == MOUNTAIN) || (_coreVar._currPlace == MANOR_FRONT) || (_coreVar._currPlace == MANOR_BACK)) && (getRandomNumber(1, 3) == 2))
// Type 1: Speech
- _speechManager.startSpeech(9, getRandomNumber(2, 4), 1);
+ _soundManager.startSpeech(9, getRandomNumber(2, 4), 1);
else if ((_coreVar._currPlace == CHAPEL) && (getRandomNumber(1, 2) == 1))
// Type 1: Speech
- _speechManager.startSpeech(8, 1, 1);
+ _soundManager.startSpeech(8, 1, 1);
else if ((_coreVar._currPlace == WELL) && (getRandomNumber(1, 2) == 2))
// Type 1: Speech
- _speechManager.startSpeech(12, 1, 1);
+ _soundManager.startSpeech(12, 1, 1);
else if (_coreVar._currPlace == INSIDE_WELL)
// Type 1: Speech
- _speechManager.startSpeech(13, 1, 1);
+ _soundManager.startSpeech(13, 1, 1);
else
// Type 2 : music
- _speechManager.startSpeech(getRandomNumber(1, 17), 1, 2);
+ _soundManager.startSpeech(getRandomNumber(1, 17), 1, 2);
}
}
@@ -1341,7 +1343,7 @@ void MortevielleEngine::startDialog(int16 rep) {
key = 0;
do {
- _speechManager.startSpeech(rep, haut[_caff - 69], 0);
+ _soundManager.startSpeech(rep, haut[_caff - 69], 0);
key = _dialogManager.waitForF3F8();
if (shouldQuit())
return;
@@ -2132,19 +2134,6 @@ void MortevielleEngine::loadTexts() {
}
-void MortevielleEngine::loadBRUIT5() {
- Common::File f;
-
- if (!f.open("bruit5"))
- error("Missing file - bruit5");
-
- free(_speechManager._noise5Buf);
- _speechManager._noise5Size = f.size();
- _speechManager._noise5Buf = (byte *)malloc(sizeof(byte) * _speechManager._noise5Size);
- f.read(_speechManager._noise5Buf, _speechManager._noise5Size);
- f.close();
-}
-
void MortevielleEngine::loadCFIEC() {
Common::File f;
@@ -2179,10 +2168,10 @@ void MortevielleEngine::loadCFIPH() {
error("Missing file - *cfiph.mor");
}
- _speechManager._cfiphBuffer = (uint16 *)malloc(sizeof(uint16) * (f.size() / 2));
+ _soundManager._cfiphBuffer = (uint16 *)malloc(sizeof(uint16) * (f.size() / 2));
for (int i = 0; i < (f.size() / 2); ++i)
- _speechManager._cfiphBuffer[i] = f.readUint16BE();
+ _soundManager._cfiphBuffer[i] = f.readUint16BE();
f.close();
}
@@ -2210,9 +2199,6 @@ void MortevielleEngine::music() {
int musicSize = _soundManager.decodeMusic(compMusicBuf, musicBuf, size);
free(compMusicBuf);
- _addFix = (float)((kTempoMusic - 8)) / 256;
- _speechManager.cctable(_speechManager._tbi);
-
_soundManager.playSong(musicBuf, musicSize, 5);
while (keyPressed())
getChar();
@@ -2398,7 +2384,7 @@ void MortevielleEngine::prepareRoom() {
prepareScreenType2();
displayTextInVerbBar(getEngineString(S_HEAR_NOISE));
int rand = (getRandomNumber(0, 4)) - 2;
- _speechManager.startSpeech(1, rand, 1);
+ _soundManager.startSpeech(1, rand, 1);
clearVerbBar();
}
}
@@ -2524,7 +2510,7 @@ void MortevielleEngine::initCaveOrCellar() {
prepareScreenType2();
displayTextInVerbBar(getEngineString(S_SOMEONE_ENTERS));
int rand = (getRandomNumber(0, 4)) - 2;
- _speechManager.startSpeech(2, rand, 1);
+ _soundManager.startSpeech(2, rand, 1);
// The original was doing here a useless loop.
// It has been removed
@@ -2877,8 +2863,10 @@ void MortevielleEngine::setPresenceFlags(int roomId) {
void MortevielleEngine::initMaxAnswer() {
static const byte maxAnswer[9] = { 0, 4, 5, 6, 7, 5, 6, 5, 8 };
- for (int idx = 0; idx < 9; ++idx)
+ for (int idx = 0; idx < 9; ++idx) {
_charAnswerMax[idx] = maxAnswer[idx];
+ _charAnswerCount[idx] = 0;
+ }
}
/**
@@ -3222,9 +3210,9 @@ L1:
_crep = 138;
handleDescriptionText(2, _crep);
if (_crep == 138)
- _speechManager.startSpeech(5, 2, 1);
+ _soundManager.startSpeech(5, 2, 1);
else
- _speechManager.startSpeech(4, 4, 1);
+ _soundManager.startSpeech(4, 4, 1);
if (_openObjCount == 0)
_coreVar._faithScore += 2;
@@ -3249,7 +3237,7 @@ L1:
} else {
handleDescriptionText(2, 136);
int rand = (getRandomNumber(0, 4)) - 2;
- _speechManager.startSpeech(3, rand, 1);
+ _soundManager.startSpeech(3, rand, 1);
clearDescriptionBar();
displayAloneText();
resetRoomVariables(MANOR_FRONT);