Skip to content

Commit

Permalink
MORTEVIELLE: Implement music in intro screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Strangerke committed Aug 4, 2013
1 parent 870a583 commit 1345320
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 65 deletions.
5 changes: 1 addition & 4 deletions engines/mortevielle/mortevielle.cpp
Expand Up @@ -105,15 +105,13 @@ MortevielleEngine::MortevielleEngine(OSystem *system, const ADGameDescription *g
_curAnim = nullptr;
_rightFramePict = nullptr;
_compMusicBuf1 = nullptr;
_compMusicBuf2 = nullptr;
}

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

/**
Expand Down Expand Up @@ -388,10 +386,9 @@ void MortevielleEngine::showIntroduction() {
if (shouldQuit())
return;

// TODO: Once music (Amiga/Atari ports) is implemented, only use the below delay if music is turned off
showTitleScreen();
delay(3000);
music();
_mixer->stopAll();
}

/**
Expand Down
19 changes: 1 addition & 18 deletions engines/mortevielle/mortevielle.h
Expand Up @@ -49,22 +49,6 @@

namespace Mortevielle {

/*---------------------------------------------------------------------------*/
/*------------------- MEMORY MAP ------------------------*/
/*---------------------------------------------------------------------------*/
/* The following is a list of physical addresses in memory currently used
* by the game.
*
* Address
* -------
* 5000:0 - Music data
* 6000:0 - Decompressed current image
* 7000:0+ - Compressed images
* 7000:2 - 16 words representing palette map
* 7000:4138 - width, height, x/y offset of decoded image
*/
const int kAdrMusic = 0x5000;

