From 0c00a7fde8f373d45172afc53a2d44f8dc99702d Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 10 Aug 2013 21:56:21 +0200 Subject: MORTEVIELLE: Some refactoring in noise sound code --- engines/mortevielle/sound.cpp | 41 +++++++++++++++++++++++++++++++++++++---- engines/mortevielle/sound.h | 3 +++ engines/mortevielle/speech.cpp | 32 ++------------------------------ engines/mortevielle/speech.h | 14 -------------- 4 files changed, 42 insertions(+), 48 deletions(-) (limited to 'engines') diff --git a/engines/mortevielle/sound.cpp b/engines/mortevielle/sound.cpp index 01d7176ab2..a3ac56c27b 100644 --- a/engines/mortevielle/sound.cpp +++ b/engines/mortevielle/sound.cpp @@ -139,6 +139,7 @@ SoundManager::SoundManager(Audio::Mixer *mixer) { _speakerStream, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true); _audioStream = nullptr; _ambiantNoiseBuf = nullptr; + _noiseBuf = nullptr; } SoundManager::~SoundManager() { @@ -147,6 +148,7 @@ SoundManager::~SoundManager() { _mixer->stopHandle(_speakerHandle); delete _speakerStream; free(_ambiantNoiseBuf); + free(_noiseBuf); } /** @@ -200,6 +202,37 @@ void SoundManager::loadAmbiantSounds() { free(compMusicBuf1); } +/** + * Speech function - Load Noise file + * @remarks Originally called 'charge_bruit' + */ +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::regenbruit() { + int i = 69876; + for (int j = 0; j < 100; j++) { + _vm->_speechManager._cfiphBuffer[j] = READ_BE_UINT16(&_noiseBuf[i]); + i += 2; + } +} + void SoundManager::litph(tablint &t, int typ, int tempo) { // Skip speech if (_vm->_speechManager._typlec == 0) @@ -215,7 +248,7 @@ void SoundManager::litph(tablint &t, int typ, int tempo) { int val = _vm->_mem[(kAdrTroct * 16) + i]; i++; if (_vm->_speechManager._typlec == 0) - warning("vclas"); + warning("TODO: vclas"); else if (_vm->_speechManager._typlec == 1) { debugC(5, kMortevielleSounds, "litph - duson"); const static int noiseAdr[] = {0, 17224, @@ -229,7 +262,7 @@ void SoundManager::litph(tablint &t, int typ, int tempo) { } else { if (!_audioStream) _audioStream = Audio::makeQueuingAudioStream(freq, false); - _audioStream->queueBuffer(&_vm->_mem[(kAdrNoise * 16) + noiseAdr[val * 2]], noiseAdr[(val * 2) + 1] - noiseAdr[(val * 2)], DisposeAfterUse::NO, Audio::FLAG_UNSIGNED); + _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"); @@ -271,11 +304,11 @@ void SoundManager::litph(tablint &t, int typ, int tempo) { } break; case 6: - warning("pari2"); + warning("TODO: pari2"); break; default: if (idx == 62) - warning("blab"); + warning("TODO: blab"); else if (idx == 35) { if (i < _vm->_speechManager._ptr_oct) warning("unexpected 35"); diff --git a/engines/mortevielle/sound.h b/engines/mortevielle/sound.h index 763e18a622..dccae0eaab 100644 --- a/engines/mortevielle/sound.h +++ b/engines/mortevielle/sound.h @@ -98,6 +98,7 @@ private: PCSpeaker *_speakerStream; Audio::SoundHandle _speakerHandle; byte *_ambiantNoiseBuf; + byte *_noiseBuf; public: Audio::Mixer *_mixer; @@ -112,7 +113,9 @@ public: int decodeMusic(const byte *PSrc, byte *PDest, int size); void playSong(const byte *buf, uint usize, uint loops); void loadAmbiantSounds(); + void loadNoise(); + void regenbruit(); void litph(tablint &t, int typ, int tempo); }; diff --git a/engines/mortevielle/speech.cpp b/engines/mortevielle/speech.cpp index aaa2c6a906..1037d0abe4 100644 --- a/engines/mortevielle/speech.cpp +++ b/engines/mortevielle/speech.cpp @@ -147,16 +147,6 @@ void SpeechManager::cctable(tablint &t) { } } -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 phoneme sound file * @remarks Originally called 'charge_phbruit' @@ -173,24 +163,6 @@ void SpeechManager::loadPhonemeSounds() { 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; @@ -570,8 +542,8 @@ void SpeechManager::startSpeech(int rep, int ht, int typ) { cctable(_tbi); switch (typ) { case 1: - loadNoise(); - regenbruit(); + _vm->_soundManager.loadNoise(); + _vm->_soundManager.regenbruit(); break; case 2: //TODO: Only call it once diff --git a/engines/mortevielle/speech.h b/engines/mortevielle/speech.h index 4fe9a34dca..0117a61931 100644 --- a/engines/mortevielle/speech.h +++ b/engines/mortevielle/speech.h @@ -34,13 +34,8 @@ 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; @@ -49,13 +44,6 @@ 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; @@ -88,9 +76,7 @@ public: void entroct(byte o); void veracf(byte b); void cctable(tablint &t); - void regenbruit(); void loadPhonemeSounds(); - void loadNoise(); void trait_car(); void moveQueue(); -- cgit v1.2.3