Skip to content

Commit

Permalink
MORTEVIELLE: Some refactoring in noise sound code
Browse files Browse the repository at this point in the history
  • Loading branch information
Strangerke committed Aug 10, 2013
1 parent 9569aff commit 0c00a7f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 48 deletions.
41 changes: 37 additions & 4 deletions engines/mortevielle/sound.cpp
Expand Up @@ -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() {
Expand All @@ -147,6 +148,7 @@ SoundManager::~SoundManager() {
_mixer->stopHandle(_speakerHandle);
delete _speakerStream;
free(_ambiantNoiseBuf);
free(_noiseBuf);
}

/**
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -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");
Expand Down Expand Up @@ -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");
Expand Down
3 changes: 3 additions & 0 deletions engines/mortevielle/sound.h
Expand Up @@ -98,6 +98,7 @@ class SoundManager {
PCSpeaker *_speakerStream;
Audio::SoundHandle _speakerHandle;
byte *_ambiantNoiseBuf;
byte *_noiseBuf;

public:
Audio::Mixer *_mixer;
Expand All @@ -112,7 +113,9 @@ class SoundManager {
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);
};

Expand Down
32 changes: 2 additions & 30 deletions engines/mortevielle/speech.cpp
Expand Up @@ -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'
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down
14 changes: 0 additions & 14 deletions engines/mortevielle/speech.h
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -88,9 +76,7 @@ class SpeechManager {
void entroct(byte o);
void veracf(byte b);
void cctable(tablint &t);
void regenbruit();
void loadPhonemeSounds();
void loadNoise();
void trait_car();

void moveQueue();
Expand Down

0 comments on commit 0c00a7f

Please sign in to comment.