// Debug channels
enum {
kMortevielleCore = 1 << 0,
Expand Down Expand Up @@ -197,7 +181,6 @@ class MortevielleEngine : public Engine {
Pattern _patternArr[15];
int _menuOpcode;

bool _mouseClick;
bool _inMainGameLoop; // Flag when the main game loop is active
bool _quitGame; // Quit game flag. Originally called 'arret'
bool _endGame; // End game flag. Originally called 'solu'
Expand Down Expand Up @@ -441,6 +424,7 @@ class MortevielleEngine : public Engine {
int _savedBitIndex;
int _numpal;
int _key;
bool _mouseClick;
SaveStruct _coreVar, _saveStruct;

int _maff;
Expand All @@ -456,7 +440,6 @@ class MortevielleEngine : public Engine {
byte *_curAnim;
byte *_rightFramePict;
byte *_compMusicBuf1;
byte *_compMusicBuf2;

Debugger _debugger;
ScreenSurface _screenSurface;
Expand Down
54 changes: 19 additions & 35 deletions engines/mortevielle/sound.cpp
Expand Up @@ -28,6 +28,7 @@
#include "mortevielle/mortevielle.h"
#include "mortevielle/sound.h"

#include "audio/decoders/raw.h"
#include "common/scummsys.h"

namespace Mortevielle {
Expand Down Expand Up @@ -128,8 +129,6 @@ int8 PCSpeaker::generateSquare(uint32 x, uint32 oscLength) {

/*-------------------------------------------------------------------------*/

const int tab[16] = { -96, -72, -48, -32, -20, -12, -8, -4, 0, 4, 8, 12, 20, 32, 48, 72 };

// The PC timer chip works at a frequency of 1.19318Mhz
#define TIMER_FREQUENCY 1193180

Expand All @@ -149,21 +148,21 @@ SoundManager::~SoundManager() {
/**
* Decode music data
*/
void SoundManager::decodeMusic(const byte *PSrc, byte *PDest, int NbreSeg) {
int seed = 128;
void SoundManager::decodeMusic(const byte *PSrc, byte *PDest, int size) {
static const int tab[16] = { -96, -72, -48, -32, -20, -12, -8, -4, 0, 4, 8, 12, 20, 32, 48, 72 };

uint seed = 128;
int v;

for (int idx1 = 0; idx1 < (NbreSeg * 2); ++idx1) {
for (int idx2 = 0; idx2 < 64; ++idx2) {
byte srcByte = *PSrc++;
v = tab[srcByte >> 4];
seed += v;
*PDest++ = seed & 0xff;

v = tab[srcByte & 0xf];
seed += v;
*PDest++ = seed & 0xff;
}
for (int idx1 = 0; idx1 < size; ++idx1) {
byte srcByte = *PSrc++;
v = tab[srcByte >> 4];
seed += v;
*PDest++ = seed & 0xff;

v = tab[srcByte & 0xf];
seed += v;
*PDest++ = seed & 0xff;
}
}

Expand All @@ -176,27 +175,12 @@ void SoundManager::playNote(int frequency, int32 length) {
}


void SoundManager::musyc(tablint &tb, int nbseg, int att) {
#ifdef DEBUG
const byte *pSrc = &_vm->_mem[kAdrMusic * 16];

// Convert the countdown amount to a tempo rate, and then to note length in microseconds
int tempo = TIMER_FREQUENCY / att;
int length = 1000000 / tempo;
void SoundManager::playSong(const byte* buf, int size) {
Audio::AudioStream *stream = Audio::makeRawStream(buf, size, 11025 / 2, Audio::FLAG_UNSIGNED | Audio::FLAG_LITTLE_ENDIAN | Audio::FLAG_16BITS);
_mixer->playStream(Audio::Mixer::kSFXSoundType, &_speakerHandle, stream, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO);

for (int noteIndex = 0; noteIndex < (nbseg * 16); ++noteIndex) {
int lookupValue = *pSrc++;
int noteCountdown = tb[lookupValue];
int noteFrequency = TIMER_FREQUENCY / noteCountdown;

playNote(noteFrequency, length);
}

// Keep waiting until the song has been finished
while (_speakerStream->isPlaying() && !_vm->shouldQuit()) {
_vm->delay(10);
}
#endif
while (_mixer->isSoundHandleActive(_speakerHandle) && !_vm->keyPressed() && !_vm->_mouseClick)
;
}

void SoundManager::setParent(MortevielleEngine *vm) {
Expand Down
5 changes: 3 additions & 2 deletions engines/mortevielle/sound.h
Expand Up @@ -105,9 +105,10 @@ class SoundManager {
void setParent(MortevielleEngine *vm);
void playNote(int frequency, int32 length);

void decodeMusic(const byte *PSrc, byte *PDest, int NbreSeg);
void decodeMusic(const byte *PSrc, byte *PDest, int size);
void playSong(const byte *buf, int size);

void litph(tablint &t, int typ, int tempo);
void musyc(tablint &tb, int nbseg, int att);
};

} // End of namespace Mortevielle
Expand Down
2 changes: 1 addition & 1 deletion engines/mortevielle/speech.cpp
Expand Up @@ -170,7 +170,7 @@ void SpeechManager::loadMusicSound() {
_vm->_compMusicBuf1 = (byte *)malloc(sizeof(byte) * size);
f.read(_vm->_compMusicBuf1, size);

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

Expand Down
14 changes: 9 additions & 5 deletions engines/mortevielle/utils.cpp
Expand Up @@ -2201,26 +2201,30 @@ void MortevielleEngine::music() {
if (!f.open("mort.img"))
error("Missing file - mort.img");

free(_compMusicBuf2);
int size = f.size();
_compMusicBuf2 = (byte *)malloc(sizeof(byte) * size);
f.read(_compMusicBuf2, size);
byte *compMusicBuf = (byte *)malloc(sizeof(byte) * size);
byte *musicBuf = (byte *)malloc(sizeof(byte) * size * 2);
f.read(compMusicBuf, size);
f.close();

_soundManager.decodeMusic(_compMusicBuf2, &_mem[kAdrMusic * 16], size / 128);
_soundManager.decodeMusic(compMusicBuf, musicBuf, size);
free(compMusicBuf);

_addFix = (float)((kTempoMusic - 8)) / 256;
_speechManager.cctable(_speechManager._tbi);

bool fin = false;
int k = 0;
do {
fin = keyPressed();
_soundManager.musyc(_speechManager._tbi, 9958, kTempoMusic);
_soundManager.playSong(musicBuf, size * 2);
++k;
fin = fin | keyPressed() | (k >= 5);
} while (!fin);
while (keyPressed())
getChar();

free(musicBuf);
}

/**
Expand Down

0 comments on commit 1345320

Please sign in to comment.