Skip to content

Commit

Permalink
MORTEVIELLE: Play ambiant sounds
Browse files Browse the repository at this point in the history
  • Loading branch information
Strangerke committed Aug 10, 2013
1 parent 7d6d7a7 commit 62b6c33
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 11 deletions.
2 changes: 2 additions & 0 deletions engines/mortevielle/mortevielle.cpp
Expand Up @@ -105,13 +105,15 @@ MortevielleEngine::MortevielleEngine(OSystem *system, const ADGameDescription *g
_curAnim = nullptr;
_rightFramePict = nullptr;
_compMusicBuf1 = nullptr;
_noiseBuf = nullptr;
}

MortevielleEngine::~MortevielleEngine() {
free(_curPict);
free(_curAnim);
free(_rightFramePict);
free(_compMusicBuf1);
free(_noiseBuf);
}

/**
Expand Down
1 change: 1 addition & 0 deletions engines/mortevielle/mortevielle.h
Expand Up @@ -440,6 +440,7 @@ class MortevielleEngine : public Engine {
byte *_curAnim;
byte *_rightFramePict;
byte *_compMusicBuf1;
byte *_noiseBuf;

Debugger _debugger;
ScreenSurface _screenSurface;
Expand Down
103 changes: 98 additions & 5 deletions engines/mortevielle/sound.cpp
Expand Up @@ -137,12 +137,14 @@ SoundManager::SoundManager(Audio::Mixer *mixer) {
_speakerStream = new PCSpeaker(mixer->getOutputRate());
_mixer->playStream(Audio::Mixer::kSFXSoundType, &_speakerHandle,
_speakerStream, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true);
_audioStream = nullptr;
}

SoundManager::~SoundManager() {
if (_audioStream)
_audioStream->finish();
_mixer->stopHandle(_speakerHandle);
delete _speakerStream;

delete _speakerStream;
}

/**
Expand Down Expand Up @@ -177,7 +179,100 @@ int SoundManager::decodeMusic(const byte *PSrc, byte *PDest, int size) {
}

void SoundManager::litph(tablint &t, int typ, int tempo) {
return;
if (_vm->_speechManager._typlec == 2) {
warning("--->");
for (int i = 0; i < _vm->_speechManager._ptr_oct; i++)
warning("%d", _vm->_mem[(kAdrTroct * 16) + i]);
warning("---<");
} else
return;

int i = 0;
while (i < _vm->_speechManager._ptr_oct) {
int idx = _vm->_mem[(kAdrTroct * 16) + i];
i++;
switch(idx) {
case 0: {
warning("IPCX");
/* adbrui
dw 5CB0h, 0, 17224
dw 6000h, 3656, 20108
dw 6000h, 20108, 37446
dw 6924h, 6, 8388
dw 6B30h, 4, 1893
dw 6BA6h, 6, 8595
*/
int val = _vm->_mem[(kAdrTroct * 16) + i];
i++;
warning("idx %d", val);
if (_vm->_speechManager._typlec == 0)
warning("vclas");
else if (!_vm->_speechManager._typlec == 1)
warning("duson");
else { // 2
warning("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(22428, false);
_audioStream->queueBuffer(&_vm->_noiseBuf[ambiantNoiseAdr[val * 2]], ambiantNoiseAdr[(val * 2) + 1] - ambiantNoiseAdr[(val * 2)], DisposeAfterUse::NO, Audio::FLAG_UNSIGNED);
// Audio::SeekableAudioStream *raw = nullptr;
// raw = Audio::makeRawStream(&_vm->_mem[(kAdrNoise * 16)] + ambiantNoiseAdr[val * 2], ambiantNoiseAdr[(val * 2) + 1], 22428, Audio::FLAG_UNSIGNED, DisposeAfterUse::NO);
// Audio::SoundHandle soundHandle;
// _mixer->playStream(Audio::Mixer::kSFXSoundType, &songHandle, raw, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::YES);
// while (_mixer->isSoundHandleActive(songHandle) && !_vm->keyPressed() && !_vm->_mouseClick && !_vm->shouldQuit())
// ;

}
}
break;
}
case 2: {
warning("parc");
int val = _vm->_mem[(kAdrTroct * 16) + i];
i++;
int tmpidx = (val * 12) + 268;
val = _vm->_mem[(kAdrTroct * 16) + i];
i++;
warning("%d %d", tmpidx, val);
warning("reech");
}
break;
case 4:
if (_vm->_speechManager._typlec) {
warning("Skip interphoneme: %d %d", _vm->_mem[(kAdrTroct * 16) + i], _vm->_mem[(kAdrTroct * 16) + i + 1]);
i += 2;
} else {
// Speech
warning("Interphoneme: consonne:%d voyelle:%d", _vm->_mem[(kAdrTroct * 16) + i], _vm->_mem[(kAdrTroct * 16) + i + 1]);
i += 2;
}
break;
case 6:
warning("pari2");
break;
default:
if (idx == 62)
warning("blab");
else if (idx == 35) {
if (i < _vm->_speechManager._ptr_oct)
warning("unexpected 35");
i = _vm->_speechManager._ptr_oct;
} else
warning("Other code: %d", idx);
break;
}
}
}

void SoundManager::playNote(int frequency, int32 length) {
Expand All @@ -186,9 +281,7 @@ void SoundManager::playNote(int frequency, int32 length) {


void SoundManager::playSong(const byte* buf, uint size, uint loops) {

int freq = kTempoMusic * 10 * 25.2;
warning("%d", freq);
Audio::SeekableAudioStream *raw = Audio::makeRawStream(buf, size, freq, Audio::FLAG_UNSIGNED, DisposeAfterUse::NO);
Audio::AudioStream *stream = Audio::makeLoopingAudioStream(raw, loops);
Audio::SoundHandle songHandle;
Expand Down
4 changes: 3 additions & 1 deletion engines/mortevielle/sound.h
Expand Up @@ -95,10 +95,12 @@ class PCSpeaker : public Audio::AudioStream {
class SoundManager {
private:
MortevielleEngine *_vm;
Audio::Mixer *_mixer;
PCSpeaker *_speakerStream;
Audio::SoundHandle _speakerHandle;
public:
Audio::Mixer *_mixer;
Audio::QueuingAudioStream *_audioStream;

SoundManager(Audio::Mixer *mixer);
~SoundManager();

Expand Down
23 changes: 21 additions & 2 deletions engines/mortevielle/speech.cpp
Expand Up @@ -30,6 +30,7 @@
#include "mortevielle/speech.h"
#include "mortevielle/sound.h"

#include "audio/decoders/raw.h"
#include "common/endian.h"
#include "common/file.h"

Expand Down Expand Up @@ -98,7 +99,7 @@ void SpeechManager::charg_car(int &currWordNumb) {
_queue[2]._val = int_;
_queue[2]._code = 6;
} else if ((int_ >= 22) && (int_ <= 47)) {
int_ = int_ - 22;
int_ -= 22;
_queue[2]._val = int_;
_queue[2]._code = _typcon[int_];
} else if ((int_ >= 48) && (int_ <= 56)) {
Expand Down Expand Up @@ -166,11 +167,13 @@ void SpeechManager::loadMusicSound() {
error("Missing file - sonmus.mor");

free(_vm->_compMusicBuf1);
free(_vm->_noiseBuf);
int size = f.size();
_vm->_compMusicBuf1 = (byte *)malloc(sizeof(byte) * size);
_vm->_noiseBuf = (byte *)malloc(sizeof(byte) * size * 2);
f.read(_vm->_compMusicBuf1, size);

_vm->_soundManager.decodeMusic(_vm->_compMusicBuf1, &_vm->_mem[kAdrNoise * 16], size);
_vm->_soundManager.decodeMusic(_vm->_compMusicBuf1, _vm->_noiseBuf, size);
f.close();
}

Expand Down Expand Up @@ -274,6 +277,7 @@ void SpeechManager::trait_car() {
entroct(_queue[1]._val);
entroct(3);
}

break;
case 7:
case 8:
Expand Down Expand Up @@ -321,6 +325,7 @@ void SpeechManager::trait_car() {
entroct(0);
else
entroct(1);

break;
default:
break;
Expand Down Expand Up @@ -551,6 +556,9 @@ void SpeechManager::handlePhoneme() {
do {
moveQueue();
charg_car(currWord);
if (_typlec == 2)
warning("%d %d %d %d %d", _queue[2]._acc, _queue[2]._code, _queue[2]._freq, _queue[2]._rep, _queue[2]._val);

trait_car();
} while (currWord < wordCount);

Expand Down Expand Up @@ -597,6 +605,17 @@ void SpeechManager::startSpeech(int rep, int ht, int typ) {
}
handlePhoneme();
_vm->_soundManager.litph(_tbi, typ, tempo);

if (typ == 2) {
Audio::SoundHandle soundHandle;
_vm->_soundManager._mixer->playStream(Audio::Mixer::kSFXSoundType, &soundHandle, _vm->_soundManager._audioStream);
while (_vm->_soundManager._mixer->isSoundHandleActive(soundHandle) && !_vm->keyPressed() && !_vm->_mouseClick && !_vm->shouldQuit())
;
_vm->_soundManager._audioStream->finish();
_vm->_soundManager._mixer->stopHandle(soundHandle);
_vm->_soundManager._audioStream = nullptr;
}

if (_typlec != 0)
for (int i = 0; i <= 500; ++i) {
_cfiphBuffer[i] = savph[i];
Expand Down
5 changes: 2 additions & 3 deletions engines/mortevielle/speech.h
Expand Up @@ -68,13 +68,12 @@ class SpeechManager {
private:
MortevielleEngine *_vm;

int _typlec;
int _phonemeNumb;

SpeechQueue _queue[3];
int _ptr_oct;

public:
int _typlec;
int _ptr_oct;
uint16 *_cfiphBuffer;
int _tbi[256];
int _mlec;
Expand Down

0 comments on commit 62b6c33

Please sign in to comment